Search code examples
linuxbashlistfindfile-type

Find/list only file types recursive in a directory


how can i search for files and give only a list of mimes or types out.

example:

dir
-file1.pdf
-file2.pdf
-dir2
--file3.png
--file4.pdf

wished output:

pdf
png

Edit

Found also a solution, but does not make a difference between upper and lowercase and also not .peng and .png

find . -type f -printf '%f\n' | sed 's/^.*\.//' | sort -u

Solution

  • Use find's -exec option together with any solution that extracts the extension. Then pipe through sort -u to remove duplicates.

    find dir -type f -exec bash -c 'printf %s\\n "${@##*.}"' x {} + | sort -u
    

    Files without extensions will be listed too. To filter them out add the option -name '*\.*' before -exec.