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;
}
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
New contributor
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
New contributor
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
New contributor
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
New contributor
New contributor
New contributor
asked yesterday
NasserNasser
1163
1163
New contributor
New contributor
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 MATCHING
man 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
yesterday
1
@D.BenKnoble yes, but I left that to Romeo Ninov for his answer and helped him build thefind
command line. :)
– dessert
yesterday
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.zip
instead.
– dessert
yesterday
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/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.
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 MATCHING
man 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
yesterday
1
@D.BenKnoble yes, but I left that to Romeo Ninov for his answer and helped him build thefind
command line. :)
– dessert
yesterday
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 MATCHING
man 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
yesterday
1
@D.BenKnoble yes, but I left that to Romeo Ninov for his answer and helped him build thefind
command line. :)
– dessert
yesterday
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 MATCHING
man 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 MATCHING
man bash
/EXPANSION/Pathname Expansion- Bash Hackers Wiki: Pathname expansion (globbing)
- TLDP Advanced Bash-Scripting Guide: Chapter 18.2. Globbing
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 thefind
command line. :)
– dessert
yesterday
add a comment |
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 thefind
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
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 yesterday
dessert
25.6k674108
25.6k674108
answered yesterday
Romeo NinovRomeo Ninov
59519
59519
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.zip
instead.
– dessert
yesterday
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.zip
instead.
– dessert
yesterday
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 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
add a comment |
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
add a comment |
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.
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.
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