HomeTutorsContact

Using find command to recursively look for files with a specific extension

By Gulshan Saini
Published in Linux
December 08, 2021
1 min read

I started this blog in May 2020. Today out of curiosity, I wanted to count the number of blog posts that I have written so far on this blog. The posts on this blog are written in markdown and have an extension of .mdx. Instead of manually counting all the files having .mdx extension I thought it would be easy to use the find command. The good part is, it is available on both Linux and MAC operating systems.

So I opened the terminal and changed the directory to blog posts directory (inside this directory all the posts including their respective images are stored).

Next, I used the below command to list down all the files

find . -type f -name "*.mdx"

Below is what I got

find command: output
find command: output

Counting the files returned by the find command

Next, step was to count the number of files that were returned by the find command. To achieve this you need to pipe the previous command with wc -l as follows

find . -type f -name "*.mdx" | wc -l

wc -l counts the number of lines

find command: counting files: output
find command: counting files: output

So in just a matter of a few seconds, I came to know how lazy I am 😃. I just posted 88 blog posts in one and a half years (~approx).

👉 If you found this post useful, bookmark this page (⌘ + d / ctrl + d) for your future reference 😃


Tags

#find#linux
Previous Article
CSS RGB color codes including hex values
Gulshan Saini

Gulshan Saini

Fullstack Developer

Topics

Angular
JavaScript
Linux
ReactJS
Typescript

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.
© 2022, All Rights Reserved.

Quick Links

Contact UsBrowserCSSPythonPuppeteer

Social Media