Today's Perl Advent Calendar entry talks about the Perl rename command1. This is an awesome command, originally written by Larry Wall himself. However, it's also a constant source of confusion. That's because there is another popular rename command written in C, with a completely different syntax. It's understandable, of course. It's an obvious name. There are probably millions of shell scripts out there called rename.
The recurring problem for Linux enthusiasts like myself is that there are huge populations of users who believe that the rename command on their machine is the Linux rename command. Lots of rpm-based distros (e.g., Red Hat) include the C-ish rename, while many deb-based distros (e.g., Ubuntu) include the Perl-ish rename. Neither one explains this, they just give you a rename command, along with a man page showing how to use it. Naturally, everyone believes this is the same command everyone else has, so it's puzzling when an example that works perfectly for your friend on IRC doesn't work at all for you.
Whenever I spot a comment about "the rename command" I like to point out the existence of the other one. That was my first reaction when I spotted today's Perl Advent calendar, but since that doesn't have a facility for comments, I decided to write this instead. It's just as well, since that's not really a Linux entry. It's clearly talking about the Perl command. On the other hand, this problem doesn't just concern Linux folks. BSD folks (including OS X) may have one or the other rename command as well. The same goes for Windows folks running Cygwin.
Anyway, whenever you are talking about rename, keep in mind that some folks might assume you are talking about the Perl-ish rename found on CPAN, while other folks might assume you are talking about the C-ish rename found in util-linux. It's probably best to be explicit.
I am typing this on an Ubuntu 11.10 machine, which has both commands: rename is the Perl-ish one and rename.ul is the C-ish one. YMMV.
[1] Not to be confused with the Perl function or the Unix system call. Although this whole post is about such confusion, so maybe I should have mentioned it.
I took the time to set up a typepad account just so I could comment and say THANK YOU for taking the time to post this information.
I had already discovered that there was a c version and a perl version, but your link to "the Perl-ish rename found on CPAN" was hugely useful. That's what I ended up going with rather than continuing down my fruitless path of trying to extract just the rename binary from the util-linux package for use on CentOS (Centos is in the dark-ages with the util-linux package. The latest version that that any repositories I was able to find point to util-linux-ng 2.17.2, which doesn't support backreferences, or the -n option, among other things).
Thanks again!
Posted by: Brinman | 02/24/2014 at 02:12 PM
Hey, great! Glad I could help!
Posted by: oylenshpeegul | 02/24/2014 at 05:32 PM