# xargs question



## balanga (Jul 24, 2017)

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


```
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?


----------



## SirDice (Jul 24, 2017)

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))


----------



## Maxnix (Jul 24, 2017)

Why not a simple shell loop?

```
for file in *; do
   mv "${file}" "PRE_${file}"
done
```
This assumes that you are renaming all the files in your current directory.


----------

