LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


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

Rep: Reputation: 4
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:
Code:
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 09:50 AM.
 
Old 09-26-2015, 10:35 AM   #2
Emphyrio
LQ Newbie
 
Registered: Sep 2015
Distribution: OpenSUSE
Posts: 7

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

Code:
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 10:42 AM.
 
Old 09-26-2015, 01:01 PM   #3
STDOUBT
Member
 
Registered: May 2010
Location: Stumptown
Distribution: Slackware64
Posts: 583

Rep: Reputation: 242Reputation: 242Reputation: 242
@simotrone
http://slackbuilds.org/repository/14.1/system/rename/
Similar to your solution I guess..
 
Old 09-26-2015, 05:08 PM   #4
pzognar
Member
 
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-26-2015, 11:21 PM   #5
lems
Member
 
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, 02:15 AM   #6
qweasd
Member
 
Registered: May 2010
Posts: 621

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, 04:17 AM   #7
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
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, 06:17 PM   #8
rkelsen
Senior Member
 
Registered: Sep 2004
Distribution: slackware
Posts: 4,448
Blog Entries: 7

Rep: Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553
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...
 
  


Reply



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 07:56 PM
Rename network interface (Rename ppp0 ...) Nicolas1390 Linux - Newbie 2 08-08-2011 02:14 AM
Is this pc powerful enough? trapperjohn117 Linux - Hardware 5 01-11-2007 03:54 PM
which powerful QT or GTKMM? Barq Linux - General 1 03-13-2005 11:39 AM
which linux is the most powerful? indy317 Linux - Distributions 12 06-03-2003 04:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 10:35 PM.

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