기계는 거짓말하지 않는다

Linux 파일, 디렉터리 검색 find 명령어 본문

Linux

Linux 파일, 디렉터리 검색 find 명령어

KillinTime 2023. 3. 5. 14:48

find command

 

find(1) - Linux man page

find(1) - Linux man page Name find - search for files in a directory hierarchy Synopsis find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression] Description This manual page documents the GNU version of find. GNU find searches the directory tree

linux.die.net

다음은 간단한 사용 예이다.

find "*.mp4" # 현재 경로의 모든 mp4 파일, 디렉터리 검색
find . -name "*.mp4" # 현재 경로와 현재 경로 하위의 모든 mp4 파일, 디렉터리 검색
find . / -name "*.mp4" # 최상위 경로와 최상위 경로 하위의 모든 mp4 파일, 디렉터리 검색
find . -perm 0777 # 현재 경로와 현재 경로 하위의 0777 권한 파일, 디렉터리 검색

find와 xargs, grep을 사용하여 검색어가 파일 내부에 포함되었는지 확인도 가능하다.

# 현재 경로와 현재 경로 하위의 모든 txt 파일에서 ABCD가 txt 파일 내용에 포함된 파일을 찾는다.
find . -type f -name "*.txt" | xargs grep "ABCD"
Comments