[kwlug-disc] bash - file renaming

Jason Eckert jason.eckert at gmail.com
Thu Sep 26 07:04:16 EDT 2019


Why not write a simple for loop in bash?
for $FILE in *
do
mv $FILE $FILE.whatever
done

On Thu, Sep 26, 2019 at 4:23 AM Ronald Barnes <ron at ronaldbarnes.ca> wrote:

>
> 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
>
> _______________________________________________
> kwlug-disc mailing list
> kwlug-disc at kwlug.org
> http://kwlug.org/mailman/listinfo/kwlug-disc_kwlug.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://kwlug.org/pipermail/kwlug-disc_kwlug.org/attachments/20190926/333896a2/attachment.htm>


More information about the kwlug-disc mailing list