쉘스크립트
14. 지난 파일 압축하고 삭제하기
Dorori
2009. 12. 18. 21:16
자 드뎌 완성 버전? 인가? ㅋ
ㅋㅋ
ㅋㅋ
#!/bin/bash ## Day and DIR configuration DATE=`date +%y%m%d` echo "date is $DATE" DIR=`echo $PWD` echo $DIR ## Decide period "A" is the range of the keeping days A=3 ## Tar and gzip compress find $DIR -mtime +$A > $DIR/imsy.txt tar -cvf $DATE.tar `find $PWD -mtime +$A` gzip $DATE.tar ## remove old files cat $PWD/imsy.txt | sed -n '/txt/p' > $PWD/imsy2.txt cat $PWD/imsy2.txt > $PWD/imsy.txt for B in `cat $PWD/imsy.txt` do echo $B # rm -rf $PWD/$B done
우선 이 스크립트의 기능은 특정 디렉토리안에 쌓이는 파일들이 계속 있을 경우
특정날짜만큼만 디렉토리에 그대로 두고
예를 들어 3 일이 지난 파일들은 모두 tar.gz 로 압축을 하고 나서
압축된 파일들은 지워버림.ㅋㅋ
find ${DIR} -type f -mtime +7 | xargs rm -f 이건??