REXX equivalent in (Ubuntu) Linux?

Lennart Sorensen lsorense-1wCw9BSqJbv44Nm34jS7GywD8/FfD2ys at public.gmane.org
Fri May 21 15:12:55 UTC 2010


On Fri, May 21, 2010 at 10:17:03AM -0400, Stephen wrote:
> I want to do a big rename of files on my Linux system.
>
> I have ripped a large number of CD's, and the filenames start with the  
> track number. But they go 1,2,3 ...10,11,12
>
> When my PS3 accesses my (Linux) media server, it sees these as  
> 10,11,12,1,2....
>
> So to get the right order I want to change the files to 01,02,03...
>
> The files are in directories:
>
> /home/stephen/music/*artist*/*album*/filenames
>
> What should I look at?

Well if the files were for example

1_blah.mp3
2_blah.mp3
etc.

Then you could do:

rename 's/^([0-9])_/0$1_/' *

in each directory.

To make it work with directories maybe:

find . -type f |xargs rename 's%/([1-9])(_[^/]*)$%/0$1$2%'

That changed:

./test1
./test1/10_foo
./test1/11_foo
./test1/12_foo
./test1/1_foo
./test1/2_foo
./test1/3_foo
./test1/4_foo
./test1/5_foo
./test1/6_foo
./test1/7_foo
./test1/8_foo
./test1/9_foo
./test2
./test2/10_foo
./test2/11_foo
./test2/12_foo
./test2/1_foo
./test2/2_foo
./test2/3_foo
./test2/4_foo
./test2/5_foo
./test2/6_foo
./test2/7_foo
./test2/8_foo
./test2/9_foo

into

./test1
./test1/01_foo
./test1/02_foo
./test1/03_foo
./test1/04_foo
./test1/05_foo
./test1/06_foo
./test1/07_foo
./test1/08_foo
./test1/09_foo
./test1/10_foo
./test1/11_foo
./test1/12_foo
./test2
./test2/01_foo
./test2/02_foo
./test2/03_foo
./test2/04_foo
./test2/05_foo
./test2/06_foo
./test2/07_foo
./test2/08_foo
./test2/09_foo
./test2/10_foo
./test2/11_foo
./test2/12_foo

-- 
Len Sorensen
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list