How to delete many 0 byte files in linux?

Solution 1:

Use find combined with xargs.

find . -name 'file*' -size 0 -print0 | xargs -0 rm

You avoid to start rm for every file.

Solution 2:

With GNU's find (see comments), there is no need to use xargs :

find -name 'file*' -size 0 -delete

Solution 3:

If you want to find and remove all 0-byte files in a folder:

find /path/to/folder -size 0 -delete

Solution 4:

You can use the following command:

find . -maxdepth 1 -size 0c -exec rm {} \;

And if are looking to delete the 0 byte files in subdirectories as well, omit -maxdepth 1 in previous command and execute.

Solution 5:

find . -maxdepth 1 -type f -size 0 -delete

This finds the files with size 0 in the current directory, without going into sub-directories, and deletes them.

To list the files without removing them:

find . -maxdepth 1 -type f -size 0