rename v. script

Jeff Kinz jkinz at kinz.org
Fri May 20 03:18:06 UTC 2005


On Fri, May 20, 2005 at 09:36:22AM +0800, Matt Arnilo S. Baluyos (Mailing Lists) wrote:
> On 5/20/05, THUFIR HAWAT <hawat.thufir at gmail.com> wrote:
> > this seems to be the briefest and most common solution.  thanks for
> > the addition tip, snipped, for just changing files which begin with a
> > digit, which I will file away.
> 
> very useful discussion here.
> 
> how about different ways of renaming *.JPG files to *.jpg? (i.e.
> change to the file extension to lowercase while retaining the file
> name)

The Linux rename command works a little differently from the DOS/Win
version:

To do what you want, in one simple line:

rename JPG jpg *

NAME      rename - Rename files

SYNOPSIS  rename from to file...

DESCRIPTION
       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.



Here's a test case, all done for you.

[jkinz at redline test]$ for i in `seq 1 30` ; do touch ${i}.JPG ; done
[jkinz at redline test]$ ls
1.JPG   13.JPG  17.JPG  20.JPG  24.JPG  28.JPG  4.JPG  8.JPG
10.JPG  14.JPG  18.JPG  21.JPG  25.JPG  29.JPG  5.JPG  9.JPG
11.JPG  15.JPG  19.JPG  22.JPG  26.JPG  3.JPG   6.JPG
12.JPG  16.JPG  2.JPG   23.JPG  27.JPG  30.JPG  7.JPG
[jkinz at redline test]$ rename  JPG jpg *
[jkinz at redline test]$ ls
1.jpg   13.jpg  17.jpg  20.jpg  24.jpg  28.jpg  4.jpg  8.jpg
10.jpg  14.jpg  18.jpg  21.jpg  25.jpg  29.jpg  5.jpg  9.jpg
11.jpg  15.jpg  19.jpg  22.jpg  26.jpg  3.jpg   6.jpg
12.jpg  16.jpg  2.jpg   23.jpg  27.jpg  30.jpg  7.jpg
[jkinz at redline test]$

As a script: (try it!)
 for i in `seq 1 30` ; do touch ${i}.JPG ; done
 ls
 rename  JPG jpg *
 ls





-- 
Jeff Kinz, Emergent Research, Hudson, MA.




More information about the fedora-list mailing list