Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

List small files in a directory and output a summary total

I want to (1)identify files in a directory that are under 64 bytes and (2)print out their names and size. The following one-liner does the job:

find . -size -64c -exec ls -lh {} \;|awk '{print $5, $9}'

This prints out a list of files, along with their size.
Can I easily extend this one-liner to also print out the total number of files found. In effect to pipe the file list into a wc -l command?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Can I easily extend this one-liner to also print out the total number
of files found.

Yes, by printing NR at the END block:

... | awk '{ print $5, $9 } END { print NR }'

You can also include a suffix:

... END { print "Total number of files found: " NR }'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading