Question: How do I locate empty directories that doesn’t contain any files? Also, how do I find all empty files ( zero byte files ) in Linux?
Answer: You can use unix find command to get a list of all empty files and directories as explained below.
Also, refer to our earlier articles about unix find command examples – part 1 and find command examples – part 2.
Find empty directories in the current directory using find -empty
find . -type d -empty
Use the following command to remove all empty directories under the current directory.
find . -type d -empty -exec rmdir {} \;
Note: It is not recommended to remove empty directories from /etc/ or any other system directories.
Find empty files in the current directory using find -empty
find . -type f -empty
Note: Typically empty files are created by some programs as place holders, or as lock files, or as socket files for communication.
How many empty files are located under the current directory (and sub-directories)?
To count the number of empty files under current directory, pipe the find command to wc -l
find . -type f -empty | wc -l
How many non-empty files are located under the current directory (and sub-directories)?
find . -type f -not -empty | wc -l
Note: Find option -not reverts the option that follows it.
In all the above examples, replace the ( . ) dot with any other directory-path under which you would like to search the files.
Mommy, I found it! — 15 Practical Linux Find Command Examples tutorial explains find command’s maxdepth, mindepth, and invert match.
Get free Unix tutorials, tips and tricks straight to your email in-box.
If you enjoyed this article, you might also like..


My name is Ramesh Natarajan. I will be posting instruction guides, how-to, troubleshooting tips and tricks on Linux, database, hardware, security and web. My focus is to write articles that will either teach you or help you resolve a problem. Read more about
{ 3 comments… read them below or add one }
Very good way to delete it.
Why you don’t use the option “-delete” to delete the directories?
really nice..very useful