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?

tomix reshared this.

 
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.
 
Also mmv is similar.
 
 
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: http://hotti.ch/tools/
 
@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...