简体   繁体   中英

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

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 :-)]

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.

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM