find 명령어와 그 밖의 명령어를 이용하여 아래의 작업을 할 수 있다.

1. 특정 파일 속 특정 단어 찾기
ex) html 파일에서 mms:// 찾기
find . -type f -name "*.html" -exec grep "mms://" {} /dev/null \;
(뒤에 /dev/null을 붙이는 이유는 해당 파일명을 보기 위함이다.)

2. 특정 파일 속 특정 단어 바꾸기
ex) html 파일에서 mms://를 http://로 바꾸기
find . -type f -name "*.html" -exec perl -pi -e 's/mms/http/g' {} \;

perl 대신 sed (stream editor) 명령을 사용할 수 도 있다.
find . -type f -name "*.html" -exec sed -i 's/mms/http/g' {} +

3. 특정 파일만 압축하기
ex) html 파일만 찾아서 압축하기
for i in $(find . -name '*.html'); do tar -zrvf html.tgz $i; done

4. 5일 지난 파일 삭제하기
rm -f 'find . -mtime +5'

'배움생활 > 리눅스' 카테고리의 다른 글

Pro GIT 번역  (0) 2012/01/10
Windows용 GVIM에서 화살표키 쓰기  (0) 2011/12/21
특정파일 속 특정문자열 바꾸기  (0) 2011/12/20
vim 명령 모음  (0) 2011/12/16
vim color 세팅  (0) 2011/09/08
안드로이드 보드에서 ADB가 제대로 안될때 세팅법  (0) 2010/06/12

블로그 이미지

blueecho

누군가에게 "당신은 무엇을 잘하십니까?"라는 질문을 들었을때 바로 대답할것을 만들어보자~!!

카테고리

분류 전체보기 (488)
NeWs (20)
배움생활 (97)
취미생활 (116)
끄적끄적 (239)
인생설계 (12)
Wish list (4)