This one liner command - deletes files in a directory tree that are less than 5 days old, and asks if it is okay to delete each file:
Code Snippet #1:
find /path/to/directory -mtime -5 -ok rm -f {} \;
Explanation:
- mtime- modification time older than 5days in this case
- -f – files to be deleted
delcnt=0
for files in `find /path/to/directory -mtime -5 -print`
do
echo "Deleting file $file"
/bin/rm $file
delcnt=$(($delcnt + 1))
done
echo "deleted $delcnt files"
for i in `ls -l |grep "Aug"|awk '{print $9}'`
do
echo $i
rm $i
done
for i in `ls -l | grep " 2007 "| awk '{print $9}' `
do
echo "Removing...." >> bb
echo `ll $i` >> bb
rm $i
done