[kwlug-disc] bash - file renaming
Ronald Barnes
ron at ronaldbarnes.ca
Thu Sep 26 04:00:50 EDT 2019
Hi everyone,
As you probably already know, Gnu/Linux distributions do not come with a
rename utility similar to what some of us "grew up on" in DOS and/or OS/2.
The "mv" (move) command is to be used instead. But it doesn't handle
things like "mv *.htm *.html".
So, I decided to tackle writing one.
Since bash has "Pathname Expansion", which expands a parameter like
"*.htm" into a list of files that match that expression, it was a bit
more challenging than I expected.
However, I think I have something that handles wildcards sufficiently well.
> https://github.com/RonaldBarnes/bash-rename
If anyone is interested in having a look, and providing feedback, it
would be welcome.
There is a "rename.sh" which does the parameter parsing (although once
it parses the parameters, "mv" does the actual work), and a
"rename.unit-tests.sh" which is - so far - just notes to myself on edge
cases.
I'm pretty sure this utility can be of some use to a significant number
of people and hopefully someone on this list will agree.
Note, there's a "no-op" aka "dry-run" option of -n that will prevent any
files from being touched / moved / renamed, and a -vvv option to spew
out debugging info to help determine how the script derives the target
file name from the wildcards provided.
Thanks!
rb
More information about the kwlug-disc
mailing list