The Process Of Finding And Deleting The Empty Directories In UNIX

The reason why it is important to find and delete the empty files in UNIX / LINUX is that there might be issues with processing the multiple utilities that may also comprise of the rm command.

Here are the steps that will help you to find and delete the empty files and directories: #

find . -type d -empty — for directory
find . -type f -empty — for files

Delete the empty directories present under the ‘current directory’ with the use of the following command: #

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

In order to check the count of files that are in use by the users, the following command can be used: #

wc -l find . -type f -empty | wc -l
&
For non-empty files count :
find . -type f -not -empty | wc –l

In all the examples mentioned above, replace ‘.-dot’ with the directory absolute path under which you would like to search the files. #

Note : It is not advisable to remove empty directories from any system directories.

Powered by BetterDocs

Leave a Reply

Your email address will not be published. Required fields are marked *

en_USEnglish