I am trying to convert all files in a given directory with the suffix ".foo" to files containing the same base name, but with the suffix changed to ".bar". I can do this with a shell script and a for loop, but I want to write a single line that will achieve the same goal.
Goal:
Input: * .foo
Output: * .bar
Here is what I tried:
find . -name "*.foo" | xargs -I {} mv {} `basename {} ".foo"`.bar
This is close, but false. Results:
Input: * .foo
Output: * .foo.bar
Any ideas on why this suffix is not recognized by basename? The quotation marks around ".foo" do not fit, and the results are the same if they are omitted.
source share