Dan
Dan

Reputation: 635

How do I make a zip file on linux?

zip -h is confusing! I just want to know how to make a .zip from a directory. kthxbi

Upvotes: 37

Views: 71510

Answers (6)

user19315471
user19315471

Reputation: 600

Python is installed almost everywhere, so:

# create archive
python -m zipfile -c my.zip target_file_or_dir

# extract from archive
python -m zipfile -e my.zip target-dir/

Check docs

Upvotes: 1

Scott Stensland
Scott Stensland

Reputation: 28285

On linux, although it can zip you really should instead be using :

to compress

tar -jcvf archive_name.tar /path/to/directory_to_compress

where archive_name.tar will be the the compressed version of the input dir /path/to/directory_to_compress

to decompress

tar -xvf archive_name.tar

tar is available on Windows 10 you can install it from https://www.libarchive.org/downloads/ which will give you bsdtar.exe which I just used to successfully decompress a xxx.tar file created on linux

tar on windows https://devblogs.microsoft.com/commandline/tar-and-curl-come-to-windows/

Upvotes: 3

Assy
Assy

Reputation: 191

This should be quite easy and short
compressing

tar -zcvf filename.tar myflie.sql

Decompressing

tar -xvzf filename  

For more interested in knowing usage options

z - filter achieving through gzip
j - filter achieve through bzip2
c - create achieve file
v - show the progress
x - extract achieve file
f - file name

cheers

Upvotes: 4

Akash Kandpal
Akash Kandpal

Reputation: 3366

Typically one uses tar to create an uncompressed archive and either gzip or bzip2 to compress that archive. The corresponding gunzip and bunzip2 commands can be used to uncompress said archive, or you can just use flags on the tar command to perform the uncompression.

If you are referring specifically to the Zip file format, you can simply use the zip and unzip commands.

To compress:

zip squash.zip file1 file2 file3

or to zip a directory

zip -r squash.zip dir1

To uncompress:

unzip squash.zip

this unzips it in your current working directory.

Source :: here

Upvotes: 3

Hastur
Hastur

Reputation: 2818

zip -r archive.zip dir_to_zip

from man zip

-r  
   --recurse-paths
          Travel the directory structure recursively; for example:

                 zip -r foo.zip foo

          or more concisely

                 zip -r foo foo

In  this  case, all  the  files and directories in foo are saved in a zip archive
named foo.zip,including files with names starting with ".", since  the  recursion
does not use the shell's file-name substitution mechanism...

Even if it functions well I would like to propose you 7z(http://www.7-zip.org/).

  7za a directory.7z  directory

It has a better compression and it is opensource, GNU LGPL license, freely available for windows,linux,BSD...

BTW it creates/opens 7z, XZ, BZIP2, GZIP, TAR, ZIP and WIM,
and open unpack only: ARJ, CAB, CHM, CPIO, CramFS, DEB, DMG, FAT, HFS, ISO, LZH, LZMA, MBR, MSI, NSIS, NTFS, RAR, RPM, SquashFS, UDF, VHD, WIM, XAR and Z.

[They should pay me for advertisement :-)]

Upvotes: 41

RBrandao
RBrandao

Reputation: 142

I think this is gonna help you

zip -r new_zip_file directory_name

Where "new_zip_file" is the name of the .zip file you want to create and "directory_name" is the folder you want compress in zip.

Upvotes: 7

Related Questions