Creating zip folder in linux

How to Zip Files and Folders in Linux

This quick tip shows you how to create a zip folder in Ubuntu and other Linux distributions. Both terminal and GUI methods have been discussed.

Zip is one of the most popular archive file format out there. With zip, you can compress multiple files into one file. This not only saves disk space, it also saves network bandwidth. This is why you’ll encounter zip files almost all the time. As a normal user, mostly you’ll unzip files in Linux. But how do you zip a folder in Linux? This article helps you answer that question. Prerequisite: Verify if zip is installed Normally zip support is installed but no harm in verifying. Open a terminal and use the following command:

If you see some details on the zip version, you have zip installed already. If it displays ‘zip command not found’, you can run the below command to install zip and unzip support in Ubuntu and Debian based distributions.

sudo apt install zip unzip

Now that you know your system has zip support, you can read on to learn how to zip a directory in Linux.

Zip a folder in Linux Command Line

zip [option] output_file_name input1 input2

While there could be several options, I don’t want you to confuse with them. If your only aim is to create a zip folder from a bunch of files and directories, use the command like this:

zip -r output_file.zip file1 folder1
zip -r myzip abhi-1.txt abhi-2.txt sample_directory adding: abhi-1.txt (stored 0%) adding: abhi-2.txt (stored 0%) adding: sample_directory/ (stored 0%) adding: sample_directory/newfile.txt (stored 0%) adding: sample_directory/agatha.txt (deflated 41%)

You can use the -e option to create a password protect zip folder in Linux. You are not always restricted to the terminal for creating zip archive files. You can do that graphically as well. Here’s how!

Zip a folder in Linux Using GUI

Though I have used Ubuntu here, the method should be the same in other distributions using GNOME or other desktop environments.

If you want to compress a file or folder in desktop Linux, it’s just a matter of a few clicks. Go to the folder where you have the desired files (and folders) you want to compress into one zip folder. Here, select the files and folders. Now, right-click and select Compress. You can do the same for a single file as well. Creating zip file in UbuntuNow you can create a compressed archive file in zip , tar xz or 7z format. In case you are wondering, all three are various compression algorithms that you can use for compressing your files. Give it the name you desire and click on Create. Compress a zip folder in UbuntuIt shouldn’t take long and you should see an archive file in the same directory. Zip file created in Ubuntu LinuxWell, that’s it. You successfully created a zip folder in Linux. The next step is to learn to unzip a zipped file in the Linux command line. I hope this quick little tip helped you with the zip files. Please feel free to share your suggestions.

Читайте также:  Network speed testing linux

Источник

Создаем zip-архивы в командной строке

Рассмотрим, как создавать и распаковывать zip архивы из командной строки.

Для создания архивов служит команда zip. У нее есть более 30 разных опций, но я рассмотрю простейшие примеры.

Создаем простой zip-архив

Для создания zip-архива просто выполняем команду zip, в первом аргументе указываем имя будущего архива, а во втором сам файл, который мы сжимаем:

Если нужно сжать несколько файлов то перечисляем их через пробел:

zip myarchive.zip myfile.txt yourfile.txt theirfile.txt

Создаем zip-архив папки

Чтобы заархивировать папку, используется ключ -r:

zip -r mydir.zip verygooddir

Создаем zip-архив с паролем

Очень важной функцией утилиты zip является возможность задания пароля на распаковку архива. Для этого применяется опция -P, после которой следует написать пароль:

zip -P мойпароль -r mysecretdir.zip mysecretdir

Если вы не хотите вводить пароль в командной строке у всех на виду, то можно использовать опцию -e, чтобы вместо ввода пароля в открытую, вводить его в срытом виде:

zip -er mysecretdir.zip mysecretdir

После выполнения данной команды, вам будет предложено дважды ввести пароль. Сам пароль виден при этом не будет:

Enter password: Verify password:

Распаковка zip-архива

Для того, чтобы разархивировать zip-архив, используется команда unzip. Ее можно запускать без опций, только указывая имя архива:

По умолчанию распаковка происходит в текущей директории. Чтобы распаковать архив в другую директорию, используется опция -d, после которой нужно указать путь до директории:

Источник

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
Читайте также:  Linux изменить размер окна

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.

Читайте также:  Флеш плеер astra linux

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.

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