I noticed today (after 8 years of happy hacking in bash) that there is no trivial way to "delete by date" using "rm". So the solution is to pass stuff around a combination of commands like rm, ls, find, awk and sed.
Say, for example, I wanted to delete every file in the working directory since 2009, what would be the typical approach?
I came up with the following, which is inconvenient and should only be started if "rm" is configured to skip directories (otherwise you will delete the parent directory):
ls -la | awk '{if (substr($6,0,5)==2009) print $8}' | xargs rm
Points for the most elegant and most outrageously redesigned solutions.
source
share