Wednesday, October 21, 2009

Deleting Files Based on Date Time

Today I needed to delete files based on date and time:
Here is the command I used for deleting file last modified on 21 Oct 2009 16:30:
ls -lh | sed -n '/Oct\ 21\ 16:30/p' | awk '{print $9}' >> 1.txt
rm -f `cat 1.txt`
Explanations: 
ls -lh (lists all files)
sed -n  '/Oct\ 21\ 16:30/p' (find files at given date from list)
awk '{print $9}' (print only file names on list) and >> 1.txt put list of files to 1.txt
rm -f (force to delete)

No comments: