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:

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.

Tagged with: , , , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Subscribe

  

Subscribe to get the latest Linux news and how to guides directly on your e-mail!