Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Slackware This Forum is for the discussion of Slackware Linux.


  Search this Thread
Old 09-26-2015, 10:48 AM   #1
LQ Newbie
Registered: Aug 2010
Location: Internet
Distribution: Debian, Slackware, and other...
Posts: 21

Rep: Reputation: 3
A powerful rename

The rename program coming with Slackware is the really basic utility from util-linux-2.21.2 package.

I spend a lot of time on Debian and I'm used to the Perl rename with proper options (-n for dry-run actions) and powerful regex to play.
For example, I find always useful the grouping:
sim@rame:/tmp/test$ ls
file_0.pdf  file_10.pdf  file_3.pdf  file_5.pdf  file_7.pdf  file_9.pdf
file_1.pdf  file_2.pdf   file_4.pdf  file_6.pdf  file_8.pdf
sim@rame:/tmp/test$ # -n = this is a test
sim@rame:/tmp/test$ rename -n 's/^(\w+)_(\d+)\.pdf$/$2_$1.pdf/' *pdf
rename(file_0.pdf, 0_file.pdf)
rename(file_1.pdf, 1_file.pdf)
rename(file_10.pdf, 10_file.pdf)
rename(file_2.pdf, 2_file.pdf)
rename(file_3.pdf, 3_file.pdf)
rename(file_4.pdf, 4_file.pdf)
rename(file_5.pdf, 5_file.pdf)
rename(file_6.pdf, 6_file.pdf)
rename(file_7.pdf, 7_file.pdf)
rename(file_8.pdf, 8_file.pdf)
rename(file_9.pdf, 9_file.pdf)
sim@rame:/tmp/test$ # it seems ok
sim@rame:/tmp/test$ rename 's/^(\w+)_(\d+)\.pdf$/$2_$1.pdf/' *pdf
sim@rame:/tmp/test$ ls
0_file.pdf   1_file.pdf  3_file.pdf  5_file.pdf  7_file.pdf  9_file.pdf
10_file.pdf  2_file.pdf  4_file.pdf  6_file.pdf  8_file.pdf
So, if you need a more powerful rename you can install the File::Rename module from cpan: it will come with the rename script in /usr/local/bin.

Last edited by simotrone; 09-26-2015 at 10:50 AM.
Old 09-26-2015, 11:35 AM   #2
LQ Newbie
Registered: Sep 2015
Distribution: OpenSUSE
Posts: 7

Rep: Reputation: Disabled
I always like to do these things with awk:

ls *.pdf | awk '{print "mv "$1" "gensub(/^(.*)_(.*)\.pdf/,"\\2_\\1.pdf",$1)}' | sh
(rather than learning new commands)

Last edited by Emphyrio; 09-26-2015 at 11:42 AM.
Old 09-26-2015, 02:01 PM   #3
Registered: May 2010
Location: Stumptown
Distribution: Slackware -current 32bit!
Posts: 537

Rep: Reputation: 202Reputation: 202Reputation: 202
Similar to your solution I guess..
Old 09-26-2015, 06:08 PM   #4
Registered: Jun 2015
Distribution: Debian Jessie 64
Posts: 163
Blog Entries: 9

Rep: Reputation: Disabled
I always used mv to rename. An actual rename command is a surprise to me.
Old 09-27-2015, 12:21 AM   #5
Registered: May 2004
Distribution: BSD
Posts: 269

Rep: Reputation: 119Reputation: 119
There is also rename by Perl wiz (and former Slackware user) Aristotle Pagaltzis.
Old 09-27-2015, 03:15 AM   #6
Registered: May 2010
Posts: 613

Rep: Reputation: Disabled
I use the stock rename for things like .JPG -> .jpg, it works great. This thread made me read about regexes yet again, and yet again I am not a fan. A regex match always halts, so it's not as good as TM. So if I had an real bad itch, I would scratch it with feeding file names into a turing-complete process, which boils down to a custom script in your favorite language.
Old 09-27-2015, 05:17 AM   #7
Senior Member
Registered: May 2008
Posts: 4,811
Blog Entries: 14

Rep: Reputation: Disabled
I've spent the best part of 20 years on slackware and I'm used to the util-linux version of 'rename'. IMO if debian felt the need to ship the regex based rename tool, they should have given it a different name so that both can coexist without confusing the user.
Old 09-27-2015, 07:17 PM   #8
Senior Member
Registered: Sep 2004
Distribution: slackware
Posts: 2,159

Rep: Reputation: 508Reputation: 508Reputation: 508Reputation: 508Reputation: 508Reputation: 508
At the risk of sounding like a GUI-using softy, I've found the "Bulk Rename" utility provided by XFCE to do a superb job with very little effort...


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Choosing OS for my Old but Powerful PC :) Mitizaro Linux - Distributions 13 11-17-2012 08:56 PM
Rename network interface (Rename ppp0 ...) Nicolas1390 Linux - Newbie 2 08-08-2011 03:14 AM
Is this pc powerful enough? trapperjohn117 Linux - Hardware 5 01-11-2007 04:54 PM
which powerful QT or GTKMM? Barq Linux - General 1 03-13-2005 12:39 PM
which linux is the most powerful? indy317 Linux - Distributions 12 06-03-2003 05:14 AM > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 12:07 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration