Where does the rename command come from?
user@host> dpkg -S /usr/bin/rename
dpkg-query: no path found matching pattern /usr/bin/rename
Where does the rename command come from?
user@host> dpkg -S /usr/bin/rename
dpkg-query: no path found matching pattern /usr/bin/rename
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
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
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
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?
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
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
renamethat ships with Fedora is a different one, though. It seems to be a compiled program and it is not nearly as powerful as therenamethat ships with Ubuntu. So be careful when you use scripts on a different Linux distribution. – Martin Ueding Jan 20 '17 at 09:21prename– Gallifreyan Jan 20 '17 at 10:38