How to use wildcards (*) when copying with scp?











up vote
122
down vote

favorite
20












Why can't I copy with scp when I'm using * characters in the path?



scp SERVERNAME:/DIR/* .


What configuration does SCP need in order to allow * in the path?



UPDATE: the problem is not on server side; pscp is trying to use SCPv1, and that's why the error message:



scp commandline and error message regarding a file called *










share|improve this question




























    up vote
    122
    down vote

    favorite
    20












    Why can't I copy with scp when I'm using * characters in the path?



    scp SERVERNAME:/DIR/* .


    What configuration does SCP need in order to allow * in the path?



    UPDATE: the problem is not on server side; pscp is trying to use SCPv1, and that's why the error message:



    scp commandline and error message regarding a file called *










    share|improve this question


























      up vote
      122
      down vote

      favorite
      20









      up vote
      122
      down vote

      favorite
      20






      20





      Why can't I copy with scp when I'm using * characters in the path?



      scp SERVERNAME:/DIR/* .


      What configuration does SCP need in order to allow * in the path?



      UPDATE: the problem is not on server side; pscp is trying to use SCPv1, and that's why the error message:



      scp commandline and error message regarding a file called *










      share|improve this question















      Why can't I copy with scp when I'm using * characters in the path?



      scp SERVERNAME:/DIR/* .


      What configuration does SCP need in order to allow * in the path?



      UPDATE: the problem is not on server side; pscp is trying to use SCPv1, and that's why the error message:



      scp commandline and error message regarding a file called *







      wildcards scp putty






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 3 at 15:39









      Jeff Schaller

      37k1052121




      37k1052121










      asked Dec 22 '11 at 13:39









      LanceBaynes

      10.2k75192322




      10.2k75192322






















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          109
          down vote













          You need to pass a literal escape to scp to avoid the remote machine treating * as a glob (notice that it is doubly quoted):



          scp 'SERVERNAME:/DIR/*' .





          share|improve this answer



















          • 32




            You either need quotes, or a backslash before the star, not both. And scp is not the one expanding it, the shell is.
            – Patrick
            Dec 23 '11 at 4:39












          • @Patrick That's not correct, scp expands the glob, even if your shell doesn't (you can try it for yourself). There are two stages: stopping your shell from expanding the glob (which is not necessary because it should have nothing to expand the glob to, and thus will remain intact), and telling scp that this character is not a glob. If it was your shell expanding the glob you would not have to escape it at all.
            – Chris Down
            Dec 23 '11 at 13:29








          • 3




            Have you tried it? I just did, works exactly as I described (quoting and escaping causes failure). User1274964 even confirms the behavior in his answer. touch /tmp/abcd.1234; scp 'localhost:/tmp/abcd.*' ./: scp: /tmp/abcd.*: No such file or directory
            – Patrick
            Dec 7 '13 at 1:00








          • 2




            @Patrick The question is about using a literal asterisk, ie, avoiding globbing altogether, not about how to glob on the remote.
            – Chris Down
            Dec 8 '13 at 20:57








          • 2




            Actually the question is about getting pscp on the client side to allow remote globbing.
            – Patrick
            Dec 8 '13 at 22:08




















          up vote
          45
          down vote













          I found Patrick's advice to be correct, although Chris's answer got me on the right track. Use quotes and then you don't need the backslash before the asterisk.



          scp 'SERVERNAME:/tmp/file_num*' .


          scp: /tmp/file_num*.csv: No such file or directory



          scp 'SERVERNAME:/tmp/file_num*' .


          judgments_for_job_171642.csv 100% 32KB 32.0KB/s 00:00

          judgments_for_job_172394.csv 100% 548KB 182.6KB/s 00:03






          share|improve this answer

















          • 4




            Right, because this means that you want to glob on the remote. The question is about how to stop globbing on the remote (to get a literal *), not about how to glob on the remote only.
            – Chris Down
            Dec 8 '13 at 20:57








          • 1




            @ChrisDown. No. The user wants the wildcard not expanded on the host, and does want it expanded on the remote, to allow it to match multiple files there. None of the files returned have a literal '*' in them. Did you mean "stop globbing on the host "?
            – Tim Bird
            Sep 7 '16 at 19:38




















          up vote
          0
          down vote













          For me it works differently in bash and in c-shell. Don't ask why I use c-shell. In bash I don't need '' - in c-shell I do. So it seems they handle the globs differently in different linux versions.






          share|improve this answer








          New contributor




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


















            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: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            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%2f27419%2fhow-to-use-wildcards-when-copying-with-scp%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            109
            down vote













            You need to pass a literal escape to scp to avoid the remote machine treating * as a glob (notice that it is doubly quoted):



            scp 'SERVERNAME:/DIR/*' .





            share|improve this answer



















            • 32




              You either need quotes, or a backslash before the star, not both. And scp is not the one expanding it, the shell is.
              – Patrick
              Dec 23 '11 at 4:39












            • @Patrick That's not correct, scp expands the glob, even if your shell doesn't (you can try it for yourself). There are two stages: stopping your shell from expanding the glob (which is not necessary because it should have nothing to expand the glob to, and thus will remain intact), and telling scp that this character is not a glob. If it was your shell expanding the glob you would not have to escape it at all.
              – Chris Down
              Dec 23 '11 at 13:29








            • 3




              Have you tried it? I just did, works exactly as I described (quoting and escaping causes failure). User1274964 even confirms the behavior in his answer. touch /tmp/abcd.1234; scp 'localhost:/tmp/abcd.*' ./: scp: /tmp/abcd.*: No such file or directory
              – Patrick
              Dec 7 '13 at 1:00








            • 2




              @Patrick The question is about using a literal asterisk, ie, avoiding globbing altogether, not about how to glob on the remote.
              – Chris Down
              Dec 8 '13 at 20:57








            • 2




              Actually the question is about getting pscp on the client side to allow remote globbing.
              – Patrick
              Dec 8 '13 at 22:08

















            up vote
            109
            down vote













            You need to pass a literal escape to scp to avoid the remote machine treating * as a glob (notice that it is doubly quoted):



            scp 'SERVERNAME:/DIR/*' .





            share|improve this answer



















            • 32




              You either need quotes, or a backslash before the star, not both. And scp is not the one expanding it, the shell is.
              – Patrick
              Dec 23 '11 at 4:39












            • @Patrick That's not correct, scp expands the glob, even if your shell doesn't (you can try it for yourself). There are two stages: stopping your shell from expanding the glob (which is not necessary because it should have nothing to expand the glob to, and thus will remain intact), and telling scp that this character is not a glob. If it was your shell expanding the glob you would not have to escape it at all.
              – Chris Down
              Dec 23 '11 at 13:29








            • 3




              Have you tried it? I just did, works exactly as I described (quoting and escaping causes failure). User1274964 even confirms the behavior in his answer. touch /tmp/abcd.1234; scp 'localhost:/tmp/abcd.*' ./: scp: /tmp/abcd.*: No such file or directory
              – Patrick
              Dec 7 '13 at 1:00








            • 2




              @Patrick The question is about using a literal asterisk, ie, avoiding globbing altogether, not about how to glob on the remote.
              – Chris Down
              Dec 8 '13 at 20:57








            • 2




              Actually the question is about getting pscp on the client side to allow remote globbing.
              – Patrick
              Dec 8 '13 at 22:08















            up vote
            109
            down vote










            up vote
            109
            down vote









            You need to pass a literal escape to scp to avoid the remote machine treating * as a glob (notice that it is doubly quoted):



            scp 'SERVERNAME:/DIR/*' .





            share|improve this answer














            You need to pass a literal escape to scp to avoid the remote machine treating * as a glob (notice that it is doubly quoted):



            scp 'SERVERNAME:/DIR/*' .






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Sep 12 '13 at 16:28

























            answered Dec 22 '11 at 13:46









            Chris Down

            78.3k13187200




            78.3k13187200








            • 32




              You either need quotes, or a backslash before the star, not both. And scp is not the one expanding it, the shell is.
              – Patrick
              Dec 23 '11 at 4:39












            • @Patrick That's not correct, scp expands the glob, even if your shell doesn't (you can try it for yourself). There are two stages: stopping your shell from expanding the glob (which is not necessary because it should have nothing to expand the glob to, and thus will remain intact), and telling scp that this character is not a glob. If it was your shell expanding the glob you would not have to escape it at all.
              – Chris Down
              Dec 23 '11 at 13:29








            • 3




              Have you tried it? I just did, works exactly as I described (quoting and escaping causes failure). User1274964 even confirms the behavior in his answer. touch /tmp/abcd.1234; scp 'localhost:/tmp/abcd.*' ./: scp: /tmp/abcd.*: No such file or directory
              – Patrick
              Dec 7 '13 at 1:00








            • 2




              @Patrick The question is about using a literal asterisk, ie, avoiding globbing altogether, not about how to glob on the remote.
              – Chris Down
              Dec 8 '13 at 20:57








            • 2




              Actually the question is about getting pscp on the client side to allow remote globbing.
              – Patrick
              Dec 8 '13 at 22:08
















            • 32




              You either need quotes, or a backslash before the star, not both. And scp is not the one expanding it, the shell is.
              – Patrick
              Dec 23 '11 at 4:39












            • @Patrick That's not correct, scp expands the glob, even if your shell doesn't (you can try it for yourself). There are two stages: stopping your shell from expanding the glob (which is not necessary because it should have nothing to expand the glob to, and thus will remain intact), and telling scp that this character is not a glob. If it was your shell expanding the glob you would not have to escape it at all.
              – Chris Down
              Dec 23 '11 at 13:29








            • 3




              Have you tried it? I just did, works exactly as I described (quoting and escaping causes failure). User1274964 even confirms the behavior in his answer. touch /tmp/abcd.1234; scp 'localhost:/tmp/abcd.*' ./: scp: /tmp/abcd.*: No such file or directory
              – Patrick
              Dec 7 '13 at 1:00








            • 2




              @Patrick The question is about using a literal asterisk, ie, avoiding globbing altogether, not about how to glob on the remote.
              – Chris Down
              Dec 8 '13 at 20:57








            • 2




              Actually the question is about getting pscp on the client side to allow remote globbing.
              – Patrick
              Dec 8 '13 at 22:08










            32




            32




            You either need quotes, or a backslash before the star, not both. And scp is not the one expanding it, the shell is.
            – Patrick
            Dec 23 '11 at 4:39






            You either need quotes, or a backslash before the star, not both. And scp is not the one expanding it, the shell is.
            – Patrick
            Dec 23 '11 at 4:39














            @Patrick That's not correct, scp expands the glob, even if your shell doesn't (you can try it for yourself). There are two stages: stopping your shell from expanding the glob (which is not necessary because it should have nothing to expand the glob to, and thus will remain intact), and telling scp that this character is not a glob. If it was your shell expanding the glob you would not have to escape it at all.
            – Chris Down
            Dec 23 '11 at 13:29






            @Patrick That's not correct, scp expands the glob, even if your shell doesn't (you can try it for yourself). There are two stages: stopping your shell from expanding the glob (which is not necessary because it should have nothing to expand the glob to, and thus will remain intact), and telling scp that this character is not a glob. If it was your shell expanding the glob you would not have to escape it at all.
            – Chris Down
            Dec 23 '11 at 13:29






            3




            3




            Have you tried it? I just did, works exactly as I described (quoting and escaping causes failure). User1274964 even confirms the behavior in his answer. touch /tmp/abcd.1234; scp 'localhost:/tmp/abcd.*' ./: scp: /tmp/abcd.*: No such file or directory
            – Patrick
            Dec 7 '13 at 1:00






            Have you tried it? I just did, works exactly as I described (quoting and escaping causes failure). User1274964 even confirms the behavior in his answer. touch /tmp/abcd.1234; scp 'localhost:/tmp/abcd.*' ./: scp: /tmp/abcd.*: No such file or directory
            – Patrick
            Dec 7 '13 at 1:00






            2




            2




            @Patrick The question is about using a literal asterisk, ie, avoiding globbing altogether, not about how to glob on the remote.
            – Chris Down
            Dec 8 '13 at 20:57






            @Patrick The question is about using a literal asterisk, ie, avoiding globbing altogether, not about how to glob on the remote.
            – Chris Down
            Dec 8 '13 at 20:57






            2




            2




            Actually the question is about getting pscp on the client side to allow remote globbing.
            – Patrick
            Dec 8 '13 at 22:08






            Actually the question is about getting pscp on the client side to allow remote globbing.
            – Patrick
            Dec 8 '13 at 22:08














            up vote
            45
            down vote













            I found Patrick's advice to be correct, although Chris's answer got me on the right track. Use quotes and then you don't need the backslash before the asterisk.



            scp 'SERVERNAME:/tmp/file_num*' .


            scp: /tmp/file_num*.csv: No such file or directory



            scp 'SERVERNAME:/tmp/file_num*' .


            judgments_for_job_171642.csv 100% 32KB 32.0KB/s 00:00

            judgments_for_job_172394.csv 100% 548KB 182.6KB/s 00:03






            share|improve this answer

















            • 4




              Right, because this means that you want to glob on the remote. The question is about how to stop globbing on the remote (to get a literal *), not about how to glob on the remote only.
              – Chris Down
              Dec 8 '13 at 20:57








            • 1




              @ChrisDown. No. The user wants the wildcard not expanded on the host, and does want it expanded on the remote, to allow it to match multiple files there. None of the files returned have a literal '*' in them. Did you mean "stop globbing on the host "?
              – Tim Bird
              Sep 7 '16 at 19:38

















            up vote
            45
            down vote













            I found Patrick's advice to be correct, although Chris's answer got me on the right track. Use quotes and then you don't need the backslash before the asterisk.



            scp 'SERVERNAME:/tmp/file_num*' .


            scp: /tmp/file_num*.csv: No such file or directory



            scp 'SERVERNAME:/tmp/file_num*' .


            judgments_for_job_171642.csv 100% 32KB 32.0KB/s 00:00

            judgments_for_job_172394.csv 100% 548KB 182.6KB/s 00:03






            share|improve this answer

















            • 4




              Right, because this means that you want to glob on the remote. The question is about how to stop globbing on the remote (to get a literal *), not about how to glob on the remote only.
              – Chris Down
              Dec 8 '13 at 20:57








            • 1




              @ChrisDown. No. The user wants the wildcard not expanded on the host, and does want it expanded on the remote, to allow it to match multiple files there. None of the files returned have a literal '*' in them. Did you mean "stop globbing on the host "?
              – Tim Bird
              Sep 7 '16 at 19:38















            up vote
            45
            down vote










            up vote
            45
            down vote









            I found Patrick's advice to be correct, although Chris's answer got me on the right track. Use quotes and then you don't need the backslash before the asterisk.



            scp 'SERVERNAME:/tmp/file_num*' .


            scp: /tmp/file_num*.csv: No such file or directory



            scp 'SERVERNAME:/tmp/file_num*' .


            judgments_for_job_171642.csv 100% 32KB 32.0KB/s 00:00

            judgments_for_job_172394.csv 100% 548KB 182.6KB/s 00:03






            share|improve this answer












            I found Patrick's advice to be correct, although Chris's answer got me on the right track. Use quotes and then you don't need the backslash before the asterisk.



            scp 'SERVERNAME:/tmp/file_num*' .


            scp: /tmp/file_num*.csv: No such file or directory



            scp 'SERVERNAME:/tmp/file_num*' .


            judgments_for_job_171642.csv 100% 32KB 32.0KB/s 00:00

            judgments_for_job_172394.csv 100% 548KB 182.6KB/s 00:03







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 2 '13 at 0:41









            user1274964

            55142




            55142








            • 4




              Right, because this means that you want to glob on the remote. The question is about how to stop globbing on the remote (to get a literal *), not about how to glob on the remote only.
              – Chris Down
              Dec 8 '13 at 20:57








            • 1




              @ChrisDown. No. The user wants the wildcard not expanded on the host, and does want it expanded on the remote, to allow it to match multiple files there. None of the files returned have a literal '*' in them. Did you mean "stop globbing on the host "?
              – Tim Bird
              Sep 7 '16 at 19:38
















            • 4




              Right, because this means that you want to glob on the remote. The question is about how to stop globbing on the remote (to get a literal *), not about how to glob on the remote only.
              – Chris Down
              Dec 8 '13 at 20:57








            • 1




              @ChrisDown. No. The user wants the wildcard not expanded on the host, and does want it expanded on the remote, to allow it to match multiple files there. None of the files returned have a literal '*' in them. Did you mean "stop globbing on the host "?
              – Tim Bird
              Sep 7 '16 at 19:38










            4




            4




            Right, because this means that you want to glob on the remote. The question is about how to stop globbing on the remote (to get a literal *), not about how to glob on the remote only.
            – Chris Down
            Dec 8 '13 at 20:57






            Right, because this means that you want to glob on the remote. The question is about how to stop globbing on the remote (to get a literal *), not about how to glob on the remote only.
            – Chris Down
            Dec 8 '13 at 20:57






            1




            1




            @ChrisDown. No. The user wants the wildcard not expanded on the host, and does want it expanded on the remote, to allow it to match multiple files there. None of the files returned have a literal '*' in them. Did you mean "stop globbing on the host "?
            – Tim Bird
            Sep 7 '16 at 19:38






            @ChrisDown. No. The user wants the wildcard not expanded on the host, and does want it expanded on the remote, to allow it to match multiple files there. None of the files returned have a literal '*' in them. Did you mean "stop globbing on the host "?
            – Tim Bird
            Sep 7 '16 at 19:38












            up vote
            0
            down vote













            For me it works differently in bash and in c-shell. Don't ask why I use c-shell. In bash I don't need '' - in c-shell I do. So it seems they handle the globs differently in different linux versions.






            share|improve this answer








            New contributor




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






















              up vote
              0
              down vote













              For me it works differently in bash and in c-shell. Don't ask why I use c-shell. In bash I don't need '' - in c-shell I do. So it seems they handle the globs differently in different linux versions.






              share|improve this answer








              New contributor




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




















                up vote
                0
                down vote










                up vote
                0
                down vote









                For me it works differently in bash and in c-shell. Don't ask why I use c-shell. In bash I don't need '' - in c-shell I do. So it seems they handle the globs differently in different linux versions.






                share|improve this answer








                New contributor




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









                For me it works differently in bash and in c-shell. Don't ask why I use c-shell. In bash I don't need '' - in c-shell I do. So it seems they handle the globs differently in different linux versions.







                share|improve this answer








                New contributor




                Sammy777 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 answer



                share|improve this answer






                New contributor




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









                answered Nov 30 at 17:49









                Sammy777

                1




                1




                New contributor




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





                New contributor





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






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






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f27419%2fhow-to-use-wildcards-when-copying-with-scp%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Accessing regular linux commands in Huawei's Dopra Linux

                    Can't connect RFCOMM socket: Host is down

                    Kernel panic - not syncing: Fatal Exception in Interrupt