Tuesday, August 20, 2013

Find and delete the empty files and directories

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.

No comments:

Post a Comment