missionMan
missionMan

Reputation: 903

How can I list how many files are in each directory in OSX terminal?

How can I list how many files are in each directory together sub-directoies?

i found that:

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

but this is count all. I need the count for each sub-directory separately

Expected sample result is:

home/folder1 12
home/folder2 10
home/ 22
etc/folder1 100
etc/folder2 200
etc/folder3 10
etc 310
...

Is there a way I can count the number of files in each directory like this?

Upvotes: 0

Views: 783

Answers (1)

gogaz
gogaz

Reputation: 2400

You have to loop over your directories and find .txt files inside each of them

find . -type d -exec sh -c 'echo -n "{} " && find {} -name "*.txt" | wc -l' \;

Upvotes: 1

Related Questions