linux how to add a file to a specific folder within a zip file
If you need to add the file to the same folder as in the original directory hierarchy, then you just need to add the full path to it:
zip -g xxx.zip folder/file
Otherwise, probably the easiest way to do that is to create the same layout you need in the zip file in a temporary directory.
How do I unzip a specific folder within a zipped file, and exclude some specific folder within it?
The exclude option works!
We just need to provide a path to the files to be excluded!
unzip main.zip "main_folder/folder2/*" -x "main_folder/folder2/*.git/*" -d path/to/some/directory
Create a dedicated folder for every zip files in a directory and extract zip files
"extract here" is merely a feature of whatever unzip
wrapper you are using. unzip
will only extract what actually is in the archive. There is probably no simpler way than a shell script. But sed
, awk
etc. are not needed for this if you have a POSIX-compliant shell:
for f in *.zip; do unzip -d "${f%*.zip}" "$f"; done
(You MUST NOT escape the *
or pathname expansion will not take place.) Be aware that if the ZIP archive contains a directory, such as with Eclipse archives (which always contain eclipse/
), you would end up with ./eclipse*/eclipse/eclipse.ini
in any case. Add echo
before unzip
for a dry run.
Loop through directory and zip specific folder without parent path
You can cd to another directory while running tar
using the --cd
option.
#!/bin/bash
for dir in MyPersonalFolder/*/*/WhatIWantFolder; do
parent="${dir%/*/*}"
subdir="${dir#*/*/*}"
outfile="backup-theme/${subdir/\//-}.tar.gz"
tar --cd "$parent" -cvzf "$outfile" "$subdir"
done
The directory structure of the tar file would look something like this:
tar -tf backup-theme/0001-WhatIWantFolder.tar.gz
0001/WhatIWantFolder/
0001/WhatIWantFolder/f1
Related Topics
What Does Two Dots Before a Slash Mean? (../)
Linux /Bin/Sh Check If String Contains X
How to Avoid the Prompts While Using Azcopy on Linux in a Script
How to Import Environment Settings into My Perl Program
What Really Is the "Linger Time" That Can Be Set with So_Linger on Sockets
Linux Kernel Headers' Organization
Best Approach to Detecting a Move or Rename to a File in Linux
Awk: Words Frequency from One Text File, How to Ouput into Myfile.Txt
Capturing Display/Monitor Images, Sending Keyboard Input on Linux
How to Produce Stand Alone Haskell Executable
Extract Text Between Two Strings Repeatedly Using Sed or Awk
C Calling Conventions and Passed Arguments
Simulating a Spinner for Progress in Bash
Explanation of Memcpy Memmove Glibc_2.14/2.2.5