- 다른 뜻에 대해서는 indexOf 문서를 참조하십시오.
1 개요[ | ]
- 리눅스 find
- /bin/find
- 파일, 디렉토리 검색 리눅스 명령어
Console
Copy
[root@zetawiki yum]# find
.
./version-groups.conf
./pluginconf.d
./pluginconf.d/security.conf
./pluginconf.d/fastestmirror.conf
./vars
./protected.d
2 리눅스 파일 찾기[ | ]

Bash
Copy
find / -name 파일명
Console
Copy
[root@zetawiki ~]# find / -name httpd.conf
/etc/httpd/conf/httpd.conf
3 하위 디렉토리 목록[ | ]

- 하위디렉토리 전체(recursive)
Console
Copy
[root@zetawiki vector]# find . -type d
.
./images
./images/preferences
./components
- 1단계 하위디렉토리
Console
Copy
[root@koreanpol vector]# find . -maxdepth 1 -type d
.
./images
./components
4 두 개의 파일 동시에 찾기[ | ]
- "-o" 를 사용하여 두개의 파일을 한 번에 찾을 수 있음
Console
Copy
[root@koreanpol vector]# find -name "a.c" -o -name "b.c"
./a.c
./b.c
5 특정 파일을 제외하고 찾기[ | ]
- "!"를 사용하여 특정 파일을 제외하여 찾을 수 있음
Console
Copy
[root@koreanpol vector]# find . ! -name "*.txt"
.
./a.c
./b.c
- → 현재 디렉토리에서 텍스트 파일 형식을 제외한 다른 모든 파일을 찾음
6 file 명령과 함께 현재 디렉토리에서 파일 찾기[ | ]
- file 명령과 함께 현재 디렉토리에서 파일을 찾기 위한 명령
Bash
Copy
find . -type f -exec file '{}' \;
- 1. 분석해보면 find . -type f 는 현재 디렉토리에서 파일을 찾는 명령
Console
Copy
john@zetawiki:~$ ll
total 16
drwxrwxr-x 3 john john 4096 Feb 14 13:53 ./
drwxr-xr-x 12 john john 4096 Feb 14 13:52 ../
-rw-rw-r-- 1 john john 69 Feb 14 13:52 a.c
-rw-rw-r-- 1 john john 0 Feb 14 13:52 b.c
-rw-rw-r-- 1 john john 0 Feb 14 13:53 c.c
drwxrwxr-x 2 john john 4096 Feb 14 13:53 d/
john@zetawiki:~$ find . -type f
./c.c
./a.c
./b.c
- →현재 디렉토리에 a.c, b.c, c.c 파일과 d라는 디렉토리가 있음.
- 파일 형태만 출력 했기 때문에 디렉토리 d를 제외한 a.c, b.c, c.c 파일이 출력이됨
- 2. -exec file '{}' \;는 각각의 파일에 대해서 file 명령을 실행하고 그 결과 출력을 {}에 위치 시킴
- {}의 양옆에 위치한 따옴표는 쉘 스크립트의 명령에 따른 명령 혼돈을 방지하기 위함임.
- 마지막의 세미콜론은 백슬러시를 통해 출력 값에 의한 쉘 스크립트에서의 명령 혼돈을 막아줌
- 3. 전체 명령 출력
Console
Copy
john@zetawiki:~$ ll
total 24
drwxrwxr-x 3 john john 4096 Feb 14 14:06 ./
drwxr-xr-x 12 john john 4096 Feb 14 14:06 ../
-rw-rw-r-- 1 john john 69 Feb 14 13:52 a.c
-rw-rw-r-- 1 john john 19 Feb 14 14:06 b.c
-rw-rw-r-- 1 john john 38 Feb 14 14:06 c.c
drwxrwxr-x 2 john john 4096 Feb 14 13:53 d/
john@zetawiki:~$ find . -type f -exec file '{}' \;
./c.c: C source, ASCII text
./a.c: C source, ASCII text
./b.c: C source, ASCII text
- →file 명령과 함께 find가 실행 된 것을 확인 할 수 있음
※ file 명령 실행
Console
Copy
john@zetawiki:~$ file a.c
a.c: C source, ASCII text
7 같이 보기[ | ]
8 참고[ | ]
편집자 John Jeong Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.