I'm trying to write some ruby that would recursively search a given directory for all empty child directories and remove them.
Thoughts?
Note: I'd like a script version if possible. This is both a practical need and a something to help me learn.
First, search all the empty files in the given directory and then, delete all those files. This particular part of the command, find . -type f -empty -print, will find all the empty files in the given directory recursively. Then, we add the -delete option to delete all those files.
Removing Directories with rm rm is a command-line utility for deleting files and directories. Unlike rmdir the rm command can delete both empty and non-empty directories. By default, when used without any option rm does not remove directories.
Use the rmdir command to remove the directory, specified by the Directory parameter, from the system. The directory must be empty (it can contain only .
Why not just use shell?
find . -type d -empty -exec rmdir '{}' \;
Does exactly what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With