Delete files based on date
Got a directory full of files going back for months, I need to delete all files in there which are older then this month of June.
Can't find the syntax to delete files by date so any help would be appreciated. Cheers |
You could use the find command.
find <directory> -ctime +17 -daystart -exec rm "{}" \; The plus sign before the 17 will select change times greater than 17*24 hours ago. The daystart options measures the time from midnight rather than the current time. The double quotes are needed when a file-name contains whitespace. This command will also delete files from subdirectories. If that isn't what you want, use the -maxdepth 1 option. |
Cheers mate, I'll give that a go!
|
I can tell you this much:
This line will print only those files in a directory specified by the date argument to sed: Code:
ls -lh | awk '{print $6 " " $9}' | sed -n '/Jun/p' You could then pipe this output to a file: Code:
ls -lh | awk '{print $6 " " $9}' | sed -n '/May/p' | awk '{print $2}' >> file_list You then should be able to do: Code:
rm `cat file_list` I'd test it first on "dummy data" to make sure I didn't screw up! |
All times are GMT -5. The time now is 03:50 PM. |