Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list empty files? (Bash)

In order to list empty files I do

find . -name "*.txt" | xargs wc -l | awk -F" " '{if ($1==0) {print $2} }'

or simply

wc -l *.txt | awk -F" " '{if ($1==0) {print $2} }'

It works but it is a bit slow as wc -l counts the number of newline characters in each file while this is not necessary. A process that excludes files as soon as they find a single newline character would be much faster.

How can one list empty files in a performant way?

like image 200
Remi.b Avatar asked Sep 11 '16 00:09

Remi.b


1 Answers

find . -name '*.txt' -size 0

Print files which match *.txt and are of size zero.

like image 180
Jonathan Leffler Avatar answered Oct 01 '22 22:10

Jonathan Leffler