How to find empty folders on Linux
Posted by Planet Malaysia on October 17, 2008
Tips: How to find an empty folders on Linux box
In order to do some folder maintenance job, you may require to find an empty folder on Linux box. I would like to share tips here:
# find /path -type d -empty
Find empty folder and list
# find /path -type d -empty -exec ls -ld {} \;
Find empty folder and save as temporary file
# find /path -type d -empty -exec ls -ld >> /tmp/savefiles.txt {} \;
Find empty folder and delete
# find /path -type d -empty -exec rm -rf {} \;
Enjoy!
Possibly Related Posts:
- How to add Dell PERC Drivers into VMware Converter Cold Clone ISO
- Top 10 Free Anti Virus
- Microsoft SQL 2008 Agent not starts
- VMware Workstation 7 Serial Key
- WP Contact Form III – You do not have sufficient permissions to access this page Error
Comments
6 Responses to “How to find empty folders on Linux”
Leave a Reply
you can easily found tons of similar tutorial.
Thanks for this, just what I was looking for
I have posted a complete how-to for the linux newbs at LinuxBuzz.net
You should probably run
[code]
find -type d -empty -exec rmdir '{}' \;
[/code]
rmdir will only remove an empty directory, this adds some assurance (sanity) to the removal process. ‘{}’ will ensure strange directory names are ‘quoted’ and protected from your shell
> # find /path -type d -empty -exec rm -rf {} \;
If we do this, we would have to search again for empty folders (those that just got empty by deleting empty folders inside).
Better try:
# find /path -depth -type d -empty -exec rm -r {} \;
“-depth” means “act on contents before the dir (work from the bottom up)”.
Even simpler and safer is
# find /path -type d -empty -delete