List all unique extensions for files contained in a directory
Solution 1:
Try this:
find . -type f | sed -rn 's|.*/[^/]+\.([^/.]+)$|\1|p' | sort -u
It outputs nothing for:
- Files with no extension
- Files with names that end in a dot
- Hidden files
It also might be useful to pipe it to sort | uniq -c
.
Solution 2:
find . -type f | sed -E 's/.+[\./]([^/\.]+)/\1/' | sort -u
Works on OS X, except for files without extension. My downloads folder:
DS_Store
dmg
exe
localized
msi
nib
plist
pmproj
rar
tgz
txt
webloc
zip
You might need sed -r
instead?
Minor issue: Files without extensions print their name. Hidden files (such as .DS_Store
) print their name without leading .
.