Question: I recently converted all of my FLAC files to a lower sampling rate of 44.1 kHz and bit depth of 24 bits (because iPhone/iPod don't support anything above that) using XLD on my Mac OS 10.7 (Lion).

Although I told XLD to overwrote all previous files, XLD appended a `(1)` at the end of very file like from

```
some_song.m4a

```

to

```
some_song(1).m4a

```

So now I want to remove that `(1)` from all the FLAC files I converted.

I know I could have probably used some program or even an AppleScript to rename the files, but I wanted to learn using the old school way of command line.

I know that `find . -name *\(1\).m4a` will grab all the converted FLAC file.

Next I know I have to do something with `-exec` and `mv` to rename all the found files. But what I can't figure out is how to keep the original filename and only remove the `(1)`.

Maybe I need to do some group regex capturing to store the part of the filename that I don't want to modify? Or maybe it's not possible to do everything in one line and I should create a shell script (which I'm not that comfortable doing, but I'm willing to give it a try).

Any tips or suggestions are welcomed! Thanks!

Answer: 
On Debian and Ubuntu, I can use `rename 's/\(1\)//' *.m4a` to solve your problem.
The following approach gives you ability to preview/prune the generated commands *before* executing them, and it is very portable: it should work not only on a mac, not only with bash, and not only with GNU sed; even on systems without `find`(1) command it is possible to substitute it with `du`(1) without a trouble.

```
find . -name '*(1).m4a' |
sed 's/\(.*\)(1).m4a$/mv & \1.m4a/' 

```

If happy with the printed commands, re-run with `| sh -x` appended.

If concerned about spaces in file names, add another *s* to escape all spaces:

```
find . -name '*(1).m4a' |
sed -e 's/ /\\ /g' -e 's/\(.*\)(1).m4a$/mv & \1.m4a/'

```

If other special chars are expected, it gets a litle bit more tricky:

```
find . -name '*(1).m4a' |
sed -e "s/'/'\\\\''/g" -e 's/\(.*\)(1).m4a$/mv '\''&'\'' '\''\1.m4a'\'/

```

First function converts all `'` into a form such that these are taken literally when in the middle of `'...'`-escaped string. Second function generates *mv* commands whose arguments are enclosed within `'...'`.