YesYo.com MintState Forums
뒤로    YesYo.com MintState BBS > Tech > Linux
검색
멤버이름    오토
비밀번호 
 

유용한 find 명령어 예 모음

페이지 정보

작성자 MintState 댓글 0건 조회 21,968회 작성일 11-07-27 00:20

본문

유용한 find 명령어 예 모음

1. 현재 디렉토리( . ) 이하에 확장자가 .html( -name "*.html" ) 인 파일만 ( -type -f )
find . -name "*.html" -type f -ls

2. 파일 크기
# 파일 크기가 300KB 이상( -size +300k )인 파일만
# (호스팅되는 홈피내에 큰 사이트의 파일이 있는지 찾을 때 유용)
find . -size +300k -ls

# 파일 크기가 500bytes 이하( -size -500c )인 파일만 
find . -size -500c -ls

3. 수정일
# 수정한지 20일 이상( -mtime +20 )된 파일과 디렉토리
find . -mtime +20 -ls

# 수정한지 20일 이상된 파일만
find . -mtime +20 -type f -ls

# 수정한지 20일 이상된 파일만 삭제 ( -exec rm {} \; )
# (정기적으로 20일이 지난 파일을 삭제할 때 유용)
find . -mtime +20 -type f -ls -exec rm {} \;

# 수정한지 3일 이내( -mtime -3 )의 파일만 (백업할 때 유용)
find . -mtime -3 -type f -ls

# 수정한지 30분 이내( -mmin -30 )의 파일만
find . -mmin -30 -type f -ls

4. 퍼미션 및 파일 소유
# 파일시스템 전체( / )에서 SUID/SGID가 설정된 모든 파일 목록을 얻음
find / -type f \( -perm -04000 -o -perm -02000 \) -ls

# 소유자가 없는 파일 목록을 얻음 (사용자는 이미 삭제했는데, 파일이 남은 경우)
find / -nouser -o -nogroup

5. 출력 형식 지정
# 출력 형식을 printf로 만들어서 (출력 결과를 다른 프로그램에서 받아서 쓸 때 유용)
# %h = 경로, %f = 파일명, %k = KB, %s = Bytes

# 형식 : <경로/파일명> <파일크기KB>
find . -printf "%h/%f \t %kKB \n"
... 생략 ...
./public_html/phps/icon/type/pcx.gif      4KB
./public_html/phps/icon/type/ra.gif      4KB
./public_html/phps/icon/type/sound.gif    4KB
./public_html/phps/icon/type/text.gif    4KB

# 형식 : <경로/파일명> <파일크기Bytes>
find . -printf "%h/%f \t %sKB \n"
... 생략 ...
./public_html/phps/icon/type/movie.gif    912Bytes
./public_html/phps/icon/type/mp3.gif      958Bytes
./public_html/phps/icon/type/pcx.gif      897Bytes
./public_html/phps/icon/type/ra.gif      903Bytes
./public_html/phps/icon/type/sound.gif    932Bytes

6. 홈페이지 포팅할 때 퍼미션 안 맞는 경우 유용한 것
# 확장자가 .htm* .gif, .js, .css 인 것만 퍼미션을 644(rw-r--r--)로
find . -name "*.htm*" -o -name "*.gif" -o -name "*.js" -o -name "*.css" -exec chmod 644 {} \;

# 파일은 퍼미션을 644로
find . -type f -exec chmod 644 {} \;

# 디렉토리는 퍼미션을 701로
find . -type d -exec chmod 701 {} \;

# 하위의 모든 퍼미션을 바꾸지 않고 depth를 지정하여 제한을 둘 때
# 옵션 : -maxdepth 숫자  (1=현재디렉토리만, 2=현재디렉토리 포함하여 한단계 하위디렉토리까지만)
find . -maxdepth 1 -type d -exec chmod 701 {} \;

※ -maxdepth는 -type나 -perm 등의 조건연산자가 아닌 옵션이다.
  따라서 조건연산자보다 먼저 사용해야한다. (다른 명령처럼 옵션을 먼저쓰는 것으로 이해하면 됨)
  find . -type -d -maxdepth 1 과 같이 사용하는 것은 옳지 않다.


출처 : http://coffeenix.net/board_view.php?bd_code=36

댓글목록

등록된 댓글이 없습니다.

Total 360건 1 페이지
Linux 목록
번호 제목 글쓴이 조회 날짜
공지 MintState 110170 10-30
359 MintState 151886 11-10
358 MintState 38827 01-05
357 MintState 32583 11-17
356 MintState 30882 11-05
355 MintState 26871 01-05
354 MintState 25746 01-05
353 MintState 24468 01-05
352 MintState 24468 12-24
351 MintState 23852 11-17
350 MintState 23840 07-26
349 MintState 22643 01-05
348 MintState 22542 05-08
347 MintState 22526 05-08
346 MintState 22406 12-04
345 MintState 22398 01-05
열람중 MintState 21969 07-27
343 MintState 21262 01-05
342 MintState 21076 09-04
341 MintState 20802 12-04
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2024, YesYo.com MintState. ™