[Linux] find 명령어 사용법 / find example

SYSTEM/Linux / / 2022. 2. 28
반응형

1. find 명령어를 사용 파일내 문자열 치환 바꾸기


find . -name *.html -exec perl -pi -e 's/찾을키워드/바꿀키워드/g' {} ;

 


2. 리눅스 시스템에서 특정 날짜 시간대에 생성된 파일 검색 방법

   주로 리눅스 OS 해킹 사고 서버에서 침해사고 조사시 유용



# 찾고자 하는 특정 날짜 시간대 파일을 touch로 생성 
touch start.txt 
touch -t 202006281800 start.txt 

touch end.txt 
touch -t 202006282200 end.txt 

# 최상위 루트로 이동 
cd / 

# find 명령어를 조합하여 특정날짜 시간대 생성된 파일 검색 
find . -newer start.txt -a ! -newer end.txt

 

3. keyword 라는 문자열을 포함한 파일을 찾아 /dev/devnull 로 보냄


find . -type f -exec grep xxxx {} /dev/null \;

 

 

4. 기타 find 명령어 옵션


-atime : 마지막으로 엑세스한 시간
-mtime : 마지막으로 수정한 시간
-ctime : 마지막으로 i-node 정보를 수정한 시간

▶ 하위디렉토로 내려가며 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가 447인 파일을 찾음

 

#find / -user 447 -print

 

 

▶최근 10분안에 생성되거나 업데이트 된 파일 찾음


#find / -cmin -10

 

▶ 일반 유저가 쓰기 권한이 있는 폴더 찾음


#find / -perm -0002 -type d -print

 

▶ 일반 유저가 쓰기 권한이 있는 파일 찾음


#find / -perm -0002 -type f -print

 

▶ 사용자나 그룹이 없는 파일 전체 검색


#find / -nouser -o -nogroup -print

 

▶ 지난 5일 사이에 변경된 파일 찾음


#find / -mtime 5 -o -ctime 2 

 

▶ 변경된지 60일 지난 파일을 찾음


#find / -mtime +60

 

▶ 파일을 찾아 일괄 적용


#find / -type f -name 'xxx' -print -exec cat {} \; 

 

▶ find 디렉토리 제외

#find . -name '*.jsp' -not \( -path "./AAA01" -o -path "./BBB02/*" \)

 

▶ 사이즈 2048 bytes 이상인 파일 찾아 출력

 

# find . -size + 2048 -print

 

▶ find 정규식 사용 예제

 

$ find . -regex "./[a-f0-9\-]\{48\}\.jpeg"
$ find /home/test -regex "/user/test/[a-f0-9\-]\{48\}\.jpeg"

 


리눅스 사용팁 더보기

 

'SYSTEM/Linux' 카테고리의 글 목록

정보 지식 공유와 나눔으로 상생의 가치 실현해요 ^^

rootkey.tistory.com

 

 

반응형
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기
Statcounter