I want to purge old folders with all the content by GNU find. I'm familiar with -mtime
but the time stamp of the directories is usually corrupted by rsync - not important. Luckily, the time stamp is encoded to the directory name as yyyy-mm-dd
.
How can I do the same by using the dirname instead of time stamp? Optimal read solution is preferred.
EDIT: Corrupted time stamps:
drwxr-xr-x 2 user user 8192 Aug 23 11:12 2016-05-03
drwxr-xr-x 2 user user 8192 Aug 23 11:12 2016-05-04
drwxr-xr-x 2 user user 8192 Aug 23 11:12 2016-05-05
The files inside the dirs have correct time stamps.
idea: purge the files with
find -mtime
and then (second round) purge the empty dirs. Most likely it is not possible to perform both in one round, since-empty
would apply to files as well.idea: fix the time stamps of the directories in one round (according to their name) and then purge all by
find -mtime
in another round. But the regular rsync will corrupt that again. The cron jobs must be tuned against race conditions.idea: convert
-mtime +150
toyyyy-mm-dd
(usingdate -d "-150 days"
) and then compare this string with the folder name, as it was suggested in the answer by @xvan
I ask for help finding the best way.