How to zip specific files that are located in subdirectories





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







3















I have a directory that consists of many subdirectories, and each subdirectory contains different files such as:



Directory All contains subdirectories A, B, C, and D. Each subdirectory contains files such as:



A (Run1.csv, Run4.csv)
B (Run2.csv, Run3.csv)
C (Run1.csv, Run3.csv)
D (Run2.csv, Run4.csv)


As you can see, each file has different duplicates in different subdirectories. For example, Run1.csv in folder A has different data from Run1.csv in folder C.



What I want to do is that I want to zip a specific run file, for example, I want to zip all the files of run2. I used the following commands:



zip run2.zip All Run2.csv 

zip run2.zip Run2.csv


But none of them works.



How can I fix that?










share|improve this question







New contributor




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



























    3















    I have a directory that consists of many subdirectories, and each subdirectory contains different files such as:



    Directory All contains subdirectories A, B, C, and D. Each subdirectory contains files such as:



    A (Run1.csv, Run4.csv)
    B (Run2.csv, Run3.csv)
    C (Run1.csv, Run3.csv)
    D (Run2.csv, Run4.csv)


    As you can see, each file has different duplicates in different subdirectories. For example, Run1.csv in folder A has different data from Run1.csv in folder C.



    What I want to do is that I want to zip a specific run file, for example, I want to zip all the files of run2. I used the following commands:



    zip run2.zip All Run2.csv 

    zip run2.zip Run2.csv


    But none of them works.



    How can I fix that?










    share|improve this question







    New contributor




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























      3












      3








      3








      I have a directory that consists of many subdirectories, and each subdirectory contains different files such as:



      Directory All contains subdirectories A, B, C, and D. Each subdirectory contains files such as:



      A (Run1.csv, Run4.csv)
      B (Run2.csv, Run3.csv)
      C (Run1.csv, Run3.csv)
      D (Run2.csv, Run4.csv)


      As you can see, each file has different duplicates in different subdirectories. For example, Run1.csv in folder A has different data from Run1.csv in folder C.



      What I want to do is that I want to zip a specific run file, for example, I want to zip all the files of run2. I used the following commands:



      zip run2.zip All Run2.csv 

      zip run2.zip Run2.csv


      But none of them works.



      How can I fix that?










      share|improve this question







      New contributor




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












      I have a directory that consists of many subdirectories, and each subdirectory contains different files such as:



      Directory All contains subdirectories A, B, C, and D. Each subdirectory contains files such as:



      A (Run1.csv, Run4.csv)
      B (Run2.csv, Run3.csv)
      C (Run1.csv, Run3.csv)
      D (Run2.csv, Run4.csv)


      As you can see, each file has different duplicates in different subdirectories. For example, Run1.csv in folder A has different data from Run1.csv in folder C.



      What I want to do is that I want to zip a specific run file, for example, I want to zip all the files of run2. I used the following commands:



      zip run2.zip All Run2.csv 

      zip run2.zip Run2.csv


      But none of them works.



      How can I fix that?







      command-line ssh zip






      share|improve this question







      New contributor




      Nasser 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




      Nasser 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






      New contributor




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









      asked yesterday









      NasserNasser

      1163




      1163




      New contributor




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





      New contributor





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






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






















          3 Answers
          3






          active

          oldest

          votes


















          6
















          You can use bash Pathname Expansion as follows:



          zip run2.zip */Run2.csv


          */Run2.csv matches every file called Run2.csv in any subdirectory. If you have very many files that match the glob, this fails because of the shell’s ARG_MAX limit. To work around that, use:



          printf '%s' */Run2.csv | xargs -0 zip run2.zip


          This uses the builtin printf to build up a zero-delimited list of the matching files and pipes it to xargs, which calls zip as often as necessary. As add is zip’s default mode, it updates the archive adding the files to it.



          If you need to dig further into an unknown or changing number of subdirectories, set bash’s globstar option with



          shopt -s globstar


          and use:



          zip run2.zip **/Run2.csv  # or respectively
          printf '%s' **/Run2.csv | xargs -0 zip run2.zip


          **/Run2.csv matches every file called Run2.csv in any subdirectory recursively.



          Further reading





          • man zip/PATTERN MATCHING


          • man bash/EXPANSION/Pathname Expansion

          • Bash Hackers Wiki: Pathname expansion (globbing)

          • TLDP Advanced Bash-Scripting Guide: Chapter 18.2. Globbing






          share|improve this answer


























          • If youre digging further, find might be a good option

            – D. Ben Knoble
            yesterday






          • 1





            @D.BenKnoble yes, but I left that to Romeo Ninov for his answer and helped him build the find command line. :)

            – dessert
            yesterday





















          2














          you can use something like to search and archive all (for example) Run2.csv files:



          zip run2.zip `find . -name Run2.csv`


          By suggestion if OP expect special characters (like space) in file/directories names can use command like:



          find . -name Run2.csv -exec zip run2.zip {} +





          share|improve this answer

































            1














            Try this for finding files and zip them in separate files :



            find . -name Run2.csv -print | zip Run2.zip -@





            share|improve this answer
























            • This fails if any of the file or directory names contain whitespaces, you could use … -print0 | xargs -0 zip Run2.zip instead.

              – dessert
              yesterday












            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "89"
            };
            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
            });


            }
            });






            Nasser 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%2faskubuntu.com%2fquestions%2f1134053%2fhow-to-zip-specific-files-that-are-located-in-subdirectories%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









            6
















            You can use bash Pathname Expansion as follows:



            zip run2.zip */Run2.csv


            */Run2.csv matches every file called Run2.csv in any subdirectory. If you have very many files that match the glob, this fails because of the shell’s ARG_MAX limit. To work around that, use:



            printf '%s' */Run2.csv | xargs -0 zip run2.zip


            This uses the builtin printf to build up a zero-delimited list of the matching files and pipes it to xargs, which calls zip as often as necessary. As add is zip’s default mode, it updates the archive adding the files to it.



            If you need to dig further into an unknown or changing number of subdirectories, set bash’s globstar option with



            shopt -s globstar


            and use:



            zip run2.zip **/Run2.csv  # or respectively
            printf '%s' **/Run2.csv | xargs -0 zip run2.zip


            **/Run2.csv matches every file called Run2.csv in any subdirectory recursively.



            Further reading





            • man zip/PATTERN MATCHING


            • man bash/EXPANSION/Pathname Expansion

            • Bash Hackers Wiki: Pathname expansion (globbing)

            • TLDP Advanced Bash-Scripting Guide: Chapter 18.2. Globbing






            share|improve this answer


























            • If youre digging further, find might be a good option

              – D. Ben Knoble
              yesterday






            • 1





              @D.BenKnoble yes, but I left that to Romeo Ninov for his answer and helped him build the find command line. :)

              – dessert
              yesterday


















            6
















            You can use bash Pathname Expansion as follows:



            zip run2.zip */Run2.csv


            */Run2.csv matches every file called Run2.csv in any subdirectory. If you have very many files that match the glob, this fails because of the shell’s ARG_MAX limit. To work around that, use:



            printf '%s' */Run2.csv | xargs -0 zip run2.zip


            This uses the builtin printf to build up a zero-delimited list of the matching files and pipes it to xargs, which calls zip as often as necessary. As add is zip’s default mode, it updates the archive adding the files to it.



            If you need to dig further into an unknown or changing number of subdirectories, set bash’s globstar option with



            shopt -s globstar


            and use:



            zip run2.zip **/Run2.csv  # or respectively
            printf '%s' **/Run2.csv | xargs -0 zip run2.zip


            **/Run2.csv matches every file called Run2.csv in any subdirectory recursively.



            Further reading





            • man zip/PATTERN MATCHING


            • man bash/EXPANSION/Pathname Expansion

            • Bash Hackers Wiki: Pathname expansion (globbing)

            • TLDP Advanced Bash-Scripting Guide: Chapter 18.2. Globbing






            share|improve this answer


























            • If youre digging further, find might be a good option

              – D. Ben Knoble
              yesterday






            • 1





              @D.BenKnoble yes, but I left that to Romeo Ninov for his answer and helped him build the find command line. :)

              – dessert
              yesterday
















            6












            6








            6









            You can use bash Pathname Expansion as follows:



            zip run2.zip */Run2.csv


            */Run2.csv matches every file called Run2.csv in any subdirectory. If you have very many files that match the glob, this fails because of the shell’s ARG_MAX limit. To work around that, use:



            printf '%s' */Run2.csv | xargs -0 zip run2.zip


            This uses the builtin printf to build up a zero-delimited list of the matching files and pipes it to xargs, which calls zip as often as necessary. As add is zip’s default mode, it updates the archive adding the files to it.



            If you need to dig further into an unknown or changing number of subdirectories, set bash’s globstar option with



            shopt -s globstar


            and use:



            zip run2.zip **/Run2.csv  # or respectively
            printf '%s' **/Run2.csv | xargs -0 zip run2.zip


            **/Run2.csv matches every file called Run2.csv in any subdirectory recursively.



            Further reading





            • man zip/PATTERN MATCHING


            • man bash/EXPANSION/Pathname Expansion

            • Bash Hackers Wiki: Pathname expansion (globbing)

            • TLDP Advanced Bash-Scripting Guide: Chapter 18.2. Globbing






            share|improve this answer

















            You can use bash Pathname Expansion as follows:



            zip run2.zip */Run2.csv


            */Run2.csv matches every file called Run2.csv in any subdirectory. If you have very many files that match the glob, this fails because of the shell’s ARG_MAX limit. To work around that, use:



            printf '%s' */Run2.csv | xargs -0 zip run2.zip


            This uses the builtin printf to build up a zero-delimited list of the matching files and pipes it to xargs, which calls zip as often as necessary. As add is zip’s default mode, it updates the archive adding the files to it.



            If you need to dig further into an unknown or changing number of subdirectories, set bash’s globstar option with



            shopt -s globstar


            and use:



            zip run2.zip **/Run2.csv  # or respectively
            printf '%s' **/Run2.csv | xargs -0 zip run2.zip


            **/Run2.csv matches every file called Run2.csv in any subdirectory recursively.



            Further reading





            • man zip/PATTERN MATCHING


            • man bash/EXPANSION/Pathname Expansion

            • Bash Hackers Wiki: Pathname expansion (globbing)

            • TLDP Advanced Bash-Scripting Guide: Chapter 18.2. Globbing







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited yesterday

























            answered yesterday









            dessertdessert

            25.6k674108




            25.6k674108













            • If youre digging further, find might be a good option

              – D. Ben Knoble
              yesterday






            • 1





              @D.BenKnoble yes, but I left that to Romeo Ninov for his answer and helped him build the find command line. :)

              – dessert
              yesterday





















            • If youre digging further, find might be a good option

              – D. Ben Knoble
              yesterday






            • 1





              @D.BenKnoble yes, but I left that to Romeo Ninov for his answer and helped him build the find command line. :)

              – dessert
              yesterday



















            If youre digging further, find might be a good option

            – D. Ben Knoble
            yesterday





            If youre digging further, find might be a good option

            – D. Ben Knoble
            yesterday




            1




            1





            @D.BenKnoble yes, but I left that to Romeo Ninov for his answer and helped him build the find command line. :)

            – dessert
            yesterday







            @D.BenKnoble yes, but I left that to Romeo Ninov for his answer and helped him build the find command line. :)

            – dessert
            yesterday















            2














            you can use something like to search and archive all (for example) Run2.csv files:



            zip run2.zip `find . -name Run2.csv`


            By suggestion if OP expect special characters (like space) in file/directories names can use command like:



            find . -name Run2.csv -exec zip run2.zip {} +





            share|improve this answer






























              2














              you can use something like to search and archive all (for example) Run2.csv files:



              zip run2.zip `find . -name Run2.csv`


              By suggestion if OP expect special characters (like space) in file/directories names can use command like:



              find . -name Run2.csv -exec zip run2.zip {} +





              share|improve this answer




























                2












                2








                2







                you can use something like to search and archive all (for example) Run2.csv files:



                zip run2.zip `find . -name Run2.csv`


                By suggestion if OP expect special characters (like space) in file/directories names can use command like:



                find . -name Run2.csv -exec zip run2.zip {} +





                share|improve this answer















                you can use something like to search and archive all (for example) Run2.csv files:



                zip run2.zip `find . -name Run2.csv`


                By suggestion if OP expect special characters (like space) in file/directories names can use command like:



                find . -name Run2.csv -exec zip run2.zip {} +






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited yesterday









                dessert

                25.6k674108




                25.6k674108










                answered yesterday









                Romeo NinovRomeo Ninov

                59519




                59519























                    1














                    Try this for finding files and zip them in separate files :



                    find . -name Run2.csv -print | zip Run2.zip -@





                    share|improve this answer
























                    • This fails if any of the file or directory names contain whitespaces, you could use … -print0 | xargs -0 zip Run2.zip instead.

                      – dessert
                      yesterday
















                    1














                    Try this for finding files and zip them in separate files :



                    find . -name Run2.csv -print | zip Run2.zip -@





                    share|improve this answer
























                    • This fails if any of the file or directory names contain whitespaces, you could use … -print0 | xargs -0 zip Run2.zip instead.

                      – dessert
                      yesterday














                    1












                    1








                    1







                    Try this for finding files and zip them in separate files :



                    find . -name Run2.csv -print | zip Run2.zip -@





                    share|improve this answer













                    Try this for finding files and zip them in separate files :



                    find . -name Run2.csv -print | zip Run2.zip -@






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered yesterday









                    Mohit MalviyaMohit Malviya

                    1064




                    1064













                    • This fails if any of the file or directory names contain whitespaces, you could use … -print0 | xargs -0 zip Run2.zip instead.

                      – dessert
                      yesterday



















                    • This fails if any of the file or directory names contain whitespaces, you could use … -print0 | xargs -0 zip Run2.zip instead.

                      – dessert
                      yesterday

















                    This fails if any of the file or directory names contain whitespaces, you could use … -print0 | xargs -0 zip Run2.zip instead.

                    – dessert
                    yesterday





                    This fails if any of the file or directory names contain whitespaces, you could use … -print0 | xargs -0 zip Run2.zip instead.

                    – dessert
                    yesterday










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










                    draft saved

                    draft discarded


















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













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












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
















                    Thanks for contributing an answer to Ask Ubuntu!


                    • 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%2faskubuntu.com%2fquestions%2f1134053%2fhow-to-zip-specific-files-that-are-located-in-subdirectories%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

                    數位音樂下載

                    格利澤436b

                    When can things happen in Etherscan, such as the picture below?