xargs question

I'm trying to rename a number files, adding a prefix to their name, and found what seems to be an easy way of doing it:-

http://www.mmtek.com/dp20090929/node/201

Code:
ls | xargs -I {} mv {} PRE_{}

except it doesn't work for me... all the files end up being renamed as 'PRE_' and the original filename is not appended.

Any idea what I'm doing wrong?
 
The {} moniker is a place-holder for find(1). It looks like you tried to use a -exec from find(1) out of context.

Edit: Scratch that. The -I {} replaces the place-holder string. In that case you probably need to put quotes around it to prevent the shell from trying to interpret the accolades (they have special meaning in csh(1))
 
Why not a simple shell loop?
Code:
for file in *; do
   mv "${file}" "PRE_${file}"
done
This assumes that you are renaming all the files in your current directory.
 
Back
Top