scp all files ending '-123.jpg' - recursion, spaces, wildcards …












0















There's too much going on for me to get my noobie head around here. I'm wanting to download all files that end -123.jpg from a multitude of nested directories on a remote server. Some of these directories have spaces in their names. I'm thinking that the command should be along the lines of:



scp -r user@server:/path/to/parent directory/*/*/*123.jpg ./


… where "parent directory" is a directory name with a space, and the specified path goes as deep as it can before it splits off to various sub-directories, for example dir/sub dir/[uniquely_id]-123.jpg file. (Note that these sub-directories often contain spaces too, should that affect the * wildcard)



I'm getting 'no match' returned for this, or 'no such file or directory' if I meddle with the space escaping. I'm thinking therefore that it's the recursion or the wildcard that I've got wrong.



Thanks in advance.










share|improve this question













migrated from stackoverflow.com Nov 2 '10 at 0:28


This question came from our site for professional and enthusiast programmers.























    0















    There's too much going on for me to get my noobie head around here. I'm wanting to download all files that end -123.jpg from a multitude of nested directories on a remote server. Some of these directories have spaces in their names. I'm thinking that the command should be along the lines of:



    scp -r user@server:/path/to/parent directory/*/*/*123.jpg ./


    … where "parent directory" is a directory name with a space, and the specified path goes as deep as it can before it splits off to various sub-directories, for example dir/sub dir/[uniquely_id]-123.jpg file. (Note that these sub-directories often contain spaces too, should that affect the * wildcard)



    I'm getting 'no match' returned for this, or 'no such file or directory' if I meddle with the space escaping. I'm thinking therefore that it's the recursion or the wildcard that I've got wrong.



    Thanks in advance.










    share|improve this question













    migrated from stackoverflow.com Nov 2 '10 at 0:28


    This question came from our site for professional and enthusiast programmers.





















      0












      0








      0








      There's too much going on for me to get my noobie head around here. I'm wanting to download all files that end -123.jpg from a multitude of nested directories on a remote server. Some of these directories have spaces in their names. I'm thinking that the command should be along the lines of:



      scp -r user@server:/path/to/parent directory/*/*/*123.jpg ./


      … where "parent directory" is a directory name with a space, and the specified path goes as deep as it can before it splits off to various sub-directories, for example dir/sub dir/[uniquely_id]-123.jpg file. (Note that these sub-directories often contain spaces too, should that affect the * wildcard)



      I'm getting 'no match' returned for this, or 'no such file or directory' if I meddle with the space escaping. I'm thinking therefore that it's the recursion or the wildcard that I've got wrong.



      Thanks in advance.










      share|improve this question














      There's too much going on for me to get my noobie head around here. I'm wanting to download all files that end -123.jpg from a multitude of nested directories on a remote server. Some of these directories have spaces in their names. I'm thinking that the command should be along the lines of:



      scp -r user@server:/path/to/parent directory/*/*/*123.jpg ./


      … where "parent directory" is a directory name with a space, and the specified path goes as deep as it can before it splits off to various sub-directories, for example dir/sub dir/[uniquely_id]-123.jpg file. (Note that these sub-directories often contain spaces too, should that affect the * wildcard)



      I'm getting 'no match' returned for this, or 'no such file or directory' if I meddle with the space escaping. I'm thinking therefore that it's the recursion or the wildcard that I've got wrong.



      Thanks in advance.







      ssh terminal scp






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 1 '10 at 18:50









      hyppyhyppy

      111




      111




      migrated from stackoverflow.com Nov 2 '10 at 0:28


      This question came from our site for professional and enthusiast programmers.









      migrated from stackoverflow.com Nov 2 '10 at 0:28


      This question came from our site for professional and enthusiast programmers.
























          4 Answers
          4






          active

          oldest

          votes


















          2














          Lacking your server layout for testing I don't know if the following command actually works, but I think rsync would be better than scp in that case, as you can specify in- and exclude patterns. Something like:



          rsync -arvzSH  --include "*123.jpg" --exclude "*" user@server:/path/to/parent directory/ /path/to/target directory/


          may work. But you better double check the rsync documentation.






          share|improve this answer

































            0














            Filename escaping with scp is tricky; your arguments get (re)expanded on the remote side. "Interesting" characters have to be double quoted, to avoid special handing by your local shell and by the remote. I would expect both the following to work for you:



            scp user@server:'/path/to/parent directory/*/*/*123.jpg' ./
            scp user@server:'"/path/to/parent directory"/*/*/*123.jpg' ./


            If that's confusing, rsync is pretty easy to use (as lothar mentions), and piping tar or cpio through ssh is pretty easy too.



            ssh user@server 'cd /path/to/parent directory;
            find -name "*123.jpg" -print0 | cpio -0 -o' |
            cpio -i -d -v





            share|improve this answer































              0














              This properly should be done in two parts:




              1. first find all needed files and copy them to one folder (this does not work if you have the same filenames) - you may do it with one find and -exec

              2. then send a bunch of files using scp


              scp is not enough advanced to copy folders structure and there is no single command to make a copy of a folders tree.



              Also, if you need all files in folders, as you will not be able to select them by wildcards, and you want to preserve folders structure - you may want to use mc = Midnight Commander and its "Shell link".






              share|improve this answer

































                -1














                A work around for scp with wildcards:



                for i in "*-123.jpg"
                do
                scp $i <user>@<server>:/path/to/destination/
                done


                Refer: https://community.hpe.com/t5/System-Administration/How-to-scp-mutiple-files-using-wild-chars-or-in-a-single-scp/m-p/3639440/highlight/true#M238959






                share|improve this answer


























                • What if filename of the file will contain space? It won't work, I think. Maybe find command would be better (with xargs)?

                  – pbies
                  Jan 4 at 7:28











                • Not sure why -1 ? the solution works. If there are other scenarios it can be improved further. But the given solution is NOT wrong.

                  – AmitM
                  Jan 11 at 6:28






                • 1





                  For this particular question the answer is ok, but we try to make things universal. There are few bugs in this answer: 1. never for ls 2. $i should be in quotes 3. find should be used

                  – pbies
                  Jan 12 at 18:42











                • 1) updated the answer to remove 'ls', not required. 2) $i works without quotes 3) works for files with space in names.

                  – AmitM
                  Jan 14 at 5:25













                • I'm not sure what shell you're using, but in de-facto standard sh/bash, an unquoted $i will have its value subject to word-splitting and so values with spaces in them will not work as expected – they'll be passed to scp as multiple arguments, each having part of the file name.

                  – grawity
                  Jan 14 at 5:49











                Your Answer








                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "3"
                };
                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',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                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%2fsuperuser.com%2fquestions%2f205990%2fscp-all-files-ending-123-jpg-recursion-spaces-wildcards%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                4 Answers
                4






                active

                oldest

                votes








                4 Answers
                4






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                2














                Lacking your server layout for testing I don't know if the following command actually works, but I think rsync would be better than scp in that case, as you can specify in- and exclude patterns. Something like:



                rsync -arvzSH  --include "*123.jpg" --exclude "*" user@server:/path/to/parent directory/ /path/to/target directory/


                may work. But you better double check the rsync documentation.






                share|improve this answer






























                  2














                  Lacking your server layout for testing I don't know if the following command actually works, but I think rsync would be better than scp in that case, as you can specify in- and exclude patterns. Something like:



                  rsync -arvzSH  --include "*123.jpg" --exclude "*" user@server:/path/to/parent directory/ /path/to/target directory/


                  may work. But you better double check the rsync documentation.






                  share|improve this answer




























                    2












                    2








                    2







                    Lacking your server layout for testing I don't know if the following command actually works, but I think rsync would be better than scp in that case, as you can specify in- and exclude patterns. Something like:



                    rsync -arvzSH  --include "*123.jpg" --exclude "*" user@server:/path/to/parent directory/ /path/to/target directory/


                    may work. But you better double check the rsync documentation.






                    share|improve this answer















                    Lacking your server layout for testing I don't know if the following command actually works, but I think rsync would be better than scp in that case, as you can specify in- and exclude patterns. Something like:



                    rsync -arvzSH  --include "*123.jpg" --exclude "*" user@server:/path/to/parent directory/ /path/to/target directory/


                    may work. But you better double check the rsync documentation.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Dec 3 '14 at 18:32









                    slhck

                    161k47446468




                    161k47446468










                    answered Nov 1 '10 at 22:07









                    lotharlothar

                    1211




                    1211

























                        0














                        Filename escaping with scp is tricky; your arguments get (re)expanded on the remote side. "Interesting" characters have to be double quoted, to avoid special handing by your local shell and by the remote. I would expect both the following to work for you:



                        scp user@server:'/path/to/parent directory/*/*/*123.jpg' ./
                        scp user@server:'"/path/to/parent directory"/*/*/*123.jpg' ./


                        If that's confusing, rsync is pretty easy to use (as lothar mentions), and piping tar or cpio through ssh is pretty easy too.



                        ssh user@server 'cd /path/to/parent directory;
                        find -name "*123.jpg" -print0 | cpio -0 -o' |
                        cpio -i -d -v





                        share|improve this answer




























                          0














                          Filename escaping with scp is tricky; your arguments get (re)expanded on the remote side. "Interesting" characters have to be double quoted, to avoid special handing by your local shell and by the remote. I would expect both the following to work for you:



                          scp user@server:'/path/to/parent directory/*/*/*123.jpg' ./
                          scp user@server:'"/path/to/parent directory"/*/*/*123.jpg' ./


                          If that's confusing, rsync is pretty easy to use (as lothar mentions), and piping tar or cpio through ssh is pretty easy too.



                          ssh user@server 'cd /path/to/parent directory;
                          find -name "*123.jpg" -print0 | cpio -0 -o' |
                          cpio -i -d -v





                          share|improve this answer


























                            0












                            0








                            0







                            Filename escaping with scp is tricky; your arguments get (re)expanded on the remote side. "Interesting" characters have to be double quoted, to avoid special handing by your local shell and by the remote. I would expect both the following to work for you:



                            scp user@server:'/path/to/parent directory/*/*/*123.jpg' ./
                            scp user@server:'"/path/to/parent directory"/*/*/*123.jpg' ./


                            If that's confusing, rsync is pretty easy to use (as lothar mentions), and piping tar or cpio through ssh is pretty easy too.



                            ssh user@server 'cd /path/to/parent directory;
                            find -name "*123.jpg" -print0 | cpio -0 -o' |
                            cpio -i -d -v





                            share|improve this answer













                            Filename escaping with scp is tricky; your arguments get (re)expanded on the remote side. "Interesting" characters have to be double quoted, to avoid special handing by your local shell and by the remote. I would expect both the following to work for you:



                            scp user@server:'/path/to/parent directory/*/*/*123.jpg' ./
                            scp user@server:'"/path/to/parent directory"/*/*/*123.jpg' ./


                            If that's confusing, rsync is pretty easy to use (as lothar mentions), and piping tar or cpio through ssh is pretty easy too.



                            ssh user@server 'cd /path/to/parent directory;
                            find -name "*123.jpg" -print0 | cpio -0 -o' |
                            cpio -i -d -v






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 2 '10 at 2:51









                            ephemientephemient

                            19.1k42319




                            19.1k42319























                                0














                                This properly should be done in two parts:




                                1. first find all needed files and copy them to one folder (this does not work if you have the same filenames) - you may do it with one find and -exec

                                2. then send a bunch of files using scp


                                scp is not enough advanced to copy folders structure and there is no single command to make a copy of a folders tree.



                                Also, if you need all files in folders, as you will not be able to select them by wildcards, and you want to preserve folders structure - you may want to use mc = Midnight Commander and its "Shell link".






                                share|improve this answer






























                                  0














                                  This properly should be done in two parts:




                                  1. first find all needed files and copy them to one folder (this does not work if you have the same filenames) - you may do it with one find and -exec

                                  2. then send a bunch of files using scp


                                  scp is not enough advanced to copy folders structure and there is no single command to make a copy of a folders tree.



                                  Also, if you need all files in folders, as you will not be able to select them by wildcards, and you want to preserve folders structure - you may want to use mc = Midnight Commander and its "Shell link".






                                  share|improve this answer




























                                    0












                                    0








                                    0







                                    This properly should be done in two parts:




                                    1. first find all needed files and copy them to one folder (this does not work if you have the same filenames) - you may do it with one find and -exec

                                    2. then send a bunch of files using scp


                                    scp is not enough advanced to copy folders structure and there is no single command to make a copy of a folders tree.



                                    Also, if you need all files in folders, as you will not be able to select them by wildcards, and you want to preserve folders structure - you may want to use mc = Midnight Commander and its "Shell link".






                                    share|improve this answer















                                    This properly should be done in two parts:




                                    1. first find all needed files and copy them to one folder (this does not work if you have the same filenames) - you may do it with one find and -exec

                                    2. then send a bunch of files using scp


                                    scp is not enough advanced to copy folders structure and there is no single command to make a copy of a folders tree.



                                    Also, if you need all files in folders, as you will not be able to select them by wildcards, and you want to preserve folders structure - you may want to use mc = Midnight Commander and its "Shell link".







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Jan 26 at 9:16

























                                    answered Jan 26 at 9:06









                                    pbiespbies

                                    1,55911217




                                    1,55911217























                                        -1














                                        A work around for scp with wildcards:



                                        for i in "*-123.jpg"
                                        do
                                        scp $i <user>@<server>:/path/to/destination/
                                        done


                                        Refer: https://community.hpe.com/t5/System-Administration/How-to-scp-mutiple-files-using-wild-chars-or-in-a-single-scp/m-p/3639440/highlight/true#M238959






                                        share|improve this answer


























                                        • What if filename of the file will contain space? It won't work, I think. Maybe find command would be better (with xargs)?

                                          – pbies
                                          Jan 4 at 7:28











                                        • Not sure why -1 ? the solution works. If there are other scenarios it can be improved further. But the given solution is NOT wrong.

                                          – AmitM
                                          Jan 11 at 6:28






                                        • 1





                                          For this particular question the answer is ok, but we try to make things universal. There are few bugs in this answer: 1. never for ls 2. $i should be in quotes 3. find should be used

                                          – pbies
                                          Jan 12 at 18:42











                                        • 1) updated the answer to remove 'ls', not required. 2) $i works without quotes 3) works for files with space in names.

                                          – AmitM
                                          Jan 14 at 5:25













                                        • I'm not sure what shell you're using, but in de-facto standard sh/bash, an unquoted $i will have its value subject to word-splitting and so values with spaces in them will not work as expected – they'll be passed to scp as multiple arguments, each having part of the file name.

                                          – grawity
                                          Jan 14 at 5:49
















                                        -1














                                        A work around for scp with wildcards:



                                        for i in "*-123.jpg"
                                        do
                                        scp $i <user>@<server>:/path/to/destination/
                                        done


                                        Refer: https://community.hpe.com/t5/System-Administration/How-to-scp-mutiple-files-using-wild-chars-or-in-a-single-scp/m-p/3639440/highlight/true#M238959






                                        share|improve this answer


























                                        • What if filename of the file will contain space? It won't work, I think. Maybe find command would be better (with xargs)?

                                          – pbies
                                          Jan 4 at 7:28











                                        • Not sure why -1 ? the solution works. If there are other scenarios it can be improved further. But the given solution is NOT wrong.

                                          – AmitM
                                          Jan 11 at 6:28






                                        • 1





                                          For this particular question the answer is ok, but we try to make things universal. There are few bugs in this answer: 1. never for ls 2. $i should be in quotes 3. find should be used

                                          – pbies
                                          Jan 12 at 18:42











                                        • 1) updated the answer to remove 'ls', not required. 2) $i works without quotes 3) works for files with space in names.

                                          – AmitM
                                          Jan 14 at 5:25













                                        • I'm not sure what shell you're using, but in de-facto standard sh/bash, an unquoted $i will have its value subject to word-splitting and so values with spaces in them will not work as expected – they'll be passed to scp as multiple arguments, each having part of the file name.

                                          – grawity
                                          Jan 14 at 5:49














                                        -1












                                        -1








                                        -1







                                        A work around for scp with wildcards:



                                        for i in "*-123.jpg"
                                        do
                                        scp $i <user>@<server>:/path/to/destination/
                                        done


                                        Refer: https://community.hpe.com/t5/System-Administration/How-to-scp-mutiple-files-using-wild-chars-or-in-a-single-scp/m-p/3639440/highlight/true#M238959






                                        share|improve this answer















                                        A work around for scp with wildcards:



                                        for i in "*-123.jpg"
                                        do
                                        scp $i <user>@<server>:/path/to/destination/
                                        done


                                        Refer: https://community.hpe.com/t5/System-Administration/How-to-scp-mutiple-files-using-wild-chars-or-in-a-single-scp/m-p/3639440/highlight/true#M238959







                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Jan 14 at 5:24

























                                        answered Jan 4 at 7:23









                                        AmitMAmitM

                                        12




                                        12













                                        • What if filename of the file will contain space? It won't work, I think. Maybe find command would be better (with xargs)?

                                          – pbies
                                          Jan 4 at 7:28











                                        • Not sure why -1 ? the solution works. If there are other scenarios it can be improved further. But the given solution is NOT wrong.

                                          – AmitM
                                          Jan 11 at 6:28






                                        • 1





                                          For this particular question the answer is ok, but we try to make things universal. There are few bugs in this answer: 1. never for ls 2. $i should be in quotes 3. find should be used

                                          – pbies
                                          Jan 12 at 18:42











                                        • 1) updated the answer to remove 'ls', not required. 2) $i works without quotes 3) works for files with space in names.

                                          – AmitM
                                          Jan 14 at 5:25













                                        • I'm not sure what shell you're using, but in de-facto standard sh/bash, an unquoted $i will have its value subject to word-splitting and so values with spaces in them will not work as expected – they'll be passed to scp as multiple arguments, each having part of the file name.

                                          – grawity
                                          Jan 14 at 5:49



















                                        • What if filename of the file will contain space? It won't work, I think. Maybe find command would be better (with xargs)?

                                          – pbies
                                          Jan 4 at 7:28











                                        • Not sure why -1 ? the solution works. If there are other scenarios it can be improved further. But the given solution is NOT wrong.

                                          – AmitM
                                          Jan 11 at 6:28






                                        • 1





                                          For this particular question the answer is ok, but we try to make things universal. There are few bugs in this answer: 1. never for ls 2. $i should be in quotes 3. find should be used

                                          – pbies
                                          Jan 12 at 18:42











                                        • 1) updated the answer to remove 'ls', not required. 2) $i works without quotes 3) works for files with space in names.

                                          – AmitM
                                          Jan 14 at 5:25













                                        • I'm not sure what shell you're using, but in de-facto standard sh/bash, an unquoted $i will have its value subject to word-splitting and so values with spaces in them will not work as expected – they'll be passed to scp as multiple arguments, each having part of the file name.

                                          – grawity
                                          Jan 14 at 5:49

















                                        What if filename of the file will contain space? It won't work, I think. Maybe find command would be better (with xargs)?

                                        – pbies
                                        Jan 4 at 7:28





                                        What if filename of the file will contain space? It won't work, I think. Maybe find command would be better (with xargs)?

                                        – pbies
                                        Jan 4 at 7:28













                                        Not sure why -1 ? the solution works. If there are other scenarios it can be improved further. But the given solution is NOT wrong.

                                        – AmitM
                                        Jan 11 at 6:28





                                        Not sure why -1 ? the solution works. If there are other scenarios it can be improved further. But the given solution is NOT wrong.

                                        – AmitM
                                        Jan 11 at 6:28




                                        1




                                        1





                                        For this particular question the answer is ok, but we try to make things universal. There are few bugs in this answer: 1. never for ls 2. $i should be in quotes 3. find should be used

                                        – pbies
                                        Jan 12 at 18:42





                                        For this particular question the answer is ok, but we try to make things universal. There are few bugs in this answer: 1. never for ls 2. $i should be in quotes 3. find should be used

                                        – pbies
                                        Jan 12 at 18:42













                                        1) updated the answer to remove 'ls', not required. 2) $i works without quotes 3) works for files with space in names.

                                        – AmitM
                                        Jan 14 at 5:25







                                        1) updated the answer to remove 'ls', not required. 2) $i works without quotes 3) works for files with space in names.

                                        – AmitM
                                        Jan 14 at 5:25















                                        I'm not sure what shell you're using, but in de-facto standard sh/bash, an unquoted $i will have its value subject to word-splitting and so values with spaces in them will not work as expected – they'll be passed to scp as multiple arguments, each having part of the file name.

                                        – grawity
                                        Jan 14 at 5:49





                                        I'm not sure what shell you're using, but in de-facto standard sh/bash, an unquoted $i will have its value subject to word-splitting and so values with spaces in them will not work as expected – they'll be passed to scp as multiple arguments, each having part of the file name.

                                        – grawity
                                        Jan 14 at 5:49


















                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Super User!


                                        • 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%2fsuperuser.com%2fquestions%2f205990%2fscp-all-files-ending-123-jpg-recursion-spaces-wildcards%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

                                        "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                                        Alcedinidae

                                        RAC Tourist Trophy