← 전체로 돌아가기
스킬 shell

Git으로 안 쓰는 파일 찾기

Git repo에서 참조 안 되는 파일 bash 스크립트로 찾음.

gitbashshell-scriptfile-managementfind

Git repo에서 참조 안 되는 파일 찾을 때 쓰는 스크립트.

for file in $(find . -type f -not -path "./.git/*"); do
    if ! git grep -q $(basename $file); then
        echo "Unused file: $file"
    fi
done

.git 폴더 제외하고 모든 파일 탐색함. 각 파일의 basename으로 git grep 실행해서 참조 여부 확인. 참조 안 되면 "Unused file" 출력.

  • -q: Quiet, 출력 없이 존재 여부만 체크함.

여기서 배울 것

  1. `find`로 특정 폴더(`.git`) 제외하고 파일 목록 뽑기
  2. `git grep -q`로 파일 내용 참조 여부 조용히 확인
  3. `basename`으로 파일 경로에서 이름만 쏙 빼냄
  4. Bash `for`문으로 파일 리스트 처리
원본 파일 보기 (.claude/skills/tn-find-unused-files-git-bash/SKILL.md)
---
name: Git을 이용해 배쉬에서 사용되지 않는 파일 찾기
description: This skill should be used when the user asks to find potentially unused or unreferenced files within a Git repository using a bash script, by checking if `git grep` finds the file's basename.
version: 1.0.0
source: /home/son/prj/resume/backup_notes_260317/notion/Tech Note/for문으로 배쉬에서 파일 체크하기 9dd476568a0448218e5f0d12e50c038b.md
---

# for문으로 배쉬에서 파일 체크하기

for file in $(find . -type f -not -path "./.git/*"); do
if ! git grep -q $(basename $file); then
echo "Unused file: $file"
fi
done

![Screen Shot 2023-06-28 at 2.25.33 PM.png](for%EB%AC%B8%EC%9C%BC%EB%A1%9C%20%EB%B0%B0%EC%89%AC%EC%97%90%EC%84%9C%20%ED%8C%8C%EC%9D%BC%20%EC%B2%B4%ED%81%AC%ED%95%98%EA%B8%B0/Screen_Shot_2023-06-28_at_2.25.33_PM.png)