SOMEDAY/NEED
[UBUNTU] find 명령어
아이엠제니
2024. 5. 29. 17:55

CLOUD: AWS EC2
OS: Ubuntu 22.04.4 LTS
find
find

find . -maxdepth 1
현재 위치를 기준으로 level1의 디렉터리 보여줌

find . -maxdepth 2

파일만 검색
find . -type f

👉 `test` 디렉터리에서 file만 검색
find test -type f

디렉터리 검색
find -type d

👉 `test2` 디렉터리에서 디렉터리만 검색
find test2 -type d

type이랑 depth 조합
find test2 -type f -maxdepth 3

파일명으로 검색
find test -name "*.txt"

👉 특정 파일명 입력해서 검색
find test -name "error.txt"

우분투는 대소문자 구문함
파일명으로 검색 시, 대소문자 구분X
find test -iname "ERROR.txt"

파일 사이즈로 검색
find . -type f -size -10k

파일 사이즈 조건을 줘서 검색
find . -type f -size 1k -size -10k

조회된 결과 개수 카운트
find . -type f -size 1k -size -10k | wc -l

조회한 파일 excute
find . -type f -size 1k -size -10k -exec cp {} copyDirectory/ \;

참고
`Linux Command-Line 명령어 기초 배우기` - 인프런
300x250