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;
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
add a comment
|
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
add a comment
|
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
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
command-line ssh zip
asked Apr 15 at 11:01
NasserNasser
1164 bronze badges
1164 bronze badges
add a comment
|
add a comment
|
3 Answers
3
active
oldest
votes
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 MATCHINGman bash/EXPANSION/Pathname Expansion- Bash Hackers Wiki: Pathname expansion (globbing)
- TLDP Advanced Bash-Scripting Guide: Chapter 18.2. Globbing
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 thefindcommand line. :)
– dessert
Apr 15 at 17:26
add a comment
|
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 +
add a comment
|
Try this for finding files and zip them in separate files :
find . -name Run2.csv -print | zip Run2.zip -@
This fails if any of the file or directory names contain whitespaces, you could use… -print0 | xargs -0 zip Run2.zipinstead.
– dessert
Apr 15 at 11:19
add a comment
|
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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 MATCHINGman bash/EXPANSION/Pathname Expansion- Bash Hackers Wiki: Pathname expansion (globbing)
- TLDP Advanced Bash-Scripting Guide: Chapter 18.2. Globbing
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 thefindcommand line. :)
– dessert
Apr 15 at 17:26
add a comment
|
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 MATCHINGman bash/EXPANSION/Pathname Expansion- Bash Hackers Wiki: Pathname expansion (globbing)
- TLDP Advanced Bash-Scripting Guide: Chapter 18.2. Globbing
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 thefindcommand line. :)
– dessert
Apr 15 at 17:26
add a comment
|
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 MATCHINGman bash/EXPANSION/Pathname Expansion- Bash Hackers Wiki: Pathname expansion (globbing)
- TLDP Advanced Bash-Scripting Guide: Chapter 18.2. Globbing
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 MATCHINGman bash/EXPANSION/Pathname Expansion- Bash Hackers Wiki: Pathname expansion (globbing)
- TLDP Advanced Bash-Scripting Guide: Chapter 18.2. Globbing
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 thefindcommand line. :)
– dessert
Apr 15 at 17:26
add a comment
|
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 thefindcommand 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
add a comment
|
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 +
add a comment
|
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 +
add a comment
|
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 +
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 +
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
add a comment
|
add a comment
|
Try this for finding files and zip them in separate files :
find . -name Run2.csv -print | zip Run2.zip -@
This fails if any of the file or directory names contain whitespaces, you could use… -print0 | xargs -0 zip Run2.zipinstead.
– dessert
Apr 15 at 11:19
add a comment
|
Try this for finding files and zip them in separate files :
find . -name Run2.csv -print | zip Run2.zip -@
This fails if any of the file or directory names contain whitespaces, you could use… -print0 | xargs -0 zip Run2.zipinstead.
– dessert
Apr 15 at 11:19
add a comment
|
Try this for finding files and zip them in separate files :
find . -name Run2.csv -print | zip Run2.zip -@
Try this for finding files and zip them in separate files :
find . -name Run2.csv -print | zip Run2.zip -@
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.zipinstead.
– dessert
Apr 15 at 11:19
add a comment
|
This fails if any of the file or directory names contain whitespaces, you could use… -print0 | xargs -0 zip Run2.zipinstead.
– 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
add a comment
|
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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