How to "mass" renaming files

Sean Horan sean at emvis.net
Fri Aug 19 11:47:58 MST 2005


for I in *.jpg; do mv $I `echo $I |sed s#pict00##`; done

you can type that directly on the command line, which as I gather from 
your question will strip out the pict00 as you want.  this works for up 
to 99 files of course.

--sean

Josef Lowder wrote:
> 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. 
> 
> ---------------------------------------------------
> PLUG-discuss mailing list - PLUG-discuss at lists.plug.phoenix.az.us
> To subscribe, unsubscribe, or to change  you mail settings:
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss



More information about the PLUG-discuss mailing list