find 사용법

find_commands

find (파일 찾는 명령어)


Test OS : CentOS

사용법

Usage: find path-list [predicate-list]

# 검색 조건
# 파일 이름으로 찾는다.
-name filename

# access time 이 n일 이전인 파일을 찾는다.access time 이 n일 이전인 파일을 찾는다.
-atime +n

# access time이 n일 이내인 파일을 찾는다.
-atime -n

# n일 이전에 변경된 파일을 찾는다.
-mtime +n
# n일 이내에 변경된 파일을 찾는다.
-mtime -n

# 파일 권한이 nnn인 파일을 찾는다.
-perm nnn

# 파일 타입이 x인 파일들을 찾는다.
-type x

# 사이즈가 n이상인 파일들을 찾는다.
-size n

# 링크된 개수가 n인 파일들을 찾는다.
-links n

# user이름으로 찾는다.
-user username

# group 이름으로 찾는다.
-group groupname
# 처리 방법
# 찾은 파일의 절대 경로명을 화면에 출력한다.
-print

# 찾은 파일들에 대해 cmd 명령어를 실행한다.
-exec cmd {};

# 예시
# 현재 폴더 아래에 있는 파일 중에 이름에 test를 포함하는 모든 파일을 화면에 출력한다.
find . -name *test* -print

# 파일 타입이 d인 파일을 찾아 경로명을 화면에 출력한다.
find . -type d -print

#파일 권한이 700인 파일을 찾아준다.
find . -perm 700 -print

# 파일 권한이 400인 파일과 200인 파일을 찾아준다.
find . \ ( -perm 400 -o -perm 200 ) -print

# 이름이 core인 파일을 찾아서 ls -l 한다.
find . -name core -exec ls -l {} \;

# 검색어을 내용에 포함하는 파일을 찾아서 보여 줍니다.
find . -type f | xargs grep "검색어"

# * / 는 최상위 디렉터리를 뜻함. 만약 찾고자 하는 디렉터리가 있다면 그걸로 대체

# 파일 이름에 foobar 가 들어간 파일 찾기
find / -name "foobar" -print

# 특정 사용자(foobar) 소유의 파일을 찾기
find / -user foobar -print | more

#최근 하루 동안에 변경된 파일을 찾기
find / –ctime -1 -a -type f | xargs ls -l | more

# 오래된 파일(30일 이상 수정되지 않은 파일) 찾기
find / -mtime +30 -print | more

# 최근 30일안에 접근하지 않은 파일과 디렉터리를 별도의 파일로 만들기
find / ! ( -atime -30 -a ( -type d -o -type f ) ) | xargs ls -l > not_access.txt

# 하위 디렉터리로 내려가지 않고 현재 디렉터리에서만 검색하기
find . -prune ...

# 퍼미션이 777 인 파일 찾기
find / -perm 777 -print | xargs ls -l | more

# others 에게 쓰기(write) 권한이 있는 파일을 찾기
find / -perm -2 -print | xargs ls -l | more

# others 에게 쓰기(write) 권한이 있는 파일을 찾아 쓰기 권한을 없애기
find / -perm -2 -print | xargs chmod o-w 또는 # find / -perm -2 -exec chmod o-w {} ; -print | xargs ls -l | more

# 사용자이름과 그룹이름이 없는 파일 찾기
find / ( -nouser -o -nogroup ) -print | more

# 빈 파일(크기가 0 인 파일) 찾기
find / -empty -print | more 또는 # find / -size 0 -print | more

# 파일 크기가 100M 이상인 파일을 찾기
find / -size +102400k -print | xargs ls -hl

# 디렉터리만 찾기?
find . -type d ...

# root 권한으로 실행되는 파일 찾기
find / ( -user root -a -perm +4000 ) -print | xargs ls -l | more

# 다른 파일시스템은 검색하지 않기
find / -xdev ...

# 파일 이름에 공백이 들어간 파일 찾기
find / -name "* *" -print

# 숨겨진(hidden) 파일을 찾기
find / -name ".*" -print | more

# *.bak 파일을 찾아 지우기
find / -name "*.bak" -exec rm -rf {} ;

# *.bak 파일을 찾아 특정 디렉터리로 옮기기
mv `find . -name "*.bak"` /home/bak/

# 여러 개의 파일에서 특정 문자열을 바꾸기
find / -name "*.txt" -exec perl -pi -e 's/찾을 문자열/바꿀 문자열/g' {} ;

# 특정 디렉터리 하위의 모든 파일을 뒤져서 특정 문자열이 들어 있는 파일 찾기
find . | xargs grep csh   :  .은 현재 디렉터리 이므로 현재 디렉터리 하위의 모든 파일에서 csh글자를 grep



0 Comments:

댓글 쓰기

이 블로그 검색

Popular Posts

WEB&&WAS

OS

Reviews