Tuesday, August 7, 2012

How to zip an Entire Folder in Linux?

Linux uses a program named tar to archive data, which can then be compressed with a compression program like gzip, bzip2, 7zip, etc.

So, in order to "zip" an entire folder, the command is:
tar -zcvf archive.tar.gz folder-name/ 
This will tell tar to c (create) an archive from the files in the folder (tar is recursive by default), compress it using the z (gzip) algorithm, store the output as a f (file) named archive.tar.gz, and v (verbosely) list all the files it adds to the archive.

On another way around, to decompress and unpack the archive into the current directory:
tar -zxvf archive.tar.gz