changing multiple file names

karavite

Registered
Although I could do this with the GUI faster than it takes to write this post, I was wondering how I could use a terminal command or script to change a group of file names. I am setting up Fruitmenu to have folders for all my applications and this required making aliases in various directories under the fruitmenu directory. I just want to get rid of the " alias" on every file in a directory - basically a batch rename.

I though sed might be the answer, but it seems to only work on file contents, not file names.

Thanks in advance.
 
If you're in tcsh, this should do the trick:

Code:
foreach filename ( * )
set newname=`echo $filename | sed 's/ alias$//'`
mv "$filename" "$newname"
end

This renames every file in the current directory to the same thing without an ending " alias" (so file alias becomes file, but filealias stays).
 
Thanks - that is cool and it works. Sorry to bug you, but how can I make this into a script that I can call when I am in a certain directory (have to run on the current directory). I tried a few things with no luck.

Thanks
 
Put the following line first in the file,

Code:
#!/bin/tcsh

then the stuff from before, and save to a file (make sure it uses Unix-style line breaks). In the Terminal, do a

Code:
chmod 755 /path/to/file

to make it executable.
 
You could try mmv, builds on OS X and works great.
Don't remember where I downloaded the source though, but it should be easy to find.
If you don't want to compile it yourself i can mail it to you.
------------
A program by Vladimir Lanin called "mmv" that does this job
nicely was posted to comp.sources.unix (Volume 21, issues 87 and
88) in April 1990. It lets you use

mmv '*.foo' '=1.bar'
 
Back
Top