SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.