Search code examples
unixsubdirectoryrm

Unix deleting subfolders with names in YYYYMMDD that are older than 30 days


I'm looking for simple line of code (if possible) to delete subfolders with names in YYYYMMDD that are older than 30 days. I have searched for some related solutions online and came up with this. I'm sure there's something I'm missing here because when I submitted this, no subfolders that are older than 30 days are deleted and not getting errors either.

find /my/directory -type d -name '[0-9]{8}' -mtime +30 -exec rm -rf {} \;


Solution

  • use the -regex flag in find.

    find /my/directory -type d -regex "[0-9]{8}" -mtime +30 -exec rm -rf {} \;