How to Zip and Unzip a directory and its files in Linux [duplicate]

Solution 1:

You say you are a newbie. Maybe you got Windows-experiences. If you do not have the packages installed yet, you need to

sudo apt-get install zip gzip tar

first (or by a graphical pkg-manager).

Then, for an entry it would be the easiest way to use zip/unzip:

zip -r my_arch.zip my_folder

where -r means "recursive".

To unzip you simply use

unzip my_arch.zip

Zip stores relative path names by default. There are several parameter-options available for zip. For that read: the manual (man zip). For a starting this will do.

Most often you will see .tar.gz endings in linux-world. That's the product of two tools: TAR (the tape archiver) and GZIP (the GNU-Zip). Tar has got the call option to automatically gzip/gunzip files after "taring".

tar -cvzf may_arch.tar.gz my_folder

where

  • -c means "create"
  • -v means "verbose" (sometimes bothersome and slowing down...)
  • -z means "use (GNU)zip"
  • -f XYZ declares the name of the output file. (You should chose a helping name like XYZ.tar.gz)

There may also be .tar.bz2 endings. This is the product of the -j parameter instead of the -z parameter: you will choose compression with BZIP2 (-> man bzip2).

To extract you simply use -x (eXtract) instead of -c (Create):

tar -xvzf may_arch.tar.gz

Happy "zipping"!

Solution 2:

You can use the zip and unzip command line utilities. These can be installed by running

sudo apt-get install zip unzip

in the terminal.

Solution 3:

I know several ways, but since you're new on linux. So I'll tell you how to zip a file using GUI method (the easiest way).

  1. Create a new folder and fill it with anything you want, for example many of file (In my case, I'll fill it with theme folder) : enter image description here

enter image description here

  1. Right click the folder you want to zip and select "Compress..." option : enter image description here

  2. You can choose which file format you want by clicking combobox next to "Filename" textbox. Also you can set the folder you want to zip location. enter image description here

Clicking "Other options" will lead you to password section, in other word you can set password for your preferred file so someone (include you) have to enter password before unzip the file. enter image description here

  1. Click create if done