Shell – Print file name extension using -exec in find

filenamesfindparametershellvariable substitution

I am playing around with -exec flag of find command. I am trying to use the flag to print the extension name of files, using a fairly new Linux distribution release.

Starting simple, this works:

find . -type f -exec echo {} \;

An attempt to use convenient Bash string feature fails:

find . -type f -exec echo "${{}##*.}" \; (bad substitution)

So what should be the correct way to do it?

Best Answer

If you want to use shell parameter expansion then run some shell with exec:

find . -type f -exec sh -c 'echo "${0##*.}"' {} \;
Related Question