Renameing files with the find command

Hi,
I am attempting to rename files in a directory tree, using the find command:

find . -name "file-src*" -exec mv {} file-tgt \;

however, this only moves the file to the current dir: I have also tried:

mv 'find . -name file-src' file-tar

find . -name "file-src*" -exec mv {file-tgt} \;

etc, but to no avail. Any help would be appreciated.

:slight_smile:

There might be better ways to do this.

for i in `find your_dir -type f -name '*'`
do
mv $i $i.mv
done

thanks - I've tried this statement, however I still get the syntax error for the move command; when I replace the mv with echo $i; it writes out the find argument.

e.g. with the move cmd:
for i in 'find . -type f -name "file*" '
do
mv $i $i.bak
done

Output is:
$mv: invalid option

and the echo $i

for i in 'find . -type f -name "file*" '
do
echo $i
done

'find . -type f -name "file*"

:slight_smile:

Are you using single quotes, or backticks? ' or `
Backticks will do what you want. (It's the ` character on the upper-left corner of a standard PC keyboard, usually with the ~ )

If you're using a shell like bash or ksh, you could do it like this:
[...] for each in $(find . -name blah) [...]
But most shells will recognize:
[...] for each in `find . -name blah` [...]

Dont use ' (single quote). Use ` (dont know what it is called but it is left to the '1' key on the key board and above 'TAB')

:frowning:

Sorry LivinFree. probably we replied at the same time.

Good stuff -that works fine. Yah I've had some problems using the ' and ` with commands in the past ....
Thanks again.
:slight_smile: