Imagine that you decided to download a torrent that originally has a million folders. Then, imagine that you’ll only download actually one or two of them. Imagined that?
Now, imagine that you’re cleaning your files, you know, and then suddenly you see yourself in front of that million of empty folders. Of course you want to rip them off!
Knowing that find is a **VERY** powerful tool, reading its man I found out the following:
$ find . -type d -empty
And voila, only the empty dirs of the folder you are are returned.
Now, to delete them you have two options:
$ find . -type d -empty -exec rmdir "{}" ";"
(This should execute rmdir n times, where n is the number of empty folders the find command returns.)
or
$ find . -type d -empty | xargs rmdir -
(This should get all the output of the find command and use as input to rmdir command, wrapped by xargs.)
Both of them should work.
Aoooo,
Very interesting way to clean these crapy torrent way from my computer, and find unused things too
Good job carp*!
Kisses
*Are you watching Heroes (2nd season)? Then you will understand the “carp”
$ find . -type d | xargs rmdir
No need for -empty as rmdir only removes empty directories.