The “find” command supports an option “-empty” to find files with zero size and directories which have no files and sub-directories.

The following command finds empty directories:

[neo@techpulp ~]# find . -empty -type d
./Documents/External
./Music/jazz
./Templates
./TestDir
[neo@techpulp ~]#

The following command finds files with zero size:

[neo@techpulp ~]# find . -empty -type f
./Documents/draft1.doc
./Documents/testone.txt
./Music/download/u-and-me.mp3
[neo@techpulp ~]#

Similarly you can get the list of empty files and directories together with the following example:

[neo@techpulp ~]# find . -empty
./Documents/External
./Documents/draft1.doc
./Documents/testone.txt
./Music/download/u-and-me.mp3
./Music/jazz
./Templates
./TestDir
[neo@techpulp ~]#

If you want to clean up all empty files and directories recursively, you can use “xargs” command as shown below.

[neo@techpulp ~]# find . -empty | xargs rm -rf