2016-08-03 115 views
0

目录结构导航目录和子目录和使用shell

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”部分 是恒定的。
    谁能帮我在this.There可能是许多目录具有相同的子目录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