Ubuntu – What’s the difference between the different “rename” commands

command linepackagingperlrename

Since Ubuntu 14.04 there are at least three rename commands:

  1. rename provided by the util-linux package, see man rename.ul
  2. rename provided by the perl package, see man prename
  3. rename provided by the rename package, see man file-rename

Questions:

  • What exactly are the differences between those commands?
  • How come there are multiple packages providing different commands using the same name – I suppose that's not an accident, or is it?
  • Wouldn't it be rather straightforward for the perl package to either include the “full” rename command or not include any rename command at all? Why is this seemingly uncomplete split sustained until at least Ubuntu 17.04?

This question has already been asked on U&L (as I found out later):
What's with all the renames: prename, rename, file-rename?

Best Answer

How come there are two packages providing different commands using the same name (if not by accident)?

That's not unusual. Authors typically pick the simplest command name they think of, so if two people write a command to rename files, it's likely they'll both name it rename. That's one of the reasons behind the Debian Alternatives system - it allows packages providing similarly-named commands to coexist, and for one package to replace another. For example, there are multiple AWK implementations - mawk, original-awk, gawk (though they all refer to themselves as awk). With the alternatives system, you can install them all at the same time, and conveniently switch between any of them as the default awk.

In this specific case, prename comes from the Perl source code. The Debian package maintainers originally had rename be the Perl one, then switched to the alternatives system, to accommodate the rename from util-linux. Then somebody wrote an improved version of Perl's rename in the File-Rename Perl module, which was then added as another alternative. But that's not even the only Perl module for renaming files.

Wouldn't it be rather straightforward for the perl package to either include the “full” rename command or not include any rename command at all? Why is this seemingly uncomplete split sustained until at least Ubuntu 17.04?

See Debian bug #735134 for how this situation evolved. Debian maintainers generally prefer going at least one release when doing something drastic, like replacing a working command with another. prename was kept around for jessie, and has now been removed for buster. In addition, it looks like rename will no longer be under the alternatives system, since rename.ul is too incompatible. rename will be just file-rename.

Since Ubuntu generally picks up packaging changes from Debian, what happens to rename in Debian will be picked up by Ubuntu sooner or later, probably in 18.04. It seems to be too late for 17.10.

What exactly are the differences between those commands?

Fundamentally, both prename and file-rename run Perl expressions to rename files. file-rename is just actively maintained and supports more options. rename from util-linux works entirely differently, has its own rules for patterns.