<!DOCTYPE html><html><head><title></title><style type="text/css">p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div>A good thing about for loops is that they work with commands other than 'mv', eg you want to copy the files, or symlink them, or `git mv` them.<br></div><div><br></div><div>On Thu, Sep 26, 2019, at 12:02 PM, Cedric Puddy wrote:<br></div><blockquote type="cite" id="qt"><div>I've always done as Jason suggests, but the one thing that is usually helpful is the addition of "basename":<br></div><div><br></div><div><blockquote type="cite"><div dir="ltr"><div dir="ltr"><div><span style="color:#000000" class="colour"><span style="background-color:rgba(255, 255, 255, 0)" class="highlight">for $FILE in *</span></span><br></div><div><span style="color:#000000" class="colour"><span style="background-color:rgba(255, 255, 255, 0)" class="highlight">do</span></span><br></div><div><span style="color:#000000" class="colour"><span style="background-color:rgba(255, 255, 255, 0)" class="highlight">mv $FILE $(basename $FILE .htm).whatever</span></span><br></div><div><span style="color:#000000" class="colour"><span style="background-color:rgba(255, 255, 255, 0)" class="highlight">done</span></span><br></div></div></div></blockquote><div><br></div><div>Basename will remove an arbitrary string (eg: .htm) from the end of another string, thus getting rid of the old extension, so you can tack on your new ".html" or ".whatever" extension.<br></div></div><div><br></div><div>The fact that this covers most use cases is why there is no utility, I suspect. When I was first getting started, a grey beard showed me loops - I think for this exact reason, actually.<br></div><div><br></div><div><div>Also, there would be no need for multiple "*" wildcards, I expect, since every "*.htm" is going to get the new target extension, so why not have the syntax for the rename utility be "rename *.oldext .newext"?<br></div><div><br></div><div dir="ltr" id="qt-AppleMailSignature"><div><span style="background-color:rgba(255, 255, 255, 0)" class="highlight"> Warm Regards,</span><br></div><div><span style="background-color:rgba(255, 255, 255, 0)" class="highlight"> -Cedric</span><br></div><div><div><span style="background-color:rgba(255, 255, 255, 0)" class="highlight"><br></span></div><div id="qt-AppleMailSignature"><span style="background-color:rgba(255, 255, 255, 0)" class="highlight">[<b>CCj</b>] [Cedric Puddy, President, CCj/Clearline Inc.. T: <a dir="ltr" href="tel:519-342-4004;102">519-342-4004x102</a>]</span><br></div></div></div><div dir="ltr"><div><br></div><div>On Sep 26, 2019, at 13:04, Jason Eckert <<a href="mailto:jason.eckert@gmail.com">jason.eckert@gmail.com</a>> wrote:<br></div></div><blockquote type="cite"><div dir="ltr"><div dir="ltr"><div>Why not write a simple for loop in bash?<br></div><div>for $FILE in *<br></div><div>do<br></div><div>mv $FILE $FILE.whatever<br></div><div>done<br></div></div><div><br></div><div class="qt-gmail_quote"><div class="qt-gmail_attr" dir="ltr">On Thu, Sep 26, 2019 at 4:23 AM Ronald Barnes <<a href="mailto:ron@ronaldbarnes.ca">ron@ronaldbarnes.ca</a>> wrote:<br></div><blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-color:rgb(204, 204, 204);border-left-style:solid;border-left-width:1px;padding-left:1ex;" class="qt-gmail_quote"><div><br></div><div>Hi everyone,<br></div><div> <br></div><div> As you probably already know, Gnu/Linux distributions do not come with a <br></div><div> rename utility similar to what some of us "grew up on" in DOS and/or OS/2.<br></div><div> <br></div><div> The "mv" (move) command is to be used instead. But it doesn't handle <br></div><div> things like "mv *.htm *.html".<br></div><div> <br></div><div> So, I decided to tackle writing one.<br></div><div> <br></div><div> <br></div><div> Since bash has "Pathname Expansion", which expands a parameter like <br></div><div> "*.htm" into a list of files that match that expression, it was a bit <br></div><div> more challenging than I expected.<br></div><div> <br></div><div> <br></div><div> However, I think I have something that handles wildcards sufficiently well.<br></div><div> <br></div><div> > <a rel="noreferrer" href="https://github.com/RonaldBarnes/bash-rename">https://github.com/RonaldBarnes/bash-rename</a><br></div><div> <br></div><div> <br></div><div> If anyone is interested in having a look, and providing feedback, it <br></div><div> would be welcome.<br></div><div> <br></div><div> <br></div><div> There is a "rename.sh" which does the parameter parsing (although once <br></div><div> it parses the parameters, "mv" does the actual work), and a <br></div><div> "<a rel="noreferrer" href="http://rename.unit-tests.sh">rename.unit-tests.sh</a>" which is - so far - just notes to myself on edge <br></div><div> cases.<br></div><div> <br></div><div> <br></div><div> <br></div><div> I'm pretty sure this utility can be of some use to a significant number <br></div><div> of people and hopefully someone on this list will agree.<br></div><div> <br></div><div> <br></div><div> Note, there's a "no-op" aka "dry-run" option of -n that will prevent any <br></div><div> files from being touched / moved / renamed, and a -vvv option to spew <br></div><div> out debugging info to help determine how the script derives the target <br></div><div> file name from the wildcards provided.<br></div><div> <br></div><div> <br></div><div> <br></div><div> Thanks!<br></div><div> <br></div><div> rb<br></div><div> <br></div><div> _______________________________________________<br></div><div> kwlug-disc mailing list<br></div><div> <a href="mailto:kwlug-disc@kwlug.org">kwlug-disc@kwlug.org</a><br></div><div> <a rel="noreferrer" href="http://kwlug.org/mailman/listinfo/kwlug-disc_kwlug.org">http://kwlug.org/mailman/listinfo/kwlug-disc_kwlug.org</a><br></div></blockquote></div></div></blockquote><blockquote type="cite"><div dir="ltr"><div><span>_______________________________________________</span><br></div><div><span>kwlug-disc mailing list</span><br></div><div><span><a href="mailto:kwlug-disc@kwlug.org">kwlug-disc@kwlug.org</a></span><br></div><div><span><a href="http://kwlug.org/mailman/listinfo/kwlug-disc_kwlug.org">http://kwlug.org/mailman/listinfo/kwlug-disc_kwlug.org</a></span><br></div></div></blockquote></div><div>_______________________________________________<br></div><div>kwlug-disc mailing list<br></div><div>kwlug-disc@kwlug.org<br></div><div>http://kwlug.org/mailman/listinfo/kwlug-disc_kwlug.org<br></div><div><br></div></blockquote><div><br></div></body></html>