Wednesday, 15 October 2014

Super delete

Super delete oldest files(Linux): Be in the directory.

This script can used where large number of files need to be deleted, tested up 6K files:

Caution:
1. Be in the directory
2. Replace 200 with number of files to be deleted

FYI: verify $9 is file names for your system.

ls -ltr *.arc|head -200|awk '{print $9}'|while read FL
do
    list=`echo $list $FL` 
    wcnt=`echo $list|wc -c`
      if [[ $wcnt -gt 235 ]]
      then
echo $list
        echo "rm -rf $list"|sh &
        unset list;
      fi

echo "Jobs";jobs
   while true
   do
     cnt=`ps -ef|grep  rm|grep -v grep|wc -l`;echo $cnt
     if [[ $cnt -gt 10 ]]
      then
        echo "Jobs";jobs
        echo "COUNT = $cnt"; sleep 5;
     else
         break;
    fi
   done

done