torsdag 7 april 2016

Recursively remove all empty directories


Terminal - Recursively remove all empty directories
find . -type d -empty -delete
2010-03-23 15:21:33
User: jmcantrell
Functions: find
39
Recursively remove all empty directories

Alternatives

There are 2 alternatives - vote for the best!
Terminal - Alternatives
find . -empty -type d -exec rmdir {} +
2009-08-04 16:55:34
User: jsiei97
Functions: find rmdir
14
A quick way to find and delete empty dirs, it starts in the current working directory.
If you do find . -empty -type d you will see what could be removed, or to a test run.
find . -depth -type d -empty -exec rmdir -v {} +
2009-08-05 13:48:13
User: syssyphus
Functions: find rmdir
Tags: find
6
this will show the names of the deleted directories, and will delete directories that only no files, only empty directories.
find . -type d -empty -delete
2009-08-22 09:03:14
User: hemanth
Functions: find
Tags: find rmdir
6
You can also use, $ find . -depth -type d -exec rmdir {} \; 2>/dev/null

Know a better way?

If you can do better, submit your command here.

What others think

for Unices other than Linux, one needs to use:
find . -type d -empty -exec rm -rf {} \;
Comment by kernel01 138 weeks and 2 days ago

Inga kommentarer: