Posted By

tm on 01/18/10


Tagged

Bash results count find


Versions (?)

Count results of find


 / Published in: Bash
 

  1. # Most any solutions use a .... | wc -l, which is wrong. It breaks (at least) if
  2. # files contain newlines. Thus the right way to do it is:
  3.  
  4. find [find expression] -exec printf '.' \; | wc -c
  5. (or, more efficiently)
  6. find [find expression] -exec printf %.s. {} + | wc -c
  7.  
  8. # e.g. to find all jpg-files which are larger than 1kB, you can use:
  9.  
  10. find . -type f -name \*.jpg -size +1024c -exec printf '.' \; | wc -c
  11.  
  12. # the "weird" -size argument is POSIX compliant. On a GNU system you could use
  13. # "-size +1k"

Report this snippet  

You need to login to post a comment.