find
파일·디렉터리
쓰는 꼴
find [path] -name '[pattern]' -type f디렉터리를 훑으며 하나하나 조건에 대 봅니다. -name '*.log'처럼 따옴표를 씌우지 않으면 셸이 먼저 펼쳐 버립니다.
자주 쓰는 옵션
| 옵션 | 뜻 |
|---|---|
| -name | Match the file name, case sensitive; -iname ignores case |
| -type | Restrict to f (file), d (directory) or l (symlink) |
| -size | Filter by size, as in -size +100M |
| -mtime | Filter by age in days, as in -mtime +7 |
| -maxdepth | Limit how deep to walk; GNU wants it before the tests |
| -delete | Delete every match, no confirmation |
| -exec | Run a command on each hit, ending with \; or + |
| -print0 | Separate results with NUL, to pair with xargs -0 |
예시
find . -name '*.log' -mtime +7 -deleteDeletes log files older than a week.
find / -type f -size +1G 2>/dev/nullFinds files over a gigabyte, hiding permission errors.
find . -name '*.jpg' -exec mv {} photos/ +Moves every JPEG it finds.
옮기고 지우고 찾는 것들. 되돌릴 수 없는 명령이 섞여 있어 -i를 붙이는 습관이 손을 구합니다.
읽는 방법
- 대괄호 [ ]는 넣어도 되고 안 넣어도 되는 자리입니다.
- 점 셋 …은 여러 개를 이어 쓸 수 있다는 뜻입니다.
- 옵션은 대소문자를 가립니다 — -r과 -R이 다른 명령도 있습니다.
자주 묻는 것
Q. find은 무엇을 하나요?
디렉터리를 훑으며 하나하나 조건에 대 봅니다. -name '*.log'처럼 따옴표를 씌우지 않으면 셸이 먼저 펼쳐 버립니다.
Q. 어떻게 치나요?
find [path] -name '[pattern]' -type f — 대괄호는 생략할 수 있는 자리입니다.
Q. 옵션은 몇 개나 자주 쓰나요?
여기 정리한 것은 8개입니다. 전체 목록은 man find에 있습니다. 이 명령은 파일·디렉터리 갈래입니다.
같이 보는 명령
man 페이지: man find