I want to rename multiple files (file1 ... filen to file1_renamed ... filen_renamed) using command find command:find . -type f -name 'file*' -exec mv filename='{}' $(basename $filename)_renamed ';'But getting this error: mv: cannot stat filename=./file1: No such file or directoryThis not working because filename is not interpreted as shell variable.
How to rename multiple files using find
shell;find
The following is a direct fix of your approach:find . -type f -name 'file*' -exec sh -c 'x={}; mv $x ${x}_renamed' \;However, this is very expensive if you have lots of matching files, because you start a fresh shell (that executes a mv) for each match. And if you have funny characters in any file name, this will explode. A more efficient and secure approach is this:find . -type f -name 'file*' -print0 | xargs --null -I{} mv {} {}_renamedIt also has the benefit of working with strangely named files. If find supports it, this can be reduced to find . -type f -name 'file*' -exec mv {} {}_renamed \;The xargs version is useful when not using {}, as infind .... -print0 | xargs --null rmHere rm gets called once (or with lots of files several times), but not for every file.I removed the basename in you question, because it is probably wrong: you would move foo/bar/file8 to file8_renamed, not foo/bar/file8_renamed.Edits (as suggested in comments):Added shortened find without xargsAdded security sticker