[Linux] find command (find files and directories)

dev stefanCho·2021년 6월 1일
0

Linux

목록 보기
2/4

find command는 파일이나 디렉토리를 찾을 때 사용된다.

Special characters

chardescription
*Glob Zero or more characters
?Any one Character
[]Any Single character in the brackets

Usage

basic command

> find . -name "*list*"                                           # list 가 포함된 files, dir 을 regex로 파일을 찾음
> find . -name "*list*" -type f                                   # file만 찾음
> find . -name "*list*" -type d                                   # directory만 찾음
> find . -iname "*list*"                                          # case insensitive로 찾기
> find . -mindepth 1 -name "*list*"                               # tree 깊이로 찾기 (-mindepth | -maxdepth)
> find myDirectory /home/stefancho/YourDirectory -name "*list*"   # 절대경로 포함 함께 찾기

find command with Time Stamp

  • 파일의 생성, 수정 등의 시간조건에 따라 검색가능하다.
> find . -mtime -7                                                # 7일전까지의 수정 된 파일 (현재기준)
> find . -mtime +7                                                # 7일후까지의 수정 된 파일 (아래 2개는 동일한 표현임)
> find . -not -mtime -7 
> find . ! -mtime -7

> find . -atime -7                                                # access date
> find . -ctime -7                                                # change date (mtime이랑 비슷한데 mtime이 변하면 무조건 ctime도 변함)

> find -mmin -30                                                  # 30분 내에 수정 된 파일
> find -mtime -7 -and -mtime +3                                   # 7일이전부터 3일 이후까지 (범위)

> touch --date "3 days ago" ~/start-date                          # time stamp용 파일을 만듦 (시작 시점)
> touch --date "1 day ago" ~/end-date                             # time stamp용 파일 (마지막 시점)
> find . -newer ~/start-date -and ! -newer ~/end-date             # 위 파일의 날짜 범위내에서 검색
> find . -newermt "2021-05-30" -a ! -newer ~/end-date             # -and 와 -a는 동일한 표현
> find . -newermt "2021-05-30" -a ! -newer ~/end-date -a -name "*.jpg"                                              # 파일명 추가
> find . -newermt "2021-05-30" -a ! -newer ~/end-date -a ! -path "*/NewDirectory/*" # 검색에 제외할 directory 추가

find command with File size

  • 파일사이즈로 검색하기
> find . -size +1M              # 1Mbyte 이상
> find . -empty                 # 빈 파일
profile
Front-end Developer

0개의 댓글