how do I remove all empty directories?
I'm trying to figure out how to recursivly remove all of the empty directories on my computer.
I have many cases where a directory contains another directory which is empty, so I'm trying to figure out a way to delete all of the empty child folders, and then delete any of the empty parent folders after that.
I've tried looking at the man pages for rmdir, and toying around with grep, but I can't seem to figure this one out.
If it's just a few directories that you can delete the parent by hand, just do rm -rf dirname where dirname is the directory name. Otherwise, this might be something you want to script. There might be a fancy find way of doing it, but I can't think of a way to do it with find that would be any easier than doing it in a script.
Be careful! Some empty directories are needed for file locking and several other things. Some of your programs may not work correct if you remove certain subdirectories such as the ones in /proc or /var.
As root you can try the following command:
du -h / > d1.txt ; sort -g d1.txt > d2.txt
The command above will run du (disk usage), reporting all files and directories and their size. It will store the output to d1.txt. Afterward you can sort d1.txt onto d2.txt in numerical order that way you can look at all the files and folders that have 0 size with the less command.
|All times are GMT -5. The time now is 08:24 PM.|