find 명령어 위주 쉘명령어

2011. 9. 20. 01:08 from linux

# .svn이 포함된 파일 삭제
find . -name '.svn*' -exec rm -rf {} \;

 

# 30일 이전 데이타 조회
find /data/xxxxxx/log/888log -mtime -30 -mtime +0 -exec ls -l {} \; | wc -l
find /data/xxxxxx/spool/logupload -mtime -30 -mtime +0 -exec ls -l {} \; | wc -l

 

# 30일 이전 데이타 이동
find /data/xxxxxx/log/888log -mtime -30 -mtime +0 -exec mv {} . \;
find /data/xxxxxx/spool/logupload -mtime -30 -mtime +0 -exec mv {} . \;

 

# 리스트 목록 갯수 확인
ls -al | wc -l

 

#hack이라는 문자가 포함되있는 파일 검색
find ./ -name "*" -exec grep -H hack [] \;
find ./ -type f -print | xargs grep -H "hack" /dev/null
find ./ -type f -exec grep 'hack' {} /dev/null \;
egrep -r hack *

 

# 전체 디렉토리에서 소유자의 uid가 427인 파일들을 보여준다
find / -user 427 -print

 

# 최근 5분안에 생성되거나 업데이트 된 파일을 보여준다
find / -cmin -5

 

# 일반 유저가 쓰기 권한이 있는 디렉토리를 보여준다.
find / -perm -0002 -type d -print

 

# 일반유저가 쓰기 권한이 있는 파일을 보여준다
find / -perm -0002 -type f -print

 

# 유저나 그룹이 없는 파일을 보여준다
find / -nouser -o -nogroup -print

 

# 지난 2일 사이에 변경된 파일을 보여준다.
find / -mtime 2 -o -ctime 2

 

# 현재위치에서 하위 디렉토리까지 파일 찾기
find . -name "sample.txt"

 

# 현재위치에서 하위 디렉토리까지 sample 문자열 포함하는 파일 찾기
find . -name "*sample*"

 

#  현재위치에서 하위 디렉토리까지 ".txt"로 끝나는 파일 찾고 찾은파일안에 sample 단어가 있는 내용을 출력
find . -print "*.txt" | xargs grep "파일명 or 문자열" // 파일명 or 문자열이 들어있는 행 모두 화면에 출력
find . -name "*.txt" -exec grep "sample" {} \; // 파일명은 출력 안하고 찾고자 하는 문자열의 행만 출력
find . -name "*.txt" | xargs grep "sample"

 

# 현재위치에서 -type d(디렉토리찾기) 디렉토리를 찾는데 이름이 sample로 시작하는 디렉토리만 찾기
find . -type -d -name "sample*"

 

# 현재위치에서 파일만 찾는데 sample로 시작하는 단어를 찾고 찾은 파일중 현재일자로부터 2일전 파일만 찾기
find . -type f -name "sample*" -mtime 2

 

 

 

'linux' 카테고리의 다른 글

awk command  (0) 2012.07.03
Posted by 에시드 :