Ubuntu – Remove files of 0 bytes in size via command line

command linefiles

So, I got a directory filled with other directories, and I was wondering if it was possible to remove files that have no size. Typically these files are 0 bytes and since I want to merge all these subdirs I could replace a perfectly legit file with a weightless 0 byte file, and there goes my legit file. Any way to remove the zero byte files?

Best Answer

Use the Find command to find files by size and print file names to standard output.

find . -type f -size 0b -print

substitute -print with -delete to delete the files rather than print them on screen.

find . -type f -size 0b -delete
Related Question