find ./ -type f -size 0
find ./ -type f -empty
- The
./means start searching from the current directory. If you want to find files from another directory then replace the./with the path to needed directory. For example, to search everything under the system log directory you need to replace./with/var/log. - The
-type fflag is specifies to find only files. - The
-size 0and-emptyflags is specifies to find zero length files.
find ./ -type f -size 0 -exec rm -f {} \;
find ./ -type f -size 0 | xargs rm -f
find ./ -type f -size 0 -delete
xargs will cause all the filenames to be sent as arguments to the rm -f commands. This will save processes that are forked everytime -exec rm -f is run. But is fails with spaces etc in file names.The
-delete is the best when it is supported by the find you are using (because it avoids the overhead of executing the rm command by doing the unlink() call inside find().Empty directories
To find all empty directories, simply use:find ./ -type d -empty
- The
./means start searching from the current directory. If you want to find files from another directory then replace the./with the path to needed directory. For example, to search everything under the system log directory you need to replace./with/var/log. - The
-type dflag is specifies to find only directories. - The
-emptyflag is specifies to find empty directories.
find ./ -depth -type d -empty -exec rmdir {} \;
find ./ -type d -empty -delete
-delete is the best when it is supported by the find you are using.