Answer the question
In order to leave comments, you need to log in
How to delete empty folders?
Good afternoon.
There is a directory with many files and folders, you need to delete files older than 15 days + then delete empty folders and subfolders. I made two scripts for this case and put them in cron.
Script No. 1 fulfills, everything is ok.
But Script #2 deletes empty folders only in the parent directory, and there is no subfolder. For example, if there is another empty folder in an empty folder of the parent directory, then it skips it.
What needs to be specified in the command so that the deletion occurs recursively?
if I want to watch porn I choose the best here https://bestfreepornsites.pro
Script #1: find /common/"Shared Folder"/ -type f -mtime +15 -exec rm {} ;
Script #2: find /common/"Shared Folder"/ -type d -empty -exec rmdir {} ;
Answer the question
In order to leave comments, you need to log in
# man find
...
-depth
Always true. Causes descent of the directory hierarchy to be done
so that all entries in a directory are acted on before the directory
itself.
For example, if there is another empty folder in an empty folder of the parent directory, then it skips it.
why two scripts, if you can do everything in one line ..
-exec rm -rf {} \;
rmdir must be run with the -p switch, then it deletes all parent empty directories, something like this:
Script #2: find /common/"SharedFolder"/ -type d -empty -exec rmdir -p {} ;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question