+ Reply to Thread
Results 1 to 5 of 5

Using wildcards with mv

  1. Using wildcards with mv

    Hello all

    I've used this simple command in the past to rename files at a DOS /
    Windows / OS/2 prompt, but the same idea is not working for me at a
    *nix prompt (Mac OS X). I'm trying to rename all files in a dir to add
    the same text before the extension (file-123.txt becomes
    file-123-rb.txt for example).

    In DOS I've used: rename ????????.txt ????????-rb.txt
    In OS X I tried: mv ????????.txt ????????-rb.txt

    I haven't used a non-DOS-style shell for years - any idea what I'm
    missing here?

    Thanks
    Randy


  2. Re: Using wildcards with mv

    On 2007-01-23, randywbest@gmail.com wrote:
    > Hello all
    >
    > I've used this simple command in the past to rename files at a DOS /
    > Windows / OS/2 prompt, but the same idea is not working for me at a
    > *nix prompt (Mac OS X). I'm trying to rename all files in a dir to add
    > the same text before the extension (file-123.txt becomes
    > file-123-rb.txt for example).
    >
    > In DOS I've used: rename ????????.txt ????????-rb.txt
    > In OS X I tried: mv ????????.txt ????????-rb.txt
    >
    > I haven't used a non-DOS-style shell for years - any idea what I'm
    > missing here?


    In a Unix shell, wildcards are expanded by the shell, not by the
    command. The command sees only the result of the expansion. If you
    picture that, you will see why the command cannot work as you have
    written it.

    There are a couple of rename commands, with different syntax; I
    don't know whether OS/X has either.

    The traditional Unix method is:

    for file in ????????.txt
    do
    mv -i -- "$file" "${file%.txt}-rb.txt"
    done

    --
    Chris F.A. Johnson, author
    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
    ===== My code in this post, if any, assumes the POSIX locale
    ===== and is released under the GNU General Public Licence

  3. Re: Using wildcards with mv

    randywbest@gmail.com writes:
    > I've used this simple command in the past to rename files at a DOS /
    > Windows / OS/2 prompt, but the same idea is not working for me at a
    > *nix prompt (Mac OS X). I'm trying to rename all files in a dir to add
    > the same text before the extension (file-123.txt becomes
    > file-123-rb.txt for example).
    >
    > In DOS I've used: rename ????????.txt ????????-rb.txt
    > In OS X I tried: mv ????????.txt ????????-rb.txt
    >
    > I haven't used a non-DOS-style shell for years - any idea what I'm
    > missing here?


    The wildcards are expanded by the shell before the mv command is
    executed; "mv" never sees the '?' characters.

    This is question 2.6 in the Unix FAQ; see
    .

    --
    Keith Thompson (The_Other_Keith) kst-u@mib.org
    San Diego Supercomputer Center <*>
    We must do something. This is something. Therefore, we must do this.

  4. Re: Using wildcards with mv

    Understood. Thanks guys.

    On Jan 23, 4:13 pm, "Chris F.A. Johnson" wrote:
    > On 2007-01-23, randywb...@gmail.com wrote:
    > > Hello all

    >
    > > I've used this simple command in the past to rename files at a DOS /
    > > Windows / OS/2 prompt, but the same idea is not working for me at a
    > > *nix prompt (Mac OS X). I'm trying to rename all files in a dir to add
    > > the same text before the extension (file-123.txt becomes
    > > file-123-rb.txt for example).

    >
    > > In DOS I've used: rename ????????.txt ????????-rb.txt
    > > In OS X I tried: mv ????????.txt ????????-rb.txt

    >
    > > I haven't used a non-DOS-style shell for years - any idea what I'm
    > > missing here? In a Unix shell, wildcards are expanded by the shell, not by the

    > command. The command sees only the result of the expansion. If you
    > picture that, you will see why the command cannot work as you have
    > written it.
    >
    > There are a couple of rename commands, with different syntax; I
    > don't know whether OS/X has either.
    >
    > The traditional Unix method is:
    >
    > for file in ????????.txt
    > do
    > mv -i -- "$file" "${file%.txt}-rb.txt"
    > done
    >
    > --
    > Chris F.A. Johnson, author
    > Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
    > ===== My code in this post, if any, assumes the POSIX locale
    > ===== and is released under the GNU General Public Licence



  5. Re: Using wildcards with mv

    In article <1169581404.516102.133100@s48g2000cws.googlegroups.com>,
    wrote:
    >Hello all
    >
    >I've used this simple command in the past to rename files at a DOS /
    >Windows / OS/2 prompt, but the same idea is not working for me at a
    >*nix prompt (Mac OS X). I'm trying to rename all files in a dir to add
    >the same text before the extension (file-123.txt becomes
    >file-123-rb.txt for example).
    >
    >In DOS I've used: rename ????????.txt ????????-rb.txt
    >In OS X I tried: mv ????????.txt ????????-rb.txt
    >
    >I haven't used a non-DOS-style shell for years - any idea what I'm
    >missing here?


    Aside from the answers already given - if you want to continue to use the
    syntax you're used to, and have ksh for OS X, you can use this:

    ftp://ftp.armory.com/pub/scripts/ren

    Your command would be: ren '????????.txt' '????????-rb.txt'

    It works fine under OS X, though I don't know where the ksh on the OS X
    machine I tested it on came from.

    John
    --
    John DuBois spcecdt@armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/

+ Reply to Thread