Friday, January 2, 2015

count number of files by type

A basic solution for counting types of files in a directory.

find -type f -name "*.js"|grep -c .js

Taking apart the one-liner , find executes by defining we are looking for a regular file (-type f) and the name ends with js (-name "*.js"). Then we pipe it to grep to suppress the grep output and prints the number of lines coming from the pipe(-c) and matching the .js string.