Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I count the different file types within a folder using linux terminal?

Hey I'm star struck on how to count the different amounts of file types / extensions recursively in a folder. I also need to print them to a .txt file.

For example I have 10 txt's 20 .docx files mixed up in multiple folders.

Help me !

like image 429
user2005383 Avatar asked Dec 27 '22 10:12

user2005383


1 Answers

find ./ -type f |awk -F . '{print $NF}' | sort | awk '{count[$1]++}END{for(j in count) print j,"("count[j]" occurences)"}'

Gets all filenames with find, then uses awk to get the extension, then uses awk again to count the occurences

like image 166
Tobias Snoad Avatar answered Jan 05 '23 18:01

Tobias Snoad