Trying to change multiple files' extensions

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












Using the command line (in Fedora) I'd like to rename all the files in the current directory, that have "foo" for the extension, to the same name but with foo1 for the extension.



I've tried several examples found on StackExchange:



rename foo foo1 *.foo


and



find . -name '*.foo' -execdir rename 's/.foo$/.foo1/' ;


Both generate the following error multiple times:



rename: not enough arguments


Any ideas appreciated.










share|improve this question





















  • What is the result of just find . -name '*.foo'? Your not enough arguments may be from the fact that *.foo expands to nothing (no files match that pattern) so rename complains because you only gave it 1 args.
    – Bailey Parker
    Aug 10 at 19:25











  • You also may want to check man rename. Not all renames work that way. The rename on Debian stretch expects a perl expression and a list of files to apply it to: rename 's/e.foo$/foo1/' *.foo
    – Bailey Parker
    Aug 10 at 19:28










  • That does seem to be the error message you'd get from the util-linux "version" of rename (known as rename.ul on some systems) when *.foo expands to nothing - although in many shells, that would require non-default globbing behavior (bash shopt -s nullglob or zsh setopt null_glob for example)
    – steeldriver
    Aug 10 at 23:00














up vote
1
down vote

favorite












Using the command line (in Fedora) I'd like to rename all the files in the current directory, that have "foo" for the extension, to the same name but with foo1 for the extension.



I've tried several examples found on StackExchange:



rename foo foo1 *.foo


and



find . -name '*.foo' -execdir rename 's/.foo$/.foo1/' ;


Both generate the following error multiple times:



rename: not enough arguments


Any ideas appreciated.










share|improve this question





















  • What is the result of just find . -name '*.foo'? Your not enough arguments may be from the fact that *.foo expands to nothing (no files match that pattern) so rename complains because you only gave it 1 args.
    – Bailey Parker
    Aug 10 at 19:25











  • You also may want to check man rename. Not all renames work that way. The rename on Debian stretch expects a perl expression and a list of files to apply it to: rename 's/e.foo$/foo1/' *.foo
    – Bailey Parker
    Aug 10 at 19:28










  • That does seem to be the error message you'd get from the util-linux "version" of rename (known as rename.ul on some systems) when *.foo expands to nothing - although in many shells, that would require non-default globbing behavior (bash shopt -s nullglob or zsh setopt null_glob for example)
    – steeldriver
    Aug 10 at 23:00












up vote
1
down vote

favorite









up vote
1
down vote

favorite











Using the command line (in Fedora) I'd like to rename all the files in the current directory, that have "foo" for the extension, to the same name but with foo1 for the extension.



I've tried several examples found on StackExchange:



rename foo foo1 *.foo


and



find . -name '*.foo' -execdir rename 's/.foo$/.foo1/' ;


Both generate the following error multiple times:



rename: not enough arguments


Any ideas appreciated.










share|improve this question













Using the command line (in Fedora) I'd like to rename all the files in the current directory, that have "foo" for the extension, to the same name but with foo1 for the extension.



I've tried several examples found on StackExchange:



rename foo foo1 *.foo


and



find . -name '*.foo' -execdir rename 's/.foo$/.foo1/' ;


Both generate the following error multiple times:



rename: not enough arguments


Any ideas appreciated.







find rename






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 10 at 19:19









mike65535

108116




108116











  • What is the result of just find . -name '*.foo'? Your not enough arguments may be from the fact that *.foo expands to nothing (no files match that pattern) so rename complains because you only gave it 1 args.
    – Bailey Parker
    Aug 10 at 19:25











  • You also may want to check man rename. Not all renames work that way. The rename on Debian stretch expects a perl expression and a list of files to apply it to: rename 's/e.foo$/foo1/' *.foo
    – Bailey Parker
    Aug 10 at 19:28










  • That does seem to be the error message you'd get from the util-linux "version" of rename (known as rename.ul on some systems) when *.foo expands to nothing - although in many shells, that would require non-default globbing behavior (bash shopt -s nullglob or zsh setopt null_glob for example)
    – steeldriver
    Aug 10 at 23:00
















  • What is the result of just find . -name '*.foo'? Your not enough arguments may be from the fact that *.foo expands to nothing (no files match that pattern) so rename complains because you only gave it 1 args.
    – Bailey Parker
    Aug 10 at 19:25











  • You also may want to check man rename. Not all renames work that way. The rename on Debian stretch expects a perl expression and a list of files to apply it to: rename 's/e.foo$/foo1/' *.foo
    – Bailey Parker
    Aug 10 at 19:28










  • That does seem to be the error message you'd get from the util-linux "version" of rename (known as rename.ul on some systems) when *.foo expands to nothing - although in many shells, that would require non-default globbing behavior (bash shopt -s nullglob or zsh setopt null_glob for example)
    – steeldriver
    Aug 10 at 23:00















What is the result of just find . -name '*.foo'? Your not enough arguments may be from the fact that *.foo expands to nothing (no files match that pattern) so rename complains because you only gave it 1 args.
– Bailey Parker
Aug 10 at 19:25





What is the result of just find . -name '*.foo'? Your not enough arguments may be from the fact that *.foo expands to nothing (no files match that pattern) so rename complains because you only gave it 1 args.
– Bailey Parker
Aug 10 at 19:25













You also may want to check man rename. Not all renames work that way. The rename on Debian stretch expects a perl expression and a list of files to apply it to: rename 's/e.foo$/foo1/' *.foo
– Bailey Parker
Aug 10 at 19:28




You also may want to check man rename. Not all renames work that way. The rename on Debian stretch expects a perl expression and a list of files to apply it to: rename 's/e.foo$/foo1/' *.foo
– Bailey Parker
Aug 10 at 19:28












That does seem to be the error message you'd get from the util-linux "version" of rename (known as rename.ul on some systems) when *.foo expands to nothing - although in many shells, that would require non-default globbing behavior (bash shopt -s nullglob or zsh setopt null_glob for example)
– steeldriver
Aug 10 at 23:00




That does seem to be the error message you'd get from the util-linux "version" of rename (known as rename.ul on some systems) when *.foo expands to nothing - although in many shells, that would require non-default globbing behavior (bash shopt -s nullglob or zsh setopt null_glob for example)
– steeldriver
Aug 10 at 23:00










2 Answers
2






active

oldest

votes

















up vote
1
down vote













Your use of rename might not work everywhere. Another way to achieve this is to use find, mv, and some bash substitution.



find . -name '*.foo' -exec bash -c 'mv "$0" "$0%.foo.foo1"' "" ;


A few things to note:



I use -exec and not -execdir. The latter effectively cds to the directory of the matched file (which isn't what you want, because then the path to the file--which will be relative to .--will no longer be correct). You want just -exec which will run the given command for each file that matches -name '*.foo' (replacing with the path to the matched file).



"$0%.foo" strips the extension .foo so if $0 is "hello.foo" then "$0%.foo" ends up as "hello". Then adding .foo1 to the end just appends that, so "$0%.foo.foo1" is "hello.foo1".






share|improve this answer



























    up vote
    1
    down vote













    Use a for loop



    for f in *.foo
    do
    mv $f $f/.foo/.foo1
    done





    share|improve this answer




















    • This would rename a file called file.foo-something.foo to file.foo1-something.foo. Better to use "$f%.foo.foo1".
      – Kusalananda
      Aug 10 at 20:23











    • Thanks Kusalananda. However, your pattern changed foo.foo-x to foo.foo-x.foo1. Also, the use of for loop will eliminate the files that do not end in .foo.
      – unxnut
      Aug 10 at 21:08










    • I took your loop into account. It would not process a file called foo.foo-x. My example in my comment does end with .foo though.
      – Kusalananda
      Aug 10 at 21:12










    • OP said "I'd like to rename all the files in the current directory, that have "foo" for the extension, to the same name but with foo1 for the extension."
      – unxnut
      Aug 10 at 21:19










    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f461886%2ftrying-to-change-multiple-files-extensions%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    Your use of rename might not work everywhere. Another way to achieve this is to use find, mv, and some bash substitution.



    find . -name '*.foo' -exec bash -c 'mv "$0" "$0%.foo.foo1"' "" ;


    A few things to note:



    I use -exec and not -execdir. The latter effectively cds to the directory of the matched file (which isn't what you want, because then the path to the file--which will be relative to .--will no longer be correct). You want just -exec which will run the given command for each file that matches -name '*.foo' (replacing with the path to the matched file).



    "$0%.foo" strips the extension .foo so if $0 is "hello.foo" then "$0%.foo" ends up as "hello". Then adding .foo1 to the end just appends that, so "$0%.foo.foo1" is "hello.foo1".






    share|improve this answer
























      up vote
      1
      down vote













      Your use of rename might not work everywhere. Another way to achieve this is to use find, mv, and some bash substitution.



      find . -name '*.foo' -exec bash -c 'mv "$0" "$0%.foo.foo1"' "" ;


      A few things to note:



      I use -exec and not -execdir. The latter effectively cds to the directory of the matched file (which isn't what you want, because then the path to the file--which will be relative to .--will no longer be correct). You want just -exec which will run the given command for each file that matches -name '*.foo' (replacing with the path to the matched file).



      "$0%.foo" strips the extension .foo so if $0 is "hello.foo" then "$0%.foo" ends up as "hello". Then adding .foo1 to the end just appends that, so "$0%.foo.foo1" is "hello.foo1".






      share|improve this answer






















        up vote
        1
        down vote










        up vote
        1
        down vote









        Your use of rename might not work everywhere. Another way to achieve this is to use find, mv, and some bash substitution.



        find . -name '*.foo' -exec bash -c 'mv "$0" "$0%.foo.foo1"' "" ;


        A few things to note:



        I use -exec and not -execdir. The latter effectively cds to the directory of the matched file (which isn't what you want, because then the path to the file--which will be relative to .--will no longer be correct). You want just -exec which will run the given command for each file that matches -name '*.foo' (replacing with the path to the matched file).



        "$0%.foo" strips the extension .foo so if $0 is "hello.foo" then "$0%.foo" ends up as "hello". Then adding .foo1 to the end just appends that, so "$0%.foo.foo1" is "hello.foo1".






        share|improve this answer












        Your use of rename might not work everywhere. Another way to achieve this is to use find, mv, and some bash substitution.



        find . -name '*.foo' -exec bash -c 'mv "$0" "$0%.foo.foo1"' "" ;


        A few things to note:



        I use -exec and not -execdir. The latter effectively cds to the directory of the matched file (which isn't what you want, because then the path to the file--which will be relative to .--will no longer be correct). You want just -exec which will run the given command for each file that matches -name '*.foo' (replacing with the path to the matched file).



        "$0%.foo" strips the extension .foo so if $0 is "hello.foo" then "$0%.foo" ends up as "hello". Then adding .foo1 to the end just appends that, so "$0%.foo.foo1" is "hello.foo1".







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Aug 10 at 19:36









        Bailey Parker

        14318




        14318






















            up vote
            1
            down vote













            Use a for loop



            for f in *.foo
            do
            mv $f $f/.foo/.foo1
            done





            share|improve this answer




















            • This would rename a file called file.foo-something.foo to file.foo1-something.foo. Better to use "$f%.foo.foo1".
              – Kusalananda
              Aug 10 at 20:23











            • Thanks Kusalananda. However, your pattern changed foo.foo-x to foo.foo-x.foo1. Also, the use of for loop will eliminate the files that do not end in .foo.
              – unxnut
              Aug 10 at 21:08










            • I took your loop into account. It would not process a file called foo.foo-x. My example in my comment does end with .foo though.
              – Kusalananda
              Aug 10 at 21:12










            • OP said "I'd like to rename all the files in the current directory, that have "foo" for the extension, to the same name but with foo1 for the extension."
              – unxnut
              Aug 10 at 21:19














            up vote
            1
            down vote













            Use a for loop



            for f in *.foo
            do
            mv $f $f/.foo/.foo1
            done





            share|improve this answer




















            • This would rename a file called file.foo-something.foo to file.foo1-something.foo. Better to use "$f%.foo.foo1".
              – Kusalananda
              Aug 10 at 20:23











            • Thanks Kusalananda. However, your pattern changed foo.foo-x to foo.foo-x.foo1. Also, the use of for loop will eliminate the files that do not end in .foo.
              – unxnut
              Aug 10 at 21:08










            • I took your loop into account. It would not process a file called foo.foo-x. My example in my comment does end with .foo though.
              – Kusalananda
              Aug 10 at 21:12










            • OP said "I'd like to rename all the files in the current directory, that have "foo" for the extension, to the same name but with foo1 for the extension."
              – unxnut
              Aug 10 at 21:19












            up vote
            1
            down vote










            up vote
            1
            down vote









            Use a for loop



            for f in *.foo
            do
            mv $f $f/.foo/.foo1
            done





            share|improve this answer












            Use a for loop



            for f in *.foo
            do
            mv $f $f/.foo/.foo1
            done






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Aug 10 at 20:16









            unxnut

            3,3802918




            3,3802918











            • This would rename a file called file.foo-something.foo to file.foo1-something.foo. Better to use "$f%.foo.foo1".
              – Kusalananda
              Aug 10 at 20:23











            • Thanks Kusalananda. However, your pattern changed foo.foo-x to foo.foo-x.foo1. Also, the use of for loop will eliminate the files that do not end in .foo.
              – unxnut
              Aug 10 at 21:08










            • I took your loop into account. It would not process a file called foo.foo-x. My example in my comment does end with .foo though.
              – Kusalananda
              Aug 10 at 21:12










            • OP said "I'd like to rename all the files in the current directory, that have "foo" for the extension, to the same name but with foo1 for the extension."
              – unxnut
              Aug 10 at 21:19
















            • This would rename a file called file.foo-something.foo to file.foo1-something.foo. Better to use "$f%.foo.foo1".
              – Kusalananda
              Aug 10 at 20:23











            • Thanks Kusalananda. However, your pattern changed foo.foo-x to foo.foo-x.foo1. Also, the use of for loop will eliminate the files that do not end in .foo.
              – unxnut
              Aug 10 at 21:08










            • I took your loop into account. It would not process a file called foo.foo-x. My example in my comment does end with .foo though.
              – Kusalananda
              Aug 10 at 21:12










            • OP said "I'd like to rename all the files in the current directory, that have "foo" for the extension, to the same name but with foo1 for the extension."
              – unxnut
              Aug 10 at 21:19















            This would rename a file called file.foo-something.foo to file.foo1-something.foo. Better to use "$f%.foo.foo1".
            – Kusalananda
            Aug 10 at 20:23





            This would rename a file called file.foo-something.foo to file.foo1-something.foo. Better to use "$f%.foo.foo1".
            – Kusalananda
            Aug 10 at 20:23













            Thanks Kusalananda. However, your pattern changed foo.foo-x to foo.foo-x.foo1. Also, the use of for loop will eliminate the files that do not end in .foo.
            – unxnut
            Aug 10 at 21:08




            Thanks Kusalananda. However, your pattern changed foo.foo-x to foo.foo-x.foo1. Also, the use of for loop will eliminate the files that do not end in .foo.
            – unxnut
            Aug 10 at 21:08












            I took your loop into account. It would not process a file called foo.foo-x. My example in my comment does end with .foo though.
            – Kusalananda
            Aug 10 at 21:12




            I took your loop into account. It would not process a file called foo.foo-x. My example in my comment does end with .foo though.
            – Kusalananda
            Aug 10 at 21:12












            OP said "I'd like to rename all the files in the current directory, that have "foo" for the extension, to the same name but with foo1 for the extension."
            – unxnut
            Aug 10 at 21:19




            OP said "I'd like to rename all the files in the current directory, that have "foo" for the extension, to the same name but with foo1 for the extension."
            – unxnut
            Aug 10 at 21:19

















             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f461886%2ftrying-to-change-multiple-files-extensions%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?