Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linux how to add a file to a specific folder within a zip file

Tags:

linux

zip

i know how to add a file to the root folder within a zip file:

zip -g xxx.apk yyy.txt

but i've no idea how to specify a particular folder within a zip file

like image 477
asfman Avatar asked Feb 15 '12 07:02

asfman


People also ask

How do I add files to an existing zip file in Linux?

After creating a zip file, you can remove a file from the archive using the -d option. 2. -u Option: Updates the file in the zip archive. This option can be used to update the specified list of files or add new files to the existing zip file.

How do I add files to a folder in Linux?

You can either click the Terminal icon in the Apps menu, or press Ctrl + Alt + T at the same time to open the Terminal. Navigate to the directory you want to create a file in. To do so, type cd followed by the path to the directory you want to create a file in and press Enter..


2 Answers

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.

like image 185
jcollado Avatar answered Sep 21 '22 09:09

jcollado


To elaborate on @Ignacio Vazquez-Abrams answer from a year ago, you can use a lower level library, such as the one that comes with Python:

#!/bin/bash python -c ' import zipfile as zf, sys z=zf.ZipFile(sys.argv[1], "a") z.write(sys.argv[2], sys.argv[3]) z.close() ' myfile.zip source/dir/file.txt dir/in/zip/file.txt 

This will open myfile.zip and add source/dir/file.txt from the file system as dir/in/zip/file.txt in the zip file.

like image 21
that other guy Avatar answered Sep 19 '22 09:09

that other guy