Tag Archives: replace

rename: The built-in filename sifting tool

Sorry for the one-day break; Thursdays are always a little bit hectic for me, and this being the last in the month was especially busy.

The bulk of util-linux is splashed across the previous post, but I have a few left over that I want to point out. rename is one of those, and at its best, rename is a quick and speedy tool for bulk renaming files. Here’s what it does, on a good day:

2014-09-26-6m47421-rename-01

That’s a classy solution for bulk renaming where the same string needs to be substituted out in each file. rename makes it (more or less) a cinch to swap date strings, replace extensions or even make mass insertions and deletions to file names … with a little added command-line kung fu.

rename‘s shortcomings — and you knew I was going to point some out — occasionally crop up, though:

2014-09-26-6m47421-rename-02

If you look closely, you’ll see that the last file name had its prefix changed, but not the extension. rename caught the first instance of “text,” but quit before it found the other.

rename also has very little in the way of error-checking. Once you send the command, the deed is done … and short of reversing your previous command, there is no preview-and-commit. And you must be cautious that your substitution doesn’t allow for files to be moved onto one another.

And it should probably go without saying that, unless you are a regex grand master, some of the more complex or subtle renaming that is possible with something like renameutils is lost on rename. Which isn’t to say it can’t be done, only to say that your success will depend on your proficiency. 😕

rename works though, and in minor substitutions it’s a breeze. And given its simplicity and straightforward arrangement, I can’t say too many bad things about it. Keep it in mind the next time you dump a couple hundred pictures off your digital camera, and need a system to order them. … 😯

expand: Giving you more spaces

Another clever and simple little tool, this time out of coreutils, where all the good stuff comes from … expand.

2013-10-21-lv-r1fz6-expand

Nothing complicated or obtuse here, just convert tabs to spaces. In fact, it’s a little difficult to show what’s going on, since technically there’s nothing to see. 😳

You can tell expand to use specific numbers of spaces when it replaces, to avoid tabs after non-whitespace characters and even use a list of specific locations for tabs to replace.

But beyond that, expand is content. Calm as Hindu cows.

Just remember this the next time you have a file littered with tab marks, and you don’t want to go through the hassle of search-and-replacing it again and again. … 😉