17

Where does the rename command come from?

user@host> dpkg -S /usr/bin/rename
dpkg-query: no path found matching pattern /usr/bin/rename
  • 3
    The rename that ships with Fedora is a different one, though. It seems to be a compiled program and it is not nearly as powerful as the rename that ships with Ubuntu. So be careful when you use scripts on a different Linux distribution. – Martin Ueding Jan 20 '17 at 9:21
  • @MartinUeding can you please leave a comment here: askubuntu.com/questions/873661/… – guettli Jan 20 '17 at 9:36
  • This answer says it's prename – Gallifreyan Jan 20 '17 at 10:38
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
  • 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
  • 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
  • 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
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?

  • 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
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.