HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
cancel
Showing results for 
Search instead for 
Did you mean: 

finding zero kb files

 
madhudeepan
Frequent Advisor

finding zero kb files

i need to list the 0kb files in a particular dir

and need to know how many files present,,, how can i do it
5 REPLIES

Re: finding zero kb files

Files have sizes in bytes. What is 0 Kb? Something that is less than 512, or exactly 0 bytes?

You could use "ls directory | wc -l" to count the files.

You could use awk to do both:
ll directory | awk '
BEGIN { count = 0 }
NF >= 9 {
count += 1
if ($5 < 512) print $0
}
END { print "Total files:", count } '

Re: finding zero kb files

you could try:

cd /mydir
find . -size 0 -type f

and of course for a total:

cd /mydir
find . -size 0 -type f | wc -l

of course that find will walk sub-dirs, so if you want to exclude those try:

cd /mydir
find . \( ! -name . -prune \) -size 0 -type f

and

cd /mydir
find . \( ! -name . -prune \) -size 0 -type f | wc -l

My find syntax is pretty lame though, so there may be a better way to get that...

HTH

Duncan


HTH

Duncan

Re: finding zero kb files

>Duncan: My find syntax is pretty lame though, so there may be a better way to get that.

You could remove the \( \), since the default is "-a".
Sunny123_1
Esteemed Contributor

Re: finding zero kb files

Hi


find / -size 0 -exec ll {} \;


Regards
sunny
Arturo Galbiati
Esteemed Contributor

Re: finding zero kb files

Hi,
cd
ls -l|awk '$9&&!$5 {print $0;i++} END { print i}'

HTH,
Art