Sometimes it can be useful to know how many files of a particular type are in a directory. This post presents a single line command and a shell function that count the number of files with a given extenstion in the current directory. Directories are searched recursively. A version of the shell function in a stand alone script is also presented.
The basic command to recursively tally files with a given extension looks like this.
The can be used as the basis of a shell script.
countfiles.sh complete listing
The shell script can be used as follows.
Output will look something like this.
Obviously, the countfiles function can be entered in the shell or .profile. In that case it can be used as follows.
.profile partial listing
Obviously, the output is exactly the same as above.