I wrote about setting up a cron job on my work machine to process some files in a shared Dropbox folder.
After a while, old files will start to accumulate there and I’d want to delete them, by adding another command to the crontab.
The criteria for deleting files in my case are:
– File is older than 5 days
– File has an extension .csv (keep other files like readme)
– Do not delete a few example .csv files
So HGH the HGH Unix command will look like a pipe that first finds the files, then deletes them.
find X -exec rm {} ;
It’s pretty easy to find all .csv files older than 5 days:
find /path/to/files/*.csv -mtime +5
And then, to exclude certain CSV files that I want to keep, I used -not and -and operators to specify filenames (test.csv, test_out.csv and input_example.csv):
find /path/to/files/*.csv
-not -iname test* -and -not -iname input* -mtime +5