Luo Hao

Linux——批量删除文件

rehoni / 2021-06-25


脚本如下

 #!/bin/csh
 
 #FaultRecordData CLEAR
 set basepath = /users/ems/FaultRecordData
 set mfile = ""
 foreach mfile (${basepath}/*)
 if(-d $mfile) then
 echo "$mfile" 
 #cd ${mfile}/checkreport/bak
 if($status == 0) then
 #find -mtime +31 -name "*.*" -exec rm -rf {} \\;
 echo "delete check report files "
 ls -t *.* | awk '{if(NR>=30){print $0}}' | xargs rm -rf
 endif
 #cd ${mfile}/comtrade/bak
 if($status == 0) then
 #find -mtime +31 -name "*.*" -exec rm -rf {} \\;
 echo "delete comtrade files "
 ls -t *.* | awk '{if(NR>=30){print $0}}' | xargs rm -rf
 endif
 endif
 end
 
 #IMFData CLEAR
 cd /users/ems/IMPData/bak
 if($status == 0) then
 #find -mtime +1 -name "*.*" -exec rm -rf {} \\;
 echo "delete impdata files "
 ls -t *.* | awk '{if(NR>=30){print $0}}' | xargs rm -rf
 endif
 
 #EMSData CLEAR
 cd /users/ems/EMS_MODEL/CIM
 if($status == 0) then
 #find -mtime +31 -name "*.*" -exec rm -rf {} \\;
 echo "delete ems data : cim files "
 ls -t *.* | awk '{if(NR>=30){print $0}}' | xargs rm -rf
 endif
 cd /users/ems/EMS_MODEL/TRIP/bak
 if($status == 0) then
 #find -mtime +31 -name "*.*" -exec rm -rf {} \\;
 echo "delete ems data : trip files "
 ls -t *.* | awk '{if(NR>=30){print $0}}' | xargs rm -rf
 endif
 cd /users/ems/EMS_MODEL/EFILE 
 if($status == 0) then
 #find -mtime +31 -name "*.*" -exec rm -rf {} \\;
 echo "delete ems data : efile files "
 ls -t *.* | awk '{if(NR>=30){print $0}}' | xargs rm -rf
 endif
 cd /users/ems/EMS_MODEL/RATIO/bak
 if($status == 0) then
 #find -mtime +31 -name "*.*" -exec rm -rf {} \\;
 echo "delete ems data : ratio files "
 ls -t *.* | awk '{if(NR>=30){print $0}}' | xargs rm -rf
 endif