DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Delete Empty Directories (UNIX)

11.17.2006
| 32533 views |
  • submit to reddit
        // Shell command to delete empty directories. May have to run several times to get everything.

find . -type d -empty | xargs rmdir -
    

Comments

Snippets Manager replied on Wed, 2007/02/14 - 4:58am

// correction... find dir2 -depth -empty -type d -exec rmdir {} \;

Snippets Manager replied on Wed, 2007/02/14 - 4:58am

// To delete all empty directories in one go, add the -depth option to the find comment: find . -type d -empty -depth | xargs rmdir -