I need to delete any file in a directory older than 2 years. It is very important that I keep the latest files and delete old files.
I searched and found this.
find /path/to/files* -mtime +365 -exec rm {} \;
Is it possible to simply multiply a number?
find /path/to/files* -mtime +1095 -exec rm {} \;
Is there a way to add a switch that will print the file name on the screen when it removes it? To make sure he does what I expect?
I also found this:
find /rec -mtime +365 -print0 | xargs -0 rm -f
Is there a difference between the two? Better than the other? What I read says xargs is faster. Can I multiply mtime by the second or third year?
And finally, can I put the code as it is in the cron job, which can work daily?
Thanks!
source share