18

Where does the rename command come from?

user@host> dpkg -S /usr/bin/rename
dpkg-query: no path found matching pattern /usr/bin/rename
guettli
  • 1,777

3 Answers3

20

Surprisingly, it comes from the rename package.

pilot6@Pilot6:~$ ls -l /usr/bin/rename
lrwxrwxrwx 1 root root 24 окт 17  2013 /usr/bin/rename -> /etc/alternatives/rename
pilot6@Pilot6:~$ ls -l /etc/alternatives/rename
lrwxrwxrwx 1 root root 20 апр 29  2016 /etc/alternatives/rename -> /usr/bin/file-rename
pilot6@Pilot6:~$ dpkg -S /usr/bin/file-rename
rename: /usr/bin/file-rename
Fabby
  • 34,259
Pilot6
  • 90,100
  • 91
  • 213
  • 324
  • 1
    Why does dpkg -S not follow the symlink? Bug or feature? – guettli Jan 19 '17 at 14:47
  • 5
    @guettli feature: "This command will not list extra files created by maintainer scripts, nor will it list alternatives." – muru Jan 19 '17 at 14:49
  • @muru why does dpkg not list alternatives? I don't understand it. – guettli Jan 19 '17 at 14:50
  • 2
    The symlink does not belong to the package itself. – Pilot6 Jan 19 '17 at 14:51
  • 2
    @guettli because it's not dpkg's job. dpkg only deals with installed packages. Use update-alternatives --query rename, it will show you the resolved link path – Sergiy Kolodyazhnyy Jan 19 '17 at 15:02
  • 1
    If a new comer asks a debian/ubuntu expert: "How can I find the matching package for command foo", the expert will say "dpkg -S foo". Who's job is the overall user experience? – guettli Jan 19 '17 at 15:53
  • @guettli certainly not mine, nor Pilot6's nor Serg's. You can make it yours and file a feature request. – muru Jan 19 '17 at 16:13
  • 5
    @guettli See Debian Bug #198220. It would be handy if dpkg/dpkg-query offered this info conveniently. However, I don't think dpkg -S should silently dereference symlinks until it finds a package file. dpkg -S foo isn't supposed to find the command foo, it finds the the package that installed the file foo, and is most useful when invoked with a file's absolute path. It'd be nice if dpkg -S /usr/bin/rename explained why no package provides that symlink, but I think it should still tell the truth that no package does. – Eliah Kagan Jan 19 '17 at 16:57
  • @EliahKagan thank you for providing the relevant bug in debians ticket systems. Is there a way to push this (without coding)? Is there a way to vote or donate for bugs? – guettli Jan 20 '17 at 06:35
12

You will probably find that it's a symbolic link that is managed by the update-alternatives mechanism:

$ ls -l $(which rename)
lrwxrwxrwx 1 root root 24 Jun 29  2016 /usr/bin/rename -> /etc/alternatives/rename

You can see the optional implementations using

$ update-alternatives --list rename
/usr/bin/file-rename
/usr/bin/prename

and can choose between implementations using

update-alternatives --config rename

FWIW file-rename is provided by the rename package, whereas the original prename is provided by perl itself. From apt-cache show rename:

This package provides both a perl interface for renaming files (File::Rename) and a command line tool 'rename' which is intended to replace the version currently supplied by the perl package.

As if this was not already confusing enough, you may also come across yet another rename from the util-linux package - see What's with all the renames?

steeldriver
  • 136,215
  • 21
  • 243
  • 336
  • Why isn't rename.ul available as a rename alternative? – Random832 Jan 19 '17 at 17:21
  • @Random832 For command-line utilities, alternatives are supposed to be syntax-compatible replacements for each other (at least for some common core of functionality); rename.ul and prename do not qualify. – zwol Jan 19 '17 at 22:13
7

If we're talking about /usr/bin/rename, which is a pretty nifty perl script, then rename command belongs to its own separate package.

rename:
  Installed: 0.20-4
  Candidate: 0.20-4
  Version table:
 *** 0.20-4 500
        500 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages
        500 http://archive.ubuntu.com/ubuntu xenial/main i386 Packages
        100 /var/lib/dpkg/status

In case of Korn shell and its derivatives, rename is a shell built-in command.

$ echo $SHELL
/bin/mksh

$ type rename
rename is a shell builtin
Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497
  • Why "If we're talking about /usr/bin/rename"? The question contains the absolute path. – guettli Jan 19 '17 at 14:52
  • 1
    @guettli The question asks about rename command, yet rename isn't only referred to /usr/bin/rename , as you see in my answer. Users who have ksh or mksh shells might not be aware of that. When I personally started with mksh , I was very baffled when rename wasn't accepting the regular expression, until I realized those were two different things. Also, don't take my words "If we're talking about x" literally, consider it as a way of saying "In case of " – Sergiy Kolodyazhnyy Jan 19 '17 at 14:59