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:


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


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


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


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


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

You can read the other find oneliners here.

Liked it? Take a second to support Geekster on Patreon!
Tagged with: , , , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

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


Support LinuxG via Patreon
Support LinuxG.net on Patreon!


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