[Sussex] Rename a list of files

akaDruid akadruid at gmail.com
Wed May 11 11:41:56 UTC 2005


> I have a problem, I would like to write a bash
> script or enter a command to rename a list of
> files numerically.

> Can anyone help?

I might use sed for this, if you are looking for an advanced
soloution.  There is a manual online at:
http://www.gnu.org/software/sed/manual/sed.html
and a guide that I found useful at:
http://www.dbnet.ece.ntua.gr/~adamo/sed/OLD/sedtut_1.html

Two things stand out to me:
1. How do you propose to define the list of files to renamed (e.g.
based on location, pattern matching etc).

2. How do you want the resulting file names determined (e.g. a mask
such as img##.jpg, a section of the original named followed by a
number, do you just want sequential numbers to match the order of the
original files, etc).

At the simplest, you could just shellscript this psuedo code or
something like it:
$i=1
For ($file in $dir) {
move $file "img".$i.".jpg"
$i++
}

The above assumes that you want everything in $dir and that the
listing is the order in which you plan to number the files.

(excuse my awful representation, it is my lot in life to write code in
sybase powerbuilder and php, and i'm a bit of linux newbie).

Apologies if someone already sent a definitive answer, I was reading
the list on digest mode :)

Colin




More information about the Sussex mailing list