'로그'에 해당되는 글 1건

  1. 2009.12.18 14. 지난 파일 압축하고 삭제하기 2

14. 지난 파일 압축하고 삭제하기

자 드뎌 완성 버전? 인가? ㅋ

ㅋㅋ

  1. #!/bin/bash  
  2. ## Day and DIR configuration  
  3. DATE=`date +%y%m%d`  
  4. echo "date is $DATE"  
  5. DIR=`echo $PWD`  
  6. echo $DIR  
  7.   
  8. ## Decide period "A" is the range of the keeping days  
  9.   
  10. A=3  
  11.   
  12. ## Tar and gzip compress   
  13.   
  14. find $DIR -mtime +$A > $DIR/imsy.txt  
  15. tar -cvf $DATE.tar `find $PWD -mtime +$A`  
  16. gzip $DATE.tar  
  17.   
  18. ## remove old files   
  19.         cat $PWD/imsy.txt | sed -n '/txt/p' > $PWD/imsy2.txt  
  20.         cat $PWD/imsy2.txt > $PWD/imsy.txt  
  21.         for B in `cat $PWD/imsy.txt`  
  22.         do  
  23.                 echo $B  
  24.         #       rm -rf $PWD/$B  
  25.         done  

우선 이 스크립트의 기능은 특정 디렉토리안에 쌓이는 파일들이 계속 있을 경우

특정날짜만큼만 디렉토리에 그대로 두고

예를 들어 3 일이 지난 파일들은 모두 tar.gz 로 압축을 하고 나서
압축된 파일들은 지워버림.ㅋㅋ



find ${DIR} -type f -mtime +7 | xargs rm -f  이건??