1

This question already has an answer here:

Reopen voters: The 'already answered' question, is different. I am not looking to match the folder names, I want to look at the creation date time and use this to find the x days. I will be looking for folders older than 6 months, so unless I am mistaken, the 'already answered' is incorrect.


Inside a directory, I store date named folders of website backups.

/Users/myname/Desktop/rsync/

As an example:

/Users/myname/Desktop/rsync/10-06-18
/Users/myname/Desktop/rsync/11-06-18
/Users/myname/Desktop/rsync/12-06-18

In my bash script, I need to check to find any direct descendants of the 'rsync' folder that are older than x days and delete them.

Using the following, I am able to find files that are older than 2 days, but this is within the child folders as well.

find /Users/myname/Desktop/rsync -mtime +2 -print

If anyone can show me how I would limit this to just the direct descendant folder and potentially how to delete them, that would be much appreciated.

marked as duplicate by Kusalananda bash Jun 15 '18 at 9:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • You first point out that you have folders with dates in their names, but you don't want to use these date? Also, the datestamp of creation is most likely not stored, unless that's what the folder name is. – Kusalananda Jun 15 '18 at 9:15
  • 1
    I added another dupe. This looks at the modification time of folders, and at least one answer discusses -maxdepth and -mindepth, which is what you want to use, along with -prune. – Kusalananda Jun 15 '18 at 9:32
  • See also a similar question: unix.stackexchange.com/questions/228216/… Note that you will want to add -maxdepth 1 to this, apart from taking my comment to the (currently only) answer there into account. – Kusalananda Jun 15 '18 at 9:48
  • 1
    Are the modification timestamps of those date-stamped directories not in alignment with their filename-date? – Jeff Schaller Jun 15 '18 at 11:01