How to zip specific files that are located in subdirectoriesHow to remove all files and subdirectories in a directory WITHOUT deleting the directory in bash?Excludes specific files from all subdirectories when creating a zip fileExtract several zip files, each in a new folder with the same name, via Ubuntu terminalHow can I delete all folders of a specific name without deleting Contents in it?Delete the parent directory (non-empty) if a specific child directory is emptyWhy won't excluding a specific folder work while I'm making a .zip file?Rename the files as they are extracted from the zip file as the name of the zip file itselfHow can I recursively zip files in their own folder?

Why are some files not movable on Windows 10?

Bash awk command with quotes

What 68-pin connector is this on my 2.5" solid state drive?

How to publish superseding results without creating enemies

Building Truncatable Primes using Nest(List), While, Fold

What is a "major country" as named in Bernie Sanders' Healthcare debate answers?

Is the Dodge action perceptible to other characters?

How to modify this code to add more vertical space in timeline that uses Tikz

Test to know when to use GLM over Linear Regression?

Ambiguity in notation resolved by +

How would you control supersoldiers in a late iron-age society?

Are space camera sensors usually round, or square?

'Overwrote' files, space still occupied, are they lost?

In what sequence should an advanced civilization teach technology to medieval society to maximize rate of adoption?

Permutations in Disguise

Can derivatives be defined as anti-integrals?

Read string of any length in C

Are there objective criteria for classifying consonance v. dissonance?

What organs or modifications would be needed for a life biological creature not to require sleep?

How to give my students a straightedge instead of a ruler

Would it be unbalanced to increase a druid's number of uses of Wild Shape based on level?

Planar regular languages

Are there any rules about taking damage whilst holding your breath in combat?

Is it possible to determine the index of a bip32 address?



How to zip specific files that are located in subdirectories


How to remove all files and subdirectories in a directory WITHOUT deleting the directory in bash?Excludes specific files from all subdirectories when creating a zip fileExtract several zip files, each in a new folder with the same name, via Ubuntu terminalHow can I delete all folders of a specific name without deleting Contents in it?Delete the parent directory (non-empty) if a specific child directory is emptyWhy won't excluding a specific folder work while I'm making a .zip file?Rename the files as they are extracted from the zip file as the name of the zip file itselfHow can I recursively zip files in their own folder?






.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






























    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


























      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














      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













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 15 at 11:01









      NasserNasser

      1164 bronze badges




      1164 bronze badges























          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
            Apr 15 at 16:37






          • 1





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

            – dessert
            Apr 15 at 17:26



















          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
              Apr 15 at 11:19













            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/4.0/"u003ecc by-sa 4.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%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
              Apr 15 at 16:37






            • 1





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

              – dessert
              Apr 15 at 17:26
















            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
              Apr 15 at 16:37






            • 1





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

              – dessert
              Apr 15 at 17:26














            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 Apr 15 at 11:47

























            answered Apr 15 at 11:10









            dessertdessert

            29k7 gold badges87 silver badges120 bronze badges




            29k7 gold badges87 silver badges120 bronze badges















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

              – D. Ben Knoble
              Apr 15 at 16:37






            • 1





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

              – dessert
              Apr 15 at 17:26


















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

              – D. Ben Knoble
              Apr 15 at 16:37






            • 1





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

              – dessert
              Apr 15 at 17:26

















            If youre digging further, find might be a good option

            – D. Ben Knoble
            Apr 15 at 16:37





            If youre digging further, find might be a good option

            – D. Ben Knoble
            Apr 15 at 16:37




            1




            1





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

            – dessert
            Apr 15 at 17:26






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

            – dessert
            Apr 15 at 17:26














            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 Apr 15 at 12:01









                dessert

                29k7 gold badges87 silver badges120 bronze badges




                29k7 gold badges87 silver badges120 bronze badges










                answered Apr 15 at 11:11









                Romeo NinovRomeo Ninov

                5773 silver badges10 bronze badges




                5773 silver badges10 bronze badges
























                    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
                      Apr 15 at 11:19















                    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
                      Apr 15 at 11:19













                    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 Apr 15 at 11:13









                    Mohit MalviyaMohit Malviya

                    4362 silver badges7 bronze badges




                    4362 silver badges7 bronze badges















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

                      – dessert
                      Apr 15 at 11:19

















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

                      – dessert
                      Apr 15 at 11:19
















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

                    – dessert
                    Apr 15 at 11:19





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

                    – dessert
                    Apr 15 at 11:19


















                    draft saved

                    draft discarded















































                    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

                    Distance measures on a map of a game The 2019 Stack Overflow Developer Survey Results Are Inmin distance in a graphShortest distance path on contour plotHow to plot a tilted map?Finding points outside of a diskDelaunay link distanceAnnulus from GeoDisks: drawing a ring on a mapNegative Correlation DistanceFind distance along a path (GPS coordinates)Finding position at given distance in a GeoPathMathematics behind distance estimation using camera

                    How to get a smooth, uniform ParametricPlot of a 2D Region?How to plot a complicated Region?How to exclude a region from ParametricPlotHow discretize a region placing vertices on a specific non-uniform gridHow to transform a Plot or a ParametricPlot into a RegionHow can I get a smooth plot of a bounded region?Smooth ParametricPlot3D with RegionFunction?Smooth border of a region ParametricPlotSmooth region boundarySmooth region plot from list of pointsGet minimum y of a certain x in a region

                    Genealogie vun de Merowenger Vum Merowech bis zum Chilperich I. | Navigatiounsmenü