3

This question already has an answer here:

How can I use the find command to recursively list all the file extensions in a directory? Using wildcards I can find all the files of a certain type:

find . -iname '*.mp3'

but what I want to to list to search a directory and all sub directories and list all of the file extensions found.

marked as duplicate by don_crissti, Wouter Verhelst, steve, Eric Renouf, Anthon Dec 24 '16 at 14:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Duplicate unix.stackexchange.com/q/111949/98965 – Mongrel Dec 19 '16 at 11:47
  • 2
    @GAD3R, @Mongrel I think this not what the OP wanted. From how I understand the question he wants to use find to get a list of all extension (not files) that are found, e.g. find [find magic] -> .c, .h, .cpp, see this solution below unix.stackexchange.com/a/331389/64248. So I vote to leave this question open. – countermode Dec 19 '16 at 13:20
  • @countermode - it's a dupe of another Q - see the link in my comment above – don_crissti Dec 20 '16 at 14:40
  • Not sure why it matters if it was a duplicate post as I answered my own question before anyone suggested it was a duplicate... I say close the question... I tried to delete it myself, but could not. – John D Dec 21 '16 at 15:49
4

A little more searching revealed this solution:

find . -type f | awk -F'.' '{print $NF}' | sort| uniq -c | sort -g

Not sure why this link did not show up in previous searches.

1

This would be more robust than your solution:

find . -type f -name '*.*' | awk -F. '{print $NF}' | sort | uniq -c | sort -g

That is, since you're looking for the part of a filename following a dot, it's important to add that detail to filters of find. Otherwise files without an extension will give strange results: the entire path may be printed, or if the path contained a dot in one of the intermediary subdirectories, then a partial path after the last dot will be printed.

Not the answer you're looking for? Browse other questions tagged or ask your own question.