How do I make a zip file on linux?

11,030

Solution 1

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

Solution 2

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

Solution 3

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

Solution 4

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.

Share:
11,030
Dan
Author by

Dan

Hello!

Updated on June 24, 2022

Comments

  • Dan
    Dan almost 2 years

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