I have a tool that wants a filename.ext to make a bunch of files, and also wants a directory name to put them in. In my case filename/ would do.


cmd Filename1.ext Filename
cmd Filename2.ext Filename2

I've been trying to tackle it via find, but maybe there is a better way?
find . -iname "*.ext" -exec cmd ... ?


2 Answers 2


I found a solution, not sure if it is optimal.
find -iname "*.ext" -exec bash -c 'cmd "$1" "${1%.*}"' bash {} \;

This will call cmd filename.ext filename for each matching file

Updated solution with input from ilkkachu, thanks!

  • Do you mean to recurse down into subdirectories? (this was not explicitly mentioned in the question) Since you're using -iname rather than -name, does that mean that you expect there to be files with suffixes .Ext, ExT, .EXT, etc.?
    – Kusalananda
    Commented Aug 8, 2021 at 17:47

If you know what's the extention of the <filename.ext>, try

for i in *.ext; do cmd "$i" "$(basename -s .ext "$i")"; done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .