As the year comes to a close, I like to look back and see how many blog posts I have written for the year. My blog is powered by Jekyll and I like to keep my posts organized by year, in directories.
With all of my posts in one place, all I need to do is list
ls out the files
in a given year’s directory, and then pipe
| the results to the word count
wc with the argument that tells it to count just the number of lines
The command in all of it’s glory looks like this:
ls | wc -l
With the result being just a plain ol’ integer.
This is great if you know that there are no directories in the directory you’re
trying to count files in. If there are directories in there, or if you’re just
not sure, you can swap out
ls for the
find . -type f | wc -l
Neither method will traverse into directories and simply counts the files in the current directory. I’ll save those more advanced commands for another post!