Skip to main content

TIL there is a CLI tool called "rename" for bulk renaming files. How could I be using # for this long and only now just discovered it?

Given the name it turns out to be almost impossible to stumble upon it unless you already know that it is there :)

Yeah it's a good one to know. Right up there with socat, sed, and awk. Not enough people know about those, either.

There are multiple CLI utilities for dang-near anything you can think of, but yeah, rename is included in a lot of distributions. The one on my distro was written by Larry Wall back in 2014. Contrary to Tecmint and a few other locations, this is not 'a very powerful built-in tool called rename' that 'comes with Linux.' And no, that is not just a dig at Linux vs. GNU - it is not a GNU utility either. It is a third-party Perl script that is included by many Linux distributions that uses Perl regular expressions for renaming. This is in contrast to mv, which is generally either from GNU coreutils, or is literally a built-in in the shell (such as with busybox).

Also, apropos is another CLI worth knowing, as it can tell you what you have installed related to a topic such as renaming.

Other such tools:
1. mmv - uses traditional shell file-globbing arguments to do mass renaming - this is an oldie but goodie inheited from comp.sources.unix (for those who remember NNTP - 'network news groups') by Vladimir Lanin.
2. renameutils - qmv lets you simply edit names in a... show more

There's GNU rename and then there's a perl version that often gets kluged in on top of it. The perl version is even better, though there are still some uncertainties. But there is a switch -n that will tell you what a command will do exactly before you run it for real.

Oh, geez, Howard did a much better job of describing the varying programs than I ever could! Thank you, Howard!

Oh, geez, three comments in a row… Is it not AMAZING how long one can use Linux and not know something that someone else thinks of as "basic"? It's one of the reasons that asking for help makes one (or at least me) feel like such a tool. There's always some 13 year old kid who just happens to know something you don't ready to humiliate you.

Ah, yeah, I should have mentioned that there IS a GNU rename, it just did not happen to be the one included in my distro. There were actually TWO GNU renames, one from util-linux and one in coreutils - the latter was a rewrite by Sami Kerola in, I think, 2012? It replaced the util-linux one, which itself replaced a shell script (which it included verbatim in the C source comment!) - I was not able to find the original author on that one for sure, but I think it may have been Andries Brouwer.

So that covers C and Bash in my list above.

Hmm... I may have erred there as well - looks like the util-linux one may not have been under GNU auspices, but actually a collection of utilities by Linux kernel developers, which would fit with 'aeb' being possibly a reference to Andries Brouwer. Soo.... in that one case, you could make an argument for it being a 'built-in tool that comes with Linux.' I might even have needed to make an apology... except that checking the article, they clearly mention it being a Perl script, so they are definitely talking about the Larry Wall version.

Nice! Hopefully the perlexpr needed isn't too different from other regex I used in the past (in egrep, emacs, etc.).

There is also viname, which gives you a vi session to edit your filenames. It was written almost two decades ago by my friend Daniel:

@Attila Kinali wow that sounds even cooler when the renaming is on a case-by-case basis. For this time it was about using regex to do a bulk renaming, although I guess you can do that sort of stuff in vi too probably...