Main Menu

Search

LINUX: How to Find Empty Files and Directories in Linux and Remove Them? ("find" command)

FIND EMPTY DIRECTORIES
Below is command to find empty directories in current directory in Linux.

find . -type d -empty

If you want to find the empty directories in whole filesystem below command can be used.



find / -type d -empty 2>/dev/null

For finding and removing the Empty Directories below command can be used.

find . -type d -empty -exec rmdir {} \;

FIND EMPTY FILES

Below is command to find empty files in Linux.
find . -type f -empty

If you want to find the empty directories in whole filsystem below command can be used.

find / -type f -empty 2>/dev/null

For finding and removing the Empty Directories below command can be used.


find . -type f -empty -exec rm -f {} \;

Products to which Article Applies


All Linux Environments

Additional References
https://www.thegeekstuff.com/2010/03/find-empty-directories-and-files/


 

tarun boyella

No comments:

Post a Comment