How to "mass" renaming files

Bill Warner wwarner42 at cox.net
Fri Aug 19 11:50:21 MST 2005


Might be better ways to do it but check out this one:

for each in *.jpg; do 
	new=`echo $each| cut -c7-12`;
	echo mv -i $each $new; #remove echo to actually mv the files
done

This script doesn't actually change anything.  If the output looks ok
you can remove the echo from the line noted and it will actually mv the
files.  It'll make sure to ask you before it overwrites a file with the
-i option to mv.

If the output isn't right you'll have to adjust the -c option for cut.

-Bill


On Fri, 2005-08-19 at 11:26 -0700, 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
-- 
Bill Warner <wwarner42 at cox.net>



More information about the PLUG-discuss mailing list