How to zip files with same name but different extension?Terminal command to add a directory to many existing zip filesFind files with same name but different content?zip a directory that name start with `-`How can I ignore “zip warning: name not matched” when using zip command with -d option?ZIP files with size limitHow to move files to files with same name, but different extensionHow to zip multiple directories into individual zip filesHow to handle Extraction of two zip files in same folder which contain files with same nameUnzip gz archives with zip extensionbash - Find All Files with Same Name Regardless of ExtensionNested Zip files
How dangerous is XSS
Can compressed videos be decoded back to their uncompresed original format?
Knowledge-based authentication using Domain-driven Design in C#
How can I deal with my CEO asking me to hire someone with a higher salary than me, a co-founder?
Why didn't Boeing produce its own regional jet?
Rotate ASCII Art by 45 Degrees
In Bayesian inference, why are some terms dropped from the posterior predictive?
Convert seconds to minutes
How can a day be of 24 hours?
Why is it a bad idea to hire a hitman to eliminate most corrupt politicians?
Sums of two squares in arithmetic progressions
What is a Samsaran Word™?
Standard deduction V. mortgage interest deduction - is it basically only for the rich?
Different meanings of こわい
What is required to make GPS signals available indoors?
What do you call someone who asks many questions?
Could the museum Saturn V's be refitted for one more flight?
How to prevent "they're falling in love" trope
How can saying a song's name be a copyright violation?
How to travel to Japan while expressing milk?
What is an equivalently powerful replacement spell for Yuan-Ti's Suggestion spell?
Processor speed limited at 0.4 Ghz
Did 'Cinema Songs' exist during Hiranyakshipu's time?
Is this draw by repetition?
How to zip files with same name but different extension?
Terminal command to add a directory to many existing zip filesFind files with same name but different content?zip a directory that name start with `-`How can I ignore “zip warning: name not matched” when using zip command with -d option?ZIP files with size limitHow to move files to files with same name, but different extensionHow to zip multiple directories into individual zip filesHow to handle Extraction of two zip files in same folder which contain files with same nameUnzip gz archives with zip extensionbash - Find All Files with Same Name Regardless of ExtensionNested Zip files
I have a large directory with files like this:
file1.txt
file1.meta
file1.csv
file2.txt
file2.meta
file2.csv
file2.abc
and I would like to create zip files like:
file1.zip
file2.zip
I have tried
ls -1 ~/TEMP | sed 's/.[a-z]*//g' | uniq | awk 'print $NF' | xargs -i zip .zip ~/TEMP/.*
But that just gives an error message that the file cannot be fund. The problem is with the wildcard * I guess.
zip error: Nothing to do! (file1.zip)
zip warning: name not matched: /home/user/TEMP/file.*
bash zip
|
show 2 more comments
I have a large directory with files like this:
file1.txt
file1.meta
file1.csv
file2.txt
file2.meta
file2.csv
file2.abc
and I would like to create zip files like:
file1.zip
file2.zip
I have tried
ls -1 ~/TEMP | sed 's/.[a-z]*//g' | uniq | awk 'print $NF' | xargs -i zip .zip ~/TEMP/.*
But that just gives an error message that the file cannot be fund. The problem is with the wildcard * I guess.
zip error: Nothing to do! (file1.zip)
zip warning: name not matched: /home/user/TEMP/file.*
bash zip
@Theophrastus The folder has ~ 200000 files with different basenames, 'file' was just an example. I tried to get the unique basenames withsed 's/.[a-z]*//g' | uniq
.
– Michael
Jan 15 '18 at 5:10
have you tried this.zip file1.zip file1.*
&zip file2.zip file2.*
– Mongrel
Jan 15 '18 at 5:11
4
for Q in *;do H=$Q%%.*;zip "$H.zip" "$Q";done
– Theophrastus
Jan 15 '18 at 5:27
In what directory are the files to be zipped located? I see anls
of the current working directory and an argument to zip of the~/TEMP
directory.
– Mark Plotnick
Jan 15 '18 at 5:33
@Theophrastus Brilliant.H=$Q%%.*
is neat.
– Michael
Jan 15 '18 at 5:33
|
show 2 more comments
I have a large directory with files like this:
file1.txt
file1.meta
file1.csv
file2.txt
file2.meta
file2.csv
file2.abc
and I would like to create zip files like:
file1.zip
file2.zip
I have tried
ls -1 ~/TEMP | sed 's/.[a-z]*//g' | uniq | awk 'print $NF' | xargs -i zip .zip ~/TEMP/.*
But that just gives an error message that the file cannot be fund. The problem is with the wildcard * I guess.
zip error: Nothing to do! (file1.zip)
zip warning: name not matched: /home/user/TEMP/file.*
bash zip
I have a large directory with files like this:
file1.txt
file1.meta
file1.csv
file2.txt
file2.meta
file2.csv
file2.abc
and I would like to create zip files like:
file1.zip
file2.zip
I have tried
ls -1 ~/TEMP | sed 's/.[a-z]*//g' | uniq | awk 'print $NF' | xargs -i zip .zip ~/TEMP/.*
But that just gives an error message that the file cannot be fund. The problem is with the wildcard * I guess.
zip error: Nothing to do! (file1.zip)
zip warning: name not matched: /home/user/TEMP/file.*
bash zip
bash zip
edited Jan 15 '18 at 5:35
Michael
asked Jan 15 '18 at 4:44
MichaelMichael
1063
1063
@Theophrastus The folder has ~ 200000 files with different basenames, 'file' was just an example. I tried to get the unique basenames withsed 's/.[a-z]*//g' | uniq
.
– Michael
Jan 15 '18 at 5:10
have you tried this.zip file1.zip file1.*
&zip file2.zip file2.*
– Mongrel
Jan 15 '18 at 5:11
4
for Q in *;do H=$Q%%.*;zip "$H.zip" "$Q";done
– Theophrastus
Jan 15 '18 at 5:27
In what directory are the files to be zipped located? I see anls
of the current working directory and an argument to zip of the~/TEMP
directory.
– Mark Plotnick
Jan 15 '18 at 5:33
@Theophrastus Brilliant.H=$Q%%.*
is neat.
– Michael
Jan 15 '18 at 5:33
|
show 2 more comments
@Theophrastus The folder has ~ 200000 files with different basenames, 'file' was just an example. I tried to get the unique basenames withsed 's/.[a-z]*//g' | uniq
.
– Michael
Jan 15 '18 at 5:10
have you tried this.zip file1.zip file1.*
&zip file2.zip file2.*
– Mongrel
Jan 15 '18 at 5:11
4
for Q in *;do H=$Q%%.*;zip "$H.zip" "$Q";done
– Theophrastus
Jan 15 '18 at 5:27
In what directory are the files to be zipped located? I see anls
of the current working directory and an argument to zip of the~/TEMP
directory.
– Mark Plotnick
Jan 15 '18 at 5:33
@Theophrastus Brilliant.H=$Q%%.*
is neat.
– Michael
Jan 15 '18 at 5:33
@Theophrastus The folder has ~ 200000 files with different basenames, 'file' was just an example. I tried to get the unique basenames with
sed 's/.[a-z]*//g' | uniq
.– Michael
Jan 15 '18 at 5:10
@Theophrastus The folder has ~ 200000 files with different basenames, 'file' was just an example. I tried to get the unique basenames with
sed 's/.[a-z]*//g' | uniq
.– Michael
Jan 15 '18 at 5:10
have you tried this.
zip file1.zip file1.*
& zip file2.zip file2.*
– Mongrel
Jan 15 '18 at 5:11
have you tried this.
zip file1.zip file1.*
& zip file2.zip file2.*
– Mongrel
Jan 15 '18 at 5:11
4
4
for Q in *;do H=$Q%%.*;zip "$H.zip" "$Q";done
– Theophrastus
Jan 15 '18 at 5:27
for Q in *;do H=$Q%%.*;zip "$H.zip" "$Q";done
– Theophrastus
Jan 15 '18 at 5:27
In what directory are the files to be zipped located? I see an
ls
of the current working directory and an argument to zip of the ~/TEMP
directory.– Mark Plotnick
Jan 15 '18 at 5:33
In what directory are the files to be zipped located? I see an
ls
of the current working directory and an argument to zip of the ~/TEMP
directory.– Mark Plotnick
Jan 15 '18 at 5:33
@Theophrastus Brilliant.
H=$Q%%.*
is neat.– Michael
Jan 15 '18 at 5:33
@Theophrastus Brilliant.
H=$Q%%.*
is neat.– Michael
Jan 15 '18 at 5:33
|
show 2 more comments
2 Answers
2
active
oldest
votes
One way, in bash (since you tagged it):
Gather the list of filename prefixes into an associative array:
declare -A prefixes
for f in *; do prefixes[$f%%.*]=1; doneLoop through the prefixes and create the zip files:
for p in "$!prefixes[@]"; do zip "$p" "$p".*; done
add a comment |
Spinning off from Jeff's idea, but not using a list:
for fname in *.*; do
prefix=$fname%.*
[ ! -f "$fname" ] || [ -f "$prefix.zip" ] && continue
zip "$prefix" "$prefix".*
done
This loop over all names in the current directory that contains at least one dot character.
The body of the loop extracts the filename prefix by removing the bit after the last dot in the current filename (use %%
in place of %
to remove from the first dot). It then tests whether the name was actually the name of a regular file (or a symbolic link to one) and whether the corresponding Zip archive for that file already exists or not.
If the file is a regular file (or symlink to one), and if the archive file does not exist, zip
is invoked to create the archive.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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
);
);
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%2funix.stackexchange.com%2fquestions%2f417163%2fhow-to-zip-files-with-same-name-but-different-extension%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
One way, in bash (since you tagged it):
Gather the list of filename prefixes into an associative array:
declare -A prefixes
for f in *; do prefixes[$f%%.*]=1; doneLoop through the prefixes and create the zip files:
for p in "$!prefixes[@]"; do zip "$p" "$p".*; done
add a comment |
One way, in bash (since you tagged it):
Gather the list of filename prefixes into an associative array:
declare -A prefixes
for f in *; do prefixes[$f%%.*]=1; doneLoop through the prefixes and create the zip files:
for p in "$!prefixes[@]"; do zip "$p" "$p".*; done
add a comment |
One way, in bash (since you tagged it):
Gather the list of filename prefixes into an associative array:
declare -A prefixes
for f in *; do prefixes[$f%%.*]=1; doneLoop through the prefixes and create the zip files:
for p in "$!prefixes[@]"; do zip "$p" "$p".*; done
One way, in bash (since you tagged it):
Gather the list of filename prefixes into an associative array:
declare -A prefixes
for f in *; do prefixes[$f%%.*]=1; doneLoop through the prefixes and create the zip files:
for p in "$!prefixes[@]"; do zip "$p" "$p".*; done
answered Jan 20 '18 at 1:43
Jeff Schaller♦Jeff Schaller
44.5k1162143
44.5k1162143
add a comment |
add a comment |
Spinning off from Jeff's idea, but not using a list:
for fname in *.*; do
prefix=$fname%.*
[ ! -f "$fname" ] || [ -f "$prefix.zip" ] && continue
zip "$prefix" "$prefix".*
done
This loop over all names in the current directory that contains at least one dot character.
The body of the loop extracts the filename prefix by removing the bit after the last dot in the current filename (use %%
in place of %
to remove from the first dot). It then tests whether the name was actually the name of a regular file (or a symbolic link to one) and whether the corresponding Zip archive for that file already exists or not.
If the file is a regular file (or symlink to one), and if the archive file does not exist, zip
is invoked to create the archive.
add a comment |
Spinning off from Jeff's idea, but not using a list:
for fname in *.*; do
prefix=$fname%.*
[ ! -f "$fname" ] || [ -f "$prefix.zip" ] && continue
zip "$prefix" "$prefix".*
done
This loop over all names in the current directory that contains at least one dot character.
The body of the loop extracts the filename prefix by removing the bit after the last dot in the current filename (use %%
in place of %
to remove from the first dot). It then tests whether the name was actually the name of a regular file (or a symbolic link to one) and whether the corresponding Zip archive for that file already exists or not.
If the file is a regular file (or symlink to one), and if the archive file does not exist, zip
is invoked to create the archive.
add a comment |
Spinning off from Jeff's idea, but not using a list:
for fname in *.*; do
prefix=$fname%.*
[ ! -f "$fname" ] || [ -f "$prefix.zip" ] && continue
zip "$prefix" "$prefix".*
done
This loop over all names in the current directory that contains at least one dot character.
The body of the loop extracts the filename prefix by removing the bit after the last dot in the current filename (use %%
in place of %
to remove from the first dot). It then tests whether the name was actually the name of a regular file (or a symbolic link to one) and whether the corresponding Zip archive for that file already exists or not.
If the file is a regular file (or symlink to one), and if the archive file does not exist, zip
is invoked to create the archive.
Spinning off from Jeff's idea, but not using a list:
for fname in *.*; do
prefix=$fname%.*
[ ! -f "$fname" ] || [ -f "$prefix.zip" ] && continue
zip "$prefix" "$prefix".*
done
This loop over all names in the current directory that contains at least one dot character.
The body of the loop extracts the filename prefix by removing the bit after the last dot in the current filename (use %%
in place of %
to remove from the first dot). It then tests whether the name was actually the name of a regular file (or a symbolic link to one) and whether the corresponding Zip archive for that file already exists or not.
If the file is a regular file (or symlink to one), and if the archive file does not exist, zip
is invoked to create the archive.
answered 2 days ago
Kusalananda♦Kusalananda
139k17259430
139k17259430
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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%2funix.stackexchange.com%2fquestions%2f417163%2fhow-to-zip-files-with-same-name-but-different-extension%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
@Theophrastus The folder has ~ 200000 files with different basenames, 'file' was just an example. I tried to get the unique basenames with
sed 's/.[a-z]*//g' | uniq
.– Michael
Jan 15 '18 at 5:10
have you tried this.
zip file1.zip file1.*
&zip file2.zip file2.*
– Mongrel
Jan 15 '18 at 5:11
4
for Q in *;do H=$Q%%.*;zip "$H.zip" "$Q";done
– Theophrastus
Jan 15 '18 at 5:27
In what directory are the files to be zipped located? I see an
ls
of the current working directory and an argument to zip of the~/TEMP
directory.– Mark Plotnick
Jan 15 '18 at 5:33
@Theophrastus Brilliant.
H=$Q%%.*
is neat.– Michael
Jan 15 '18 at 5:33