The Process Of Finding And Deleting The Empty Directories In UNIX
The reason why it’s necessary to find out and delete the empty files in UNIX/ LINUX operating system is that there may be problems with processing the multiple utilities which will also comprise of the rm command.
The steps given below shows 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.