2

Could you suggest how to use rename.ul under Ubuntu 22.04 ? Many thanks !

    Welcome to Ubuntu 22.04.1 LTS (GNU/Linux 5.10.102.1-microsoft-standard-WSL2 x86_64)
 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
/etc/update-motd.d/50-landscape-sysinfo: 17: cannot create /var/lib/landscape/landscape-sysinfo.cache: Permission denied

  System information as of Thu Aug 11 14:43:22 CST 2022

  System load:  0.0                 Processes:             15
  Usage of /:   15.8% of 250.98GB   Users logged in:       0
  Memory usage: 0%                  IPv4 address for eth0: 172.25.114.46
  Swap usage:   0%


0 updates can be applied immediately.



This message is shown once a day. To disable it please create the
/home/user/.hushlogin file.
user@localhost:~$ rename.ul
rename.ul: command not found
user@localhost:~$ sudo apt-get install util-linux
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
util-linux is already the newest version (2.37.2-4ubuntu3).
util-linux set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
user@localhost:~$ rename
Command 'rename' not found, but can be installed with:
sudo apt install rename
user@localhost:~$ rename.ul
rename.ul: command not found
user@localhost:~$

SOUser
  • 329

2 Answers2

5

rename.ul is the version of rename installed from the util-linux package. If it still existed you would install it with apt install util-linux. However, it has been removed from the upstream Debian package version 2.35.2-5 seemingly because of this submitted bug util-linux: rename.ul is not installed as a possible alternative for the "rename" command.

As far as I can ascertain the functionality is available in the command provided in the rename package (apt install rename), and if you really need rename.ul as a command distinct from rename then you will have to install it from another source.

Examples of use are given in the documentation (man rename). Here is my take, which replaces abc with def in all file names ending with .txt:

rename abc def *.txt

Also see

Chris Davies
  • 116,213
  • 16
  • 160
  • 287
  • But that doesn't work. This is a different rename (once upon a time, and maybe you tested that on a system where it is till so) what was called rename.ul was installed as rename. But on ubuntu 22.04 it is not the case. rename command cannot be used as you suggest (it takes a regex and a list of names. So your example wouldn't work. It should be used as rename s/abc/def/ *.txt.) – chrslg Nov 30 '22 at 17:34
  • @chrslg the official documentation for 22.04 is that rename is as I've described here. – Chris Davies Nov 30 '22 at 17:53
  • No. Look at your own link. That is the documentation of the "rename.ul" from Ubuntu 20. The OP is complaining (correctly) about the fact that this doesn't exist in Ubuntu 22. And that rename (without UL. Which also existed in Ubuntu 20) is not the same. Try to click on Ubuntu 22 on your own source. You can't. Because that rename.ul has been removed. The remaining rename, is not working as you described (and that is what bothers the OP. Who knows how to use rename but doesn't want to use it that way) – chrslg Nov 30 '22 at 17:58
  • Apparently, you don't have Ubuntu 22 yourself. I have. I can confirm you that your example would just fail: Bareword "abc" not allowed while "strict subs" in use at line 1, in:. And also that man rename.ul gives "no entry", while man rename shows a man page very different from the one you linked: rename [...] [ -e|-E perlexpr]*|perlexpr [ files ]. Besides, the removal of rename.ul has outraged more than one person, and it is a very well known fact that this command is no longer available on Ubuntu 22, and that the rename of Ubuntu 22 is not the same. – chrslg Nov 30 '22 at 18:01
  • The Ubuntu package rename is the (or "a") Perl-based one in all versions the package search knows, including 22.04: "jammy (22.04LTS) (perl): Perl extension for renaming multiple files [universe]". The Ubuntu search doesn't show me the package descriptions, but here's the one from Debian: "This package provides both a perl interface for renaming files (File::Rename) and a command line tool 'file-rename' [...]" – ilkkachu Nov 30 '22 at 21:14
  • And I think this is manual for the rename command from File::Rename, as far as I can find one: https://metacpan.org/dist/File-Rename/view/rename.PL. It has the familiar rename 'perl code' filenames... syntax, not the same as the util-linux one. – ilkkachu Nov 30 '22 at 21:17
  • So, no, if they want the util-linux one, the rename package doesn't seem to be the solution. If the util-linux package doesn't install it any more, building the package from source and installing it manually would seem like a way. – ilkkachu Nov 30 '22 at 21:18
  • Pending further investigation (and yes I do have Ubuntu 22.04 LTS installed) I'd like to delete this answer, but I can't do that. Please bear with me while I take another look – Chris Davies Nov 30 '22 at 22:39
  • @roaima, I think the first paragraph is quite right, though. – ilkkachu Dec 04 '22 at 14:42
2

As I commented in the other answer (of a quite old question, but the correct answer has not been given yet), the rename utils, coming from Perl, has not the same usage as previous rename.ul

Same final utility sure: rename a bunch of files. But not the same interface.

Perl's rename is used (basically) with a regex and a bunch of files

./rename s/abc/def/ *.txt

for example.

While util-linux is used with an old pattern, a new one, and a bunch of files

./rename.ul abc def *.txt

The perl version is more powerful. You can do way more finely tuned rename with regex. And as a regular user of regex, I should prefer it. But I don't, because util-linux version, in practice, covers 100% of my usage. And works well with readline's tab (most of the time, I want to rename the beginning of a filename), while the perl version forces to be more verbose with the keyboard and type more things explicitly.

They are both pretty old commands. So there isn't a new one and an old one here (surely, one of them is newer than the other. I don't know which. But I've known them for a very long time. Maybe a decade or even more).

Once upon a time, the util-linux one was the one installed as rename command. And you had to dig for the perl's one. That is still the case on RedHat for example. But it has been a long time since it is no longer the case on debian-based systems, for which rename command points to the perl version, by default.

But, until Ubuntu 20, the util-linux one was available as command rename.ul. It has been removed from debian, and then from Ubuntu 22. This has outraged more than one person, and there are still people posting "bug tickets" in some sort of protest (knowing very well that it is not really a bug, at most a bad decision).

But, well, on Ubuntu 22, you are stuck with only the perl rename, and the util-linux is not available, not even under another name (such as rename.ul).

For me I use a very simple python script that does the job

#!/usr/bin/python3

import sys import os

if len(sys.argv)<4: print("Usage rename.ul pattern newPattern file1 file2 file3 ...") print("Renames all file1, file2, ... by replacing 'pattern' by 'newPattern' in their filenames") sys.exit(1)

for fn in sys.argv[3:]: os.rename(fn, fn.replace(sys.argv[1], sys.argv[2]))

Of course, it doesn't have the options rename.ul had (to control overwriting, dry-run, what to do with symlinks, etc.). Plus, I've never torture tested it with special characters or things like that. But it does what I have been doing with rename.ul for a decade. You may use it if you wish (with all the "no warranty" and such disclaimer. If you loose a file because of that script, that's on you, not on me :D)

chrslg
  • 151