I have a folder with a bunch of files. I need to delete all the files created before July 1st. How do I do that in a bash script?
I think the following should do what you want:
touch -t 201007010000 dummyfile
find /path/to/files -type f ! -newer dummyfile -delete
The first line creates a file which was last modified on the 1st July 2010. The second line finds all files in /path/to/file which has a date not newer than the dummyfile, and then deletes them.
If you want to double check it is working correctly, then drop the -delete
argument and it should just list the files which would be deleted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With