How to zip directory in linux

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

I am a newbie in Linux.Whats is the complete process to zip and unzip a directory and its files.Please mention if any installation has to be done.

3 Answers 3

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 

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

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

sudo apt-get install zip unzip 

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).

enter image description here

  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

  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
Читайте также:  Посмотреть логи сервера linux

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.

Источник

How to zip a folder in Ubuntu Linux / Debian Linux

How to zip a folder in Ubuntu Linux / Debian Linux - TechvBlogs

This quick blog shows you how to Zip (compress) files and directories in Linux using the zip command.

Suresh Ramani - Author - TechvBlogs

Suresh Ramani

SSD VPS Servers, Cloud Servers and Cloud Hosting - Vultr.com

Zip is the most widely used archive file format that supports lossless data compression.

A Zip file is a data container containing one or more compressed files or directories. Compressed (zipped) files take up less disk space and can be transferred from one to another machine more quickly than uncompressed files. Zip files can be easily extracted in Windows, macOS, and Linux using the utilities available for all operating systems.

Unzip is a utility that is not available on most Linux flavors by default, but can be easily installed. By creating .zip files you can match .tar.gz file compression!

This quick blog shows you how to Zip (compress) files and directories in Linux using the zip command.

What Is Zip Used For?

Below are a few scenarios in which you may choose to use zip files:

  • When you are frequently working between Windows and Unix-based systems. Not only does this compress files but also is a file package utility. Works on multiple operating systems
  • To save bandwidth. If you have limited or restricted bandwidth, then zip can be used between two servers for file transfer
  • Transfers files quickly. Zip utility reduces file size, therefore reducing transfer time
  • Upload or download directories at a faster speed
  • Save disk space
  • Unzip password-protected .zip files
  • Enjoy a good compression ratio

Remember, before taking advantage of Unzip on Linux, you’ll have to SSH into your virtual private server.

Install Zip on Debian and Ubuntu Systems

Installing unzip is easy! With Ubuntu and Debian use the command below to install unzip:

Sit back and wait a minute, until the installation is finished.

To create zip files, you’ll also have to install zip. You can do this with the following command:

Install Unzip on Linux CentOS and Fedora

This again is simple and can be done using the below command:

Once the installation is complete you can check the path with the following command:

After you execute the direction in the command line, you should get an output that looks like this:

Читайте также:  Обновить время в линукс

You can also confirm everything is installed properly by using the command below. It will give a verbose with unzip utility details.

How to Use Zip and Unzip in Linux

Now that we know how to install the utility, we can start learning its basic uses of it:

zip Command

Zip is a command-line utility that helps you create Zip archives.

The zip command takes the following syntax form:

zip OPTIONS ARCHIVE_NAME FILES

To create a Zip archive in a specific directory, the user needs to have write permissions on that directory.

Zip files do not support Linux-style ownership information. The extracted files are owned by the user that runs the command. To preserve the file ownership and permissions, use the tar command.

The zip utility is not installed by default in most Linux distributions, but you can easily install it using your distribution package manager.

Create Zip Files in Linux

The basic syntax to create a .zip file is:

zip options zipfile list_Of_files

To test this, we created two files – ExampleFile.txt and ExampleFile1.txt. We’ll compress them into sampleZipFile.zip with the following command:

zip sampleZipFile.zip ExampleFile.txt ExampleFile1.txt

Using Linux to Unzip a file

The unzip command can be used without any options. This will unzip all files to the current directory. One such example is as shown below:

This by default will be unzipped in the current folder provided you have read-write access.

Remove a File from a .zip File

Once a .zip file is created, you can remove or delete files in it. So, if you want to remove ExampleFile.txt from the existing sampleZipFile.zip, then you can use the following command:

zip –d sampleZipFile.zip ExampleFile.txt

Once this command is executed, you can unzip the .zip file using:

Over here you will find that ExampleFile.txt has been removed and can’t be seen on extraction.

How to Update Zip Files

Once a .zip file is created, you can add a new file to an existing .zip file. Suppose a new file ExampleFile2.txt needs to be added to the already existing sampleZipFile.zip. You can do this with the command shown below:

zip –u sampleZipFile.zip ExampleFile2.txt

Now if you extract sampleZipFile.zip, you will find the new file ExampleFile2.txt added to it.

Move a File to a Zip

You can easily move specific files to a zip file. That means that after adding the files, they will be deleted from their original directories. This is mostly used when you have a large file or directory, but need to conserve disk space. This is done by adding the -m option. A sample of this command would be:

zip –m sampleZipFile.zip ExampleFile2.txt

Recursive Use of Zip on Linux

The -r option is used to recursively zip files. This option will compress all the files present within a folder. An example of such a command is shown below:

zip –r sampleZipFile.zip MyDirectory

In the example, MyDirectory is a directory that has multiple files and sub-directories to be zipped.

Читайте также:  Linux good text editor

Exclude Files in a Zip

While creating a .zip file, you can exclude unwanted files. This is done by using the -x option. Below is an example:

zip -x sampleZipFile.zip ExampleFile.txt

Here ExampleFile.txt will not be added to the sampleZipFile.zip.

Unzip to a Different Directory

In case you do not want to unzip to the current directory but want to specify a directory location, then this can also be done. Use the -d option to provide a directory path in the unzip command. An example of such a command is shown below:

unzip sampleZipFile.zip -d /usr/sampleZip/ExampleDir

Use Linux Unzip with Multiple Zip Files

If you want to unzip multiple zip files existing within your current working directory then you can use a command as shown below:

This command will unzip all the individual zip files.

Creating a Password Protected ZIP file

If you have sensitive information that needs to be stored in the archive, you can encrypt it using the -e option:

zip -e archivename.zip directory_name

Creating Split Zip File

Imagine you want to store the Zip archive on a file hosting service that has a file size upload limit of 1GB, and your Zip archive is 5GB.

You can create a new split Zip file using the -s option followed by a specified size. The multiplier can be k (kilobytes), m (megabytes), g (gigabytes), or t (terabytes).

zip -s 1g -r archivename.zip directory_nameCopy

The command above will keep creating new archives in a set after it reaches the specified size limit.

archivename.zip archivename.z01 archivename.z02 archivename.z03 archivename.z04

Thank you for reading this article.

If you want to manage your VPS / VM Server without touching the command line go and Checkout this link. ServerAvatar allows you to quickly set up WordPress or Custom PHP websites on VPS / VM in a matter of minutes. You can host multiple websites on a single VPS / VM, configure SSL certificates, and monitor the health of your server without ever touching the command line interface.

If you have any queries or doubts about this topic please feel free to contact us. We will try to reach you.

Источник

Оцените статью
Adblock
detector