반응형
find 명령어는 파일 및 디렉토리를 검색하는 데 사용되는 매우 강력한 도구입니다. 다양한 옵션을 통해 파일의 이름, 크기, 수정 시간, 유형 등을 기준으로 검색할 수 있습니다. 아래에 find 명령어의 주요 사용법과 옵션을 정리했습니다.
기본 문법
find [경로] [검색 조건] [연산]
주요 옵션 및 예제
- 특정 디렉토리에서 모든 파일 및 디렉토리 찾기
find /path/to/directory
- 특정 이름의 파일 찾기
find /home/user -name "test.txt"find /path/to/directory -name "filename"
- 대소문자를 구분하지 않고 이름 검색
find /home/user -iname "test.txt"find /path/to/directory -iname "filename"
- 특정 확장자를 가진 파일 찾기
find /home/user -name "*.jpg"find /path/to/directory -name "*.ext"
- 파일 유형별로 검색
- 일반 파일
find /path/to/directory -type f
- 디렉토리
find /path/to/directory -type d
- 일반 파일
- 특정 크기의 파일 찾기
- +N: N보다 큰 파일
- -N: N보다 작은 파일
- Nc: N 바이트
- Nw: N 워드 (2 바이트)
- Nb: N 블록 (512 바이트)
- Nk: N 킬로바이트
- NM: N 메가바이트
- NG: N 기가바이트
find /home/user -size +100Mfind /path/to/directory -size [+|-]N[cwbkMG] - 특정 시간 내에 수정된 파일 찾기
- N일 이내에 수정된 파일
find /path/to/directory -mtime -N
- N일 전에 수정된 파일
find /path/to/directory -mtime +N
find /home/user -mtime -7 # 최근 7일 이내에 수정된 파일 find /home/user -mtime +30 # 30일 이전에 수정된 파일 - N일 이내에 수정된 파일
- 특정 시간 내에 액세스된 파일 찾기
- N일 이내에 액세스된 파일
find /path/to/directory -atime -N
- N일 전에 액세스된 파일
find /path/to/directory -atime +N
find /home/user -atime -7 # 최근 7일 이내에 액세스된 파일 find /home/user -atime +30 # 30일 이전에 액세스된 파일 - N일 이내에 액세스된 파일
- 특정 권한을 가진 파일 찾기
find /home/user -perm 644find /path/to/directory -perm mode
- 특정 소유자 또는 그룹의 파일 찾기
- 소유자
find /path/to/directory -user username
- 그룹
find /path/to/directory -group groupname
- 소유자
- 다중 조건 사용
- AND 조건
find /path/to/directory -name "filename" -and -size +100M
- OR 조건
find /path/to/directory \( -name "file1" -o -name "file2" \)
- NOT 조건
find /path/to/directory ! -name "filename"
- AND 조건
검색 결과에 대한 연산
- 파일 삭제
find /home/user -name "*.tmp" -deletefind /path/to/directory -name "filename" -delete
- 명령어 실행
find /home/user -name "*.log" -exec rm {} \;find /path/to/directory -name "filename" -exec command {} \;
- 검색 결과 출력-print는 기본 옵션으로, 생략해도 결과가 출력됩니다.
find /path/to/directory -name "filename" -print
- 명령어 대화형 실행
find /home/user -name "*.log" -ok rm {} \;find /path/to/directory -name "filename" -ok command {} \;
이 외에도 find 명령어는 매우 강력하고 유연한 옵션들을 제공하므로, 특정 상황에 맞는 다양한 활용이 가능합니다. 필요에 따라 man find를 참조하여 더 많은 옵션과 예제를 확인할 수 있습니다.
반응형
'Linux > Linux공통' 카테고리의 다른 글
SU와 SUDO -I의 차이점 (0) | 2024.07.12 |
---|---|
alias 명령어 예시문 (0) | 2024.07.11 |
Disk 임의 제거로 인한 커널 패닉. (0) | 2024.06.10 |
grep 과 egrep 활용 (0) | 2024.05.28 |
네트워크 인터페이스 물리적으로 특정하기. (0) | 2024.04.30 |