2016-08-03 3 views
0

디렉토리 구조 I는 디렉토리 및 입출력 파일이 보존되어있는 서브 디렉토리를 탐색해야탐색 디렉토리 및 서브 디렉토리 및 셸

MyDirectory 

    -data/ 

    -DATA-TT_20160714_soe_test_testbill_52940_1.lst 

    -output/ 

    -DATA-TT_20160714_soe_test_testbill_52940_1.pdf 

    -Backup/ 

enter code here 
    #!/bin/bash 
    for i in $(ls); do 
     echo $i 
       #cd $i 
       #cd $i/data/ 
       echo $i 
      cd $i/data/ 
       echo $i/data/ 
      $(ls *1.lst) 
     cd ../output 
    $(ls *1.pdf) 
     done 
  1. 를 사용하여 파일을 이동. 이 파일의 날짜는 YYYYMMDD 형식의 이며 현재 날짜와 비교해야합니다. 차이가 1 개월 이상인 경우 파일을 압축하여 백업 디렉토리로 이동해야합니다. "DATA-TT"부분은 입니다.
    사람이 같은 하위 디렉토리 structure.Example MyDirectory1, MyDirectory2, MyDirectory3

답변

0

많은 디렉토리 수 있습니다 관해서도 나를 도울 수있는 회의를 떠날 필요가. 내가 당신을 도울 작업 봤는데 당신에게 스크립트를 떠날거야 :

#!/bin/sh 

    # in your case filename would be the variable used in the for loop 
    filename=$(find DATA-TT*) 
    # Part gets the date from the filename 
    part=$(echo $filename | grep -Eo '[[:digit:]]{8}') 
    echo "$filename -> $part" 
    # limit_date is current date -30 days 
    limit_date=$(date +'%Y%m%d' -d "now 30 days") 
    echo $cur_date 
    # this part compares and echoes, you can try it and replace echoes with ziping, moving, etc. 
    if [ $part -ge $limit_date ] 
    then 
      echo "part is older than 1 month" 
    else 
      echo "part had not yet reached 1 month age" 
    fi 
0

출력

#!/bin/bash 
list=($(find data -name "DATA-TT_*")) 
limit=`date +%Y%m%d -d "-30 days"` 
for i in ${list[@]}; do 
    filedate=$(echo $i| cut -d'_' -f 2) 
    if [ "$limit" -gt "$filedate" ]; then 
     mv $i backup 
    fi 
done 
에 대해 동일한 데이터 디렉토리이 하나
관련 문제