# Mass Rename



## piercedfreak (May 18, 2013)

I have about 800 files that I wish to rename, they all have *(U)* in them, which I wish to remove.

I installed rename from ports, and tried
`rename 's/\(U\)//' *`
but it returned 
`rename: too many arguments.`
Thinking there might be too many files to do at once, I then tried
`rename 's/\(U\)//' A*` and ended up with the same results.

Can someone point me in the right direction?


----------



## jb_fvwm2 (May 18, 2013)

```
rename -s/U/ *.fil
```
Some variation of that? Or maybe install `linrename; gprename; tren...`


----------



## ShelLuser (May 18, 2013)

In this case you'd definitely want a _for...next_ loop. The problem is that the amount of files is so much that it doesn't fit on the commandline as parameter. Keep in mind: the * you're using in the command up there basically gets replaced by everything in the current directory and that gets put behind the command. But there is only so much you can put on the commandline.

So the best way, in my opinion, is to go over all files one by one. While still automating it of course. I also wouldn't rely on external tools either, sed is more than enough.

For example like so:


```
#/bin/sh
for a in *.fil; do mv $a `echo $a | sed -r "s/\(U\)//g"`; done
```


----------



## Terry_Kennedy (May 18, 2013)

piercedfreak said:
			
		

> I installed rename from ports, and tried
> `rename 's/\(U\)//' *`
> but it returned
> `rename: too many arguments.`


Normally wildcards are globbed by the shell, so the utility sees 800-odd arguments when you give the command as shown above. You could try:
`rename 's/\(U\)//' \*`
to pass the * to the utility as a literal. That may help.

At larger numbers of files, you can run into limits imposed by kern.argmax. 

<gripe>Despite a number of requests over the years by various users to increase kern.argmax, the developers have declined, usually stating "if you have that many files, you should be using some other method than wildcards". I guess we should all run in < 4MB and limit ourselves to 8-character usernames, too. Of course, it did get raised when it broke kernel builds.</gripe>

Just search for "freebsd arg_max" for the history (and a number of alternative methods / workarounds).


----------



## jb_fvwm2 (May 19, 2013)

BTW I put these commands that I've found eventually worked as expected, in `/etc/motd` so there is one file to grep [or read sections of] for renaming, buildworld, mergemaster flags, tar, sed...


----------

