IN-Decent

Re-decentralizing internet with free software

Find and delete empty files and directories in Linux

Posted at — May 2, 2020

To find and delete empty files in Linux, find command can be used as below,

find . -type f -size 0 -delete

To find and delete empty directories use,

find . -type d -empty -delete

NOTE:

Take care to use delete only at the end, using it in beginning after path will make find first delete all files in path before matching other arguments.

Also, -delete implies -depth, which means it processes directory contents before directory itself.