原文:https://stackoverflow.com/questions/13868821/shell-script-to-delete-directories-older-than-n-days
This will do it recursively for you:
find /path/to/base/dir/* -type d -ctime +10 -exec rm -rf {} \;
Explanation:
·find: the unix command for finding files / directories / links etc. ·/path/to/base/dir: the directory to start your search in. ·-type d: only find directories ·-ctime +10: only consider the ones with modification time older than 10 days ·-exec ... \;: for each such result found, do the following command in ... ·rm -rf {}: recursively force remove the directory; the {} part is where the find result gets substituted into from the previous part.
Alternatively, use:
find /path/to/base/dir/* -type d -ctime +10 | xargs rm -rf
|