How to "mass" renaming files
Josef Lowder
joe at actionline.com
Fri Aug 19 11:26:34 MST 2005
Can anyone provide a simple shell script command to
change the file names of all the files in a given directory?
from pict0001.jpg to just 01.jpg
from pict0002.jpg to just 02.jpg etc. etc.
with the numbers running to a few hundred pix, all with
the same "pict00..." first part of the filename.
I looked on the 'net to find a shell script to "mass" rename the files
in any given directory and found the example below to rename the
suffix from php3 to just php, but I couldn't figure out how to modify
that to change the filename itself.
ls -d *.php3 | sed 's/\(.*\).php3$/mv "&" "\1.php"/' | sh
I also found a *nix utility on my system named 'rename' but I
couldn't get it to work. Below is an excerpt from the 'man' page
for 'rename' ... but what in the world is 'foo'??
MAN PAGE excerpt:
rename will rename the specified files by replacing
the first occurrence of from in their name by to.
For example, given the files foo1, ..., foo9, foo10, ..., foo278, the
commands
rename foo foo0 foo?
rename foo foo0 foo??
will turn them into foo001, ..., foo009, foo010, ..., foo278.
And
rename .htm .html *.htm will fix the extension of your html files.
More information about the PLUG-discuss
mailing list