How to copy files whose name contains number from 20 to 32

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











up vote
1
down vote

favorite












I want to copy files from the copyDest to pastDest that contain number from 20 to 32. What am I dong wrong?



cp -r ~/copyDest/*2[0-9]|3[0-2]* ~/pasteDest


Thanks.










share|improve this question









New contributor




user317427 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    1
    down vote

    favorite












    I want to copy files from the copyDest to pastDest that contain number from 20 to 32. What am I dong wrong?



    cp -r ~/copyDest/*2[0-9]|3[0-2]* ~/pasteDest


    Thanks.










    share|improve this question









    New contributor




    user317427 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I want to copy files from the copyDest to pastDest that contain number from 20 to 32. What am I dong wrong?



      cp -r ~/copyDest/*2[0-9]|3[0-2]* ~/pasteDest


      Thanks.










      share|improve this question









      New contributor




      user317427 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I want to copy files from the copyDest to pastDest that contain number from 20 to 32. What am I dong wrong?



      cp -r ~/copyDest/*2[0-9]|3[0-2]* ~/pasteDest


      Thanks.







      bash shell wildcards command






      share|improve this question









      New contributor




      user317427 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      user317427 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 22 mins ago









      Stéphane Chazelas

      289k54536875




      289k54536875






      New contributor




      user317427 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 2 hours ago









      user317427

      61




      61




      New contributor




      user317427 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      user317427 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      user317427 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          4 Answers
          4






          active

          oldest

          votes

















          up vote
          2
          down vote













          You failed to read the manual on shell pattern matching and assumed that it is the same as what is commonly called "regular expressions". Just the fact that the * operator, that you use in your example, has a different meaning should be a hint that they are not the same.



          With bash (and some other shells) you can use the , operator for the desired effect:



          cp -r ~/copyDest/*2[0-9],3[0-2]* ~/pasteDest


          But beware there are differences. This is the same as writing



          cp -r ~/copyDest/*2[0-9]* ~/copyDest/*3[0-2]* ~/pasteDest


          That means if either of the patterns doesn't match any file, it will be passed as an argument to cp, and cp will complain that the file doesn't exist. You can set the nullglob shell option to avoid that.






          share|improve this answer




















          • Note that it would copy a foo200.txt or foo120.txt file as well.
            – Stéphane Chazelas
            32 mins ago

















          up vote
          2
          down vote













          With zsh:



          cp -r ~/copyDest/(*[^0-9]|)<20-32>(|[^0-9]*) ~/pasteDest


          Without the (*[^0-9]|), it would also match on foo120



          With ksh or bash -O extglob (or use shopt -s extglob within bash) or zsh -o kshglob (set -o kshglob within zsh), the equivalent (except for the order in which the files are copied) would look like:



          (
          LC_ALL=C
          cp -r ~/copyDest/?(*[^0-9])*(0)@(2[0-9]|3[0-2])?([^0-9]*) ~/pasteDest
          )


          With ksh or bash, on most systems and most locales other than C, [0-9] matches a lot more characters than 0123456789, hence the LC_ALL=C (which also affects the glob expansion sorting order). If your file names contain only ASCII characters, you may omit it, as I don't think any locale on any sane system would have ASCII characters other than 0123456789 matched by [0-9]. Other alternative is to replace [0-9] with [0123456789].



          Also note that except in zsh -o kshglob, if the pattern doesn't match any file, cp will be called with a literal .../?(*[^0-9])*(0)@(2[0-9]|3[0-2])?([^0-9]*) argument (a valid though unlikely file name) which if it exists would then be copied (or cp would return an error otherwise). In bash, you can use the failglob option to get a behaviour closer to zsh's saner one (of cancelling the command if the pattern doesn't match).



          Above we take special care of copying files named foo20.txt, foo00020.txt, but not foo120.txt or foo200.txt (even though their name contains 20). It still copies foo32.12.txt or foo0x20.txt files.






          share|improve this answer





























            up vote
            1
            down vote













            bash approach. As a bonus it prints the numbers for which a matching file was not fou nd.



            [steve@instance-2 ~]$ find copyDest pasteDest
            copyDest
            copyDest/file15
            copyDest/file20
            copyDest/file25
            copyDest/file32
            copyDest/file33
            pasteDest
            [steve@instance-2 ~]$ cp -pr ~/copyDest/*20..32* pasteDest
            cp: cannot stat ‘/home/steve/copyDest/*21*’: No such file or directory
            cp: cannot stat ‘/home/steve/copyDest/*22*’: No such file or directory
            cp: cannot stat ‘/home/steve/copyDest/*23*’: No such file or directory
            cp: cannot stat ‘/home/steve/copyDest/*24*’: No such file or directory
            cp: cannot stat ‘/home/steve/copyDest/*26*’: No such file or directory
            cp: cannot stat ‘/home/steve/copyDest/*27*’: No such file or directory
            cp: cannot stat ‘/home/steve/copyDest/*28*’: No such file or directory
            cp: cannot stat ‘/home/steve/copyDest/*29*’: No such file or directory
            cp: cannot stat ‘/home/steve/copyDest/*30*’: No such file or directory
            cp: cannot stat ‘/home/steve/copyDest/*31*’: No such file or directory
            [steve@instance-2 ~]$ find copyDest pasteDest
            copyDest
            copyDest/file15
            copyDest/file20
            copyDest/file25
            copyDest/file32
            copyDest/file33
            pasteDest
            pasteDest/file20
            pasteDest/file25
            pasteDest/file32
            [steve@instance-2 ~]$





            share|improve this answer




















            • Note that it would copy a foo200.txt or foo120.txt file as well.
              – Stéphane Chazelas
              32 mins ago

















            up vote
            0
            down vote













            Yoe need to do pattern matching, NOT regex matching. Look into your shell's man page. Try something like



            ls *2[0-9]* *3[0-2]*


            i.e. implement the alternation by supplying two patterns.






            share|improve this answer




















            • Note that it would copy a foo200.txt or foo120.txt file as well.
              – Stéphane Chazelas
              32 mins ago










            • @Stéphane Chazelas: which is what the OP requested: "contain number from 20 to 32". 120 does contain such. But, I see your point.
              – RudiC
              14 mins ago










            • Yes, it was a note, not an objection. Something the OP possibly hadn't considered.
              – Stéphane Chazelas
              13 mins ago










            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
            );



            );






            user317427 is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f477449%2fhow-to-copy-files-whose-name-contains-number-from-20-to-32%23new-answer', 'question_page');

            );

            Post as a guest






























            4 Answers
            4






            active

            oldest

            votes








            4 Answers
            4






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote













            You failed to read the manual on shell pattern matching and assumed that it is the same as what is commonly called "regular expressions". Just the fact that the * operator, that you use in your example, has a different meaning should be a hint that they are not the same.



            With bash (and some other shells) you can use the , operator for the desired effect:



            cp -r ~/copyDest/*2[0-9],3[0-2]* ~/pasteDest


            But beware there are differences. This is the same as writing



            cp -r ~/copyDest/*2[0-9]* ~/copyDest/*3[0-2]* ~/pasteDest


            That means if either of the patterns doesn't match any file, it will be passed as an argument to cp, and cp will complain that the file doesn't exist. You can set the nullglob shell option to avoid that.






            share|improve this answer




















            • Note that it would copy a foo200.txt or foo120.txt file as well.
              – Stéphane Chazelas
              32 mins ago














            up vote
            2
            down vote













            You failed to read the manual on shell pattern matching and assumed that it is the same as what is commonly called "regular expressions". Just the fact that the * operator, that you use in your example, has a different meaning should be a hint that they are not the same.



            With bash (and some other shells) you can use the , operator for the desired effect:



            cp -r ~/copyDest/*2[0-9],3[0-2]* ~/pasteDest


            But beware there are differences. This is the same as writing



            cp -r ~/copyDest/*2[0-9]* ~/copyDest/*3[0-2]* ~/pasteDest


            That means if either of the patterns doesn't match any file, it will be passed as an argument to cp, and cp will complain that the file doesn't exist. You can set the nullglob shell option to avoid that.






            share|improve this answer




















            • Note that it would copy a foo200.txt or foo120.txt file as well.
              – Stéphane Chazelas
              32 mins ago












            up vote
            2
            down vote










            up vote
            2
            down vote









            You failed to read the manual on shell pattern matching and assumed that it is the same as what is commonly called "regular expressions". Just the fact that the * operator, that you use in your example, has a different meaning should be a hint that they are not the same.



            With bash (and some other shells) you can use the , operator for the desired effect:



            cp -r ~/copyDest/*2[0-9],3[0-2]* ~/pasteDest


            But beware there are differences. This is the same as writing



            cp -r ~/copyDest/*2[0-9]* ~/copyDest/*3[0-2]* ~/pasteDest


            That means if either of the patterns doesn't match any file, it will be passed as an argument to cp, and cp will complain that the file doesn't exist. You can set the nullglob shell option to avoid that.






            share|improve this answer












            You failed to read the manual on shell pattern matching and assumed that it is the same as what is commonly called "regular expressions". Just the fact that the * operator, that you use in your example, has a different meaning should be a hint that they are not the same.



            With bash (and some other shells) you can use the , operator for the desired effect:



            cp -r ~/copyDest/*2[0-9],3[0-2]* ~/pasteDest


            But beware there are differences. This is the same as writing



            cp -r ~/copyDest/*2[0-9]* ~/copyDest/*3[0-2]* ~/pasteDest


            That means if either of the patterns doesn't match any file, it will be passed as an argument to cp, and cp will complain that the file doesn't exist. You can set the nullglob shell option to avoid that.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 2 hours ago









            RalfFriedl

            4,4861725




            4,4861725











            • Note that it would copy a foo200.txt or foo120.txt file as well.
              – Stéphane Chazelas
              32 mins ago
















            • Note that it would copy a foo200.txt or foo120.txt file as well.
              – Stéphane Chazelas
              32 mins ago















            Note that it would copy a foo200.txt or foo120.txt file as well.
            – Stéphane Chazelas
            32 mins ago




            Note that it would copy a foo200.txt or foo120.txt file as well.
            – Stéphane Chazelas
            32 mins ago












            up vote
            2
            down vote













            With zsh:



            cp -r ~/copyDest/(*[^0-9]|)<20-32>(|[^0-9]*) ~/pasteDest


            Without the (*[^0-9]|), it would also match on foo120



            With ksh or bash -O extglob (or use shopt -s extglob within bash) or zsh -o kshglob (set -o kshglob within zsh), the equivalent (except for the order in which the files are copied) would look like:



            (
            LC_ALL=C
            cp -r ~/copyDest/?(*[^0-9])*(0)@(2[0-9]|3[0-2])?([^0-9]*) ~/pasteDest
            )


            With ksh or bash, on most systems and most locales other than C, [0-9] matches a lot more characters than 0123456789, hence the LC_ALL=C (which also affects the glob expansion sorting order). If your file names contain only ASCII characters, you may omit it, as I don't think any locale on any sane system would have ASCII characters other than 0123456789 matched by [0-9]. Other alternative is to replace [0-9] with [0123456789].



            Also note that except in zsh -o kshglob, if the pattern doesn't match any file, cp will be called with a literal .../?(*[^0-9])*(0)@(2[0-9]|3[0-2])?([^0-9]*) argument (a valid though unlikely file name) which if it exists would then be copied (or cp would return an error otherwise). In bash, you can use the failglob option to get a behaviour closer to zsh's saner one (of cancelling the command if the pattern doesn't match).



            Above we take special care of copying files named foo20.txt, foo00020.txt, but not foo120.txt or foo200.txt (even though their name contains 20). It still copies foo32.12.txt or foo0x20.txt files.






            share|improve this answer


























              up vote
              2
              down vote













              With zsh:



              cp -r ~/copyDest/(*[^0-9]|)<20-32>(|[^0-9]*) ~/pasteDest


              Without the (*[^0-9]|), it would also match on foo120



              With ksh or bash -O extglob (or use shopt -s extglob within bash) or zsh -o kshglob (set -o kshglob within zsh), the equivalent (except for the order in which the files are copied) would look like:



              (
              LC_ALL=C
              cp -r ~/copyDest/?(*[^0-9])*(0)@(2[0-9]|3[0-2])?([^0-9]*) ~/pasteDest
              )


              With ksh or bash, on most systems and most locales other than C, [0-9] matches a lot more characters than 0123456789, hence the LC_ALL=C (which also affects the glob expansion sorting order). If your file names contain only ASCII characters, you may omit it, as I don't think any locale on any sane system would have ASCII characters other than 0123456789 matched by [0-9]. Other alternative is to replace [0-9] with [0123456789].



              Also note that except in zsh -o kshglob, if the pattern doesn't match any file, cp will be called with a literal .../?(*[^0-9])*(0)@(2[0-9]|3[0-2])?([^0-9]*) argument (a valid though unlikely file name) which if it exists would then be copied (or cp would return an error otherwise). In bash, you can use the failglob option to get a behaviour closer to zsh's saner one (of cancelling the command if the pattern doesn't match).



              Above we take special care of copying files named foo20.txt, foo00020.txt, but not foo120.txt or foo200.txt (even though their name contains 20). It still copies foo32.12.txt or foo0x20.txt files.






              share|improve this answer
























                up vote
                2
                down vote










                up vote
                2
                down vote









                With zsh:



                cp -r ~/copyDest/(*[^0-9]|)<20-32>(|[^0-9]*) ~/pasteDest


                Without the (*[^0-9]|), it would also match on foo120



                With ksh or bash -O extglob (or use shopt -s extglob within bash) or zsh -o kshglob (set -o kshglob within zsh), the equivalent (except for the order in which the files are copied) would look like:



                (
                LC_ALL=C
                cp -r ~/copyDest/?(*[^0-9])*(0)@(2[0-9]|3[0-2])?([^0-9]*) ~/pasteDest
                )


                With ksh or bash, on most systems and most locales other than C, [0-9] matches a lot more characters than 0123456789, hence the LC_ALL=C (which also affects the glob expansion sorting order). If your file names contain only ASCII characters, you may omit it, as I don't think any locale on any sane system would have ASCII characters other than 0123456789 matched by [0-9]. Other alternative is to replace [0-9] with [0123456789].



                Also note that except in zsh -o kshglob, if the pattern doesn't match any file, cp will be called with a literal .../?(*[^0-9])*(0)@(2[0-9]|3[0-2])?([^0-9]*) argument (a valid though unlikely file name) which if it exists would then be copied (or cp would return an error otherwise). In bash, you can use the failglob option to get a behaviour closer to zsh's saner one (of cancelling the command if the pattern doesn't match).



                Above we take special care of copying files named foo20.txt, foo00020.txt, but not foo120.txt or foo200.txt (even though their name contains 20). It still copies foo32.12.txt or foo0x20.txt files.






                share|improve this answer














                With zsh:



                cp -r ~/copyDest/(*[^0-9]|)<20-32>(|[^0-9]*) ~/pasteDest


                Without the (*[^0-9]|), it would also match on foo120



                With ksh or bash -O extglob (or use shopt -s extglob within bash) or zsh -o kshglob (set -o kshglob within zsh), the equivalent (except for the order in which the files are copied) would look like:



                (
                LC_ALL=C
                cp -r ~/copyDest/?(*[^0-9])*(0)@(2[0-9]|3[0-2])?([^0-9]*) ~/pasteDest
                )


                With ksh or bash, on most systems and most locales other than C, [0-9] matches a lot more characters than 0123456789, hence the LC_ALL=C (which also affects the glob expansion sorting order). If your file names contain only ASCII characters, you may omit it, as I don't think any locale on any sane system would have ASCII characters other than 0123456789 matched by [0-9]. Other alternative is to replace [0-9] with [0123456789].



                Also note that except in zsh -o kshglob, if the pattern doesn't match any file, cp will be called with a literal .../?(*[^0-9])*(0)@(2[0-9]|3[0-2])?([^0-9]*) argument (a valid though unlikely file name) which if it exists would then be copied (or cp would return an error otherwise). In bash, you can use the failglob option to get a behaviour closer to zsh's saner one (of cancelling the command if the pattern doesn't match).



                Above we take special care of copying files named foo20.txt, foo00020.txt, but not foo120.txt or foo200.txt (even though their name contains 20). It still copies foo32.12.txt or foo0x20.txt files.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 18 mins ago

























                answered 40 mins ago









                Stéphane Chazelas

                289k54536875




                289k54536875




















                    up vote
                    1
                    down vote













                    bash approach. As a bonus it prints the numbers for which a matching file was not fou nd.



                    [steve@instance-2 ~]$ find copyDest pasteDest
                    copyDest
                    copyDest/file15
                    copyDest/file20
                    copyDest/file25
                    copyDest/file32
                    copyDest/file33
                    pasteDest
                    [steve@instance-2 ~]$ cp -pr ~/copyDest/*20..32* pasteDest
                    cp: cannot stat ‘/home/steve/copyDest/*21*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*22*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*23*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*24*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*26*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*27*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*28*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*29*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*30*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*31*’: No such file or directory
                    [steve@instance-2 ~]$ find copyDest pasteDest
                    copyDest
                    copyDest/file15
                    copyDest/file20
                    copyDest/file25
                    copyDest/file32
                    copyDest/file33
                    pasteDest
                    pasteDest/file20
                    pasteDest/file25
                    pasteDest/file32
                    [steve@instance-2 ~]$





                    share|improve this answer




















                    • Note that it would copy a foo200.txt or foo120.txt file as well.
                      – Stéphane Chazelas
                      32 mins ago














                    up vote
                    1
                    down vote













                    bash approach. As a bonus it prints the numbers for which a matching file was not fou nd.



                    [steve@instance-2 ~]$ find copyDest pasteDest
                    copyDest
                    copyDest/file15
                    copyDest/file20
                    copyDest/file25
                    copyDest/file32
                    copyDest/file33
                    pasteDest
                    [steve@instance-2 ~]$ cp -pr ~/copyDest/*20..32* pasteDest
                    cp: cannot stat ‘/home/steve/copyDest/*21*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*22*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*23*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*24*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*26*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*27*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*28*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*29*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*30*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*31*’: No such file or directory
                    [steve@instance-2 ~]$ find copyDest pasteDest
                    copyDest
                    copyDest/file15
                    copyDest/file20
                    copyDest/file25
                    copyDest/file32
                    copyDest/file33
                    pasteDest
                    pasteDest/file20
                    pasteDest/file25
                    pasteDest/file32
                    [steve@instance-2 ~]$





                    share|improve this answer




















                    • Note that it would copy a foo200.txt or foo120.txt file as well.
                      – Stéphane Chazelas
                      32 mins ago












                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    bash approach. As a bonus it prints the numbers for which a matching file was not fou nd.



                    [steve@instance-2 ~]$ find copyDest pasteDest
                    copyDest
                    copyDest/file15
                    copyDest/file20
                    copyDest/file25
                    copyDest/file32
                    copyDest/file33
                    pasteDest
                    [steve@instance-2 ~]$ cp -pr ~/copyDest/*20..32* pasteDest
                    cp: cannot stat ‘/home/steve/copyDest/*21*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*22*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*23*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*24*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*26*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*27*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*28*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*29*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*30*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*31*’: No such file or directory
                    [steve@instance-2 ~]$ find copyDest pasteDest
                    copyDest
                    copyDest/file15
                    copyDest/file20
                    copyDest/file25
                    copyDest/file32
                    copyDest/file33
                    pasteDest
                    pasteDest/file20
                    pasteDest/file25
                    pasteDest/file32
                    [steve@instance-2 ~]$





                    share|improve this answer












                    bash approach. As a bonus it prints the numbers for which a matching file was not fou nd.



                    [steve@instance-2 ~]$ find copyDest pasteDest
                    copyDest
                    copyDest/file15
                    copyDest/file20
                    copyDest/file25
                    copyDest/file32
                    copyDest/file33
                    pasteDest
                    [steve@instance-2 ~]$ cp -pr ~/copyDest/*20..32* pasteDest
                    cp: cannot stat ‘/home/steve/copyDest/*21*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*22*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*23*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*24*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*26*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*27*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*28*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*29*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*30*’: No such file or directory
                    cp: cannot stat ‘/home/steve/copyDest/*31*’: No such file or directory
                    [steve@instance-2 ~]$ find copyDest pasteDest
                    copyDest
                    copyDest/file15
                    copyDest/file20
                    copyDest/file25
                    copyDest/file32
                    copyDest/file33
                    pasteDest
                    pasteDest/file20
                    pasteDest/file25
                    pasteDest/file32
                    [steve@instance-2 ~]$






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 1 hour ago









                    steve

                    13.1k22251




                    13.1k22251











                    • Note that it would copy a foo200.txt or foo120.txt file as well.
                      – Stéphane Chazelas
                      32 mins ago
















                    • Note that it would copy a foo200.txt or foo120.txt file as well.
                      – Stéphane Chazelas
                      32 mins ago















                    Note that it would copy a foo200.txt or foo120.txt file as well.
                    – Stéphane Chazelas
                    32 mins ago




                    Note that it would copy a foo200.txt or foo120.txt file as well.
                    – Stéphane Chazelas
                    32 mins ago










                    up vote
                    0
                    down vote













                    Yoe need to do pattern matching, NOT regex matching. Look into your shell's man page. Try something like



                    ls *2[0-9]* *3[0-2]*


                    i.e. implement the alternation by supplying two patterns.






                    share|improve this answer




















                    • Note that it would copy a foo200.txt or foo120.txt file as well.
                      – Stéphane Chazelas
                      32 mins ago










                    • @Stéphane Chazelas: which is what the OP requested: "contain number from 20 to 32". 120 does contain such. But, I see your point.
                      – RudiC
                      14 mins ago










                    • Yes, it was a note, not an objection. Something the OP possibly hadn't considered.
                      – Stéphane Chazelas
                      13 mins ago














                    up vote
                    0
                    down vote













                    Yoe need to do pattern matching, NOT regex matching. Look into your shell's man page. Try something like



                    ls *2[0-9]* *3[0-2]*


                    i.e. implement the alternation by supplying two patterns.






                    share|improve this answer




















                    • Note that it would copy a foo200.txt or foo120.txt file as well.
                      – Stéphane Chazelas
                      32 mins ago










                    • @Stéphane Chazelas: which is what the OP requested: "contain number from 20 to 32". 120 does contain such. But, I see your point.
                      – RudiC
                      14 mins ago










                    • Yes, it was a note, not an objection. Something the OP possibly hadn't considered.
                      – Stéphane Chazelas
                      13 mins ago












                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    Yoe need to do pattern matching, NOT regex matching. Look into your shell's man page. Try something like



                    ls *2[0-9]* *3[0-2]*


                    i.e. implement the alternation by supplying two patterns.






                    share|improve this answer












                    Yoe need to do pattern matching, NOT regex matching. Look into your shell's man page. Try something like



                    ls *2[0-9]* *3[0-2]*


                    i.e. implement the alternation by supplying two patterns.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 2 hours ago









                    RudiC

                    2,536111




                    2,536111











                    • Note that it would copy a foo200.txt or foo120.txt file as well.
                      – Stéphane Chazelas
                      32 mins ago










                    • @Stéphane Chazelas: which is what the OP requested: "contain number from 20 to 32". 120 does contain such. But, I see your point.
                      – RudiC
                      14 mins ago










                    • Yes, it was a note, not an objection. Something the OP possibly hadn't considered.
                      – Stéphane Chazelas
                      13 mins ago
















                    • Note that it would copy a foo200.txt or foo120.txt file as well.
                      – Stéphane Chazelas
                      32 mins ago










                    • @Stéphane Chazelas: which is what the OP requested: "contain number from 20 to 32". 120 does contain such. But, I see your point.
                      – RudiC
                      14 mins ago










                    • Yes, it was a note, not an objection. Something the OP possibly hadn't considered.
                      – Stéphane Chazelas
                      13 mins ago















                    Note that it would copy a foo200.txt or foo120.txt file as well.
                    – Stéphane Chazelas
                    32 mins ago




                    Note that it would copy a foo200.txt or foo120.txt file as well.
                    – Stéphane Chazelas
                    32 mins ago












                    @Stéphane Chazelas: which is what the OP requested: "contain number from 20 to 32". 120 does contain such. But, I see your point.
                    – RudiC
                    14 mins ago




                    @Stéphane Chazelas: which is what the OP requested: "contain number from 20 to 32". 120 does contain such. But, I see your point.
                    – RudiC
                    14 mins ago












                    Yes, it was a note, not an objection. Something the OP possibly hadn't considered.
                    – Stéphane Chazelas
                    13 mins ago




                    Yes, it was a note, not an objection. Something the OP possibly hadn't considered.
                    – Stéphane Chazelas
                    13 mins ago










                    user317427 is a new contributor. Be nice, and check out our Code of Conduct.









                     

                    draft saved


                    draft discarded


















                    user317427 is a new contributor. Be nice, and check out our Code of Conduct.












                    user317427 is a new contributor. Be nice, and check out our Code of Conduct.











                    user317427 is a new contributor. Be nice, and check out our Code of Conduct.













                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f477449%2fhow-to-copy-files-whose-name-contains-number-from-20-to-32%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    List of Gilmore Girls characters

                    Confectionery