5 Find Oneliners for removing all the empty files with a certain extension

All this 5 oneliners do the same thing. Remove the empty files with a certain extension (.txt in my example), with the Linux and Unix powerfull find command:

Watch Free Movies

One:

$ find /path/to/dir -type f -name '*.txt' -empty -exec rm {} \;

Two:

$ find /path/to/dir -type f -name '*.txt' -size 0 -exec rm {} \;

Three:

$ find /path/to/dir -type f -name '*.txt' -empty -delete

Four:

$ find /path/to/dir -type f -name '*.txt' -empty | xargs rm -f

Five:

$ find /path/to/dir -type f -name '*.txt' -size 0 | xargs rm -f

You can read the other find oneliners here.

Scroll to Top