Gaurav Agarwal
Gaurav Agarwal

Reputation: 57

How to get the number of files with a specfic extension in a directory and it's sub directories on Linux terminal?

The question is itself self-explanatory.

I tried the following command I found somewhere on the internet but it shows the number just in the immediate directory and not its subdirectories.

ls -lR ./*.jpg | wc -l

I am searching for all the files with the extension ".jpg" in the current folder and its subdirectories.

Upvotes: 0

Views: 55

Answers (2)

Jad
Jad

Reputation: 1288

find . -type f -name '*.jpg' | wc -l

Find all the files (type f) that have a name that matches '*.jpg' then count them with wc

Upvotes: 1

pff
pff

Reputation: 11

It's a job for find:

find -name "*.jpg" | wc -l

Upvotes: 1

Related Questions