[kwlug-disc] bash - file renaming

Ronald Barnes ron at ronaldbarnes.ca
Fri Sep 27 02:46:39 EDT 2019


Doug Moen wrote on 26/09/2019 04.17:

> I tested your utility. It seems to work as expected, even if there
> are multiple '*' characters in the glob pattern. I also tested some
> cross-directory renames, and those worked too. I haven't broken it
> yet.

That's great to hear!

I had considered but not yet tested for cross-directory renames, so
that's a delightful surprise.


> So here's my competitive analysis.
> 
> There are other Linux commands that do this, but they are more
> complex to use, and they don't use the DOS rename command line
> syntax. Matching the semantics of a command that other people are
> already familiar with seems like a good strategy, and that's what
> makes your  project distinctive, AFAIK.

Agreed on all counts. The syntax thing is crucial.

Needs to be similar to "cp" and "mv".


> Ubuntu has the 'rename' and 'mmv' commands. rename is preinstalled,
> mmv has to be explicitly installed, 'sudo apt install mmv'. Here's a
> comparison:
> 
> $ rename.sh '*.foo' '*.bar'
> $ rename 's/\.foo/.bar/' *.foo
> $ mmv '*.foo' '#1.bar'
> 
> `rename` is written by Larry Wall, creator of Perl, and you write a
> short Perl program to modify each file name. It's very powerful, but
> you need to understand how to write Perl code.

Perl is one of my favourite languages.

However, I strove to eliminate all external dependencies: Perl, sed, 
awk,... I do have "basename" called in the help message though.



> Since there is already a `rename` command on Ubuntu, I suggest you
> choose a more distinctive name for your command. I suggest `ren`,
> which is a valid DOS command (it's an alias for `rename` on DOS).

That might be what I end up doing.

Having considered your advice, I shall change it. Probably be the next 
commit.

In the "rename.sh -h -vv" I do mention that the end user may want to 
alias as "ren" or even "rn" which seems a more Gnu-like styling.


Thanks, Doug, for your input!

rb




More information about the kwlug-disc mailing list