How to zip directory linux

How to Zip Files and Folders in Linux [Beginner Tip]

Last updated October 9, 2019 By Abhishek Prakash 30 Comments

Brief: 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. You can run the below command to install zip and unzip support. If it’s not installed already, it will be installed now.

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

The syntax for using the zip command is pretty straight forward.

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:

The -r option will recurse into directories and compress its contents as well. The .zip extension in the output files is optional as .zip is added by default.

You should see the files being added to the compressed folder during the zip operation.

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 Ubuntu Linux Using GUI

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

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.

In here, select the files and folders. Now, right click and select Compress. You can do the same for a single file as well.

Читайте также:  Автоотключение подсветки клавиатуры windows 10

Now you can create a compressed archive file in zip, tar xz or 7z format. In case you are wondering, all these three are various compression algorithms that you can use for compressing your files.

Give it the name you desire and click on Create.

It shouldn’t take long and you should see an archive file in the same directory.

Well, that’s it. You successfully created a zip folder in Linux.

I hope this quick little tip helped you with the zip files. Please feel free to share your suggestions.

Like what you read? Please share it with others.

Источник

How to zip a folder in Ubuntu Linux / Debian Linux

zip a folder in Ubuntu Linux using the cli

First install the zip command using apt command or apt-get command. Open the terminal and type the following command:
$ sudo apt install zip unzip

How do I use zip command to compress a folder?

The syntax is
zip -r filename.zip folder
zip -r filename.zip folder1 folder2
zip -r filename.zip /path/to/folder1 /path/to/file2
To create compressed archive named data.zip of data folder in the current directory, run:
zip -r data.zip data/

Verify file with the ls command:
ls -l data.zip
You can encrypt data.zip with a password by passing the -e option:
zip -r -e data.zip data/
Sample outputs:

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

zip command has many more options as follows:

Option Description
-f freshen: only changed files
-u update: only changed or new files
-d delete entries in zipfile
-m move into zipfile (delete OS files)
-r recurse into directories
-j junk (don’t record) directory names
-0 store only
-l convert LF to CR LF (-ll CR LF to LF)
-1 compress faster
-9 compress better
-q quiet operation
-v verbose operation/print version info
-c add one-line comments
-z add zipfile comment
-@ read names from stdin
-o make zipfile as old as latest entry
-x exclude the following names
-i include only the following names
-F fix zipfile (-FF try harder)
-D do not add directory entries
-A adjust self-extracting exe
-J junk zipfile prefix (unzipsfx)
-T test zipfile integrity
-X eXclude eXtra file attributes
-y store symbolic links as the link instead of the referenced file
-e encrypt
-n don’t compress these suffixes
-h2 show more help

Compress a directory in Ubuntu Linux

The zip command syntax is as follows to compress a directory in Ubuntu Linux:
zip -r compressed_data.zip /path/to/foldername
zip -r compressed_data.zip /home/vivek/Jan-2018

zip a folder in Ubuntu Linux using the GUI method

To access and organize your files you use “Files” app (file manager)”. Use the Files file manager to browse and organize the files on your computer. Open it. Select folder name such as data and right click the “Compress…“:

Читайте также:  Cartoon character in windows

Gif 01: Compressing a folder in Ubuntu Linux using GUI method i.e. Files file manager

Password protecting zip file

We can encrypt and password protect our zip file as follows:
zip -r -e output.zip /path/to/folder/
We can also use and state password on the CLI to encrypt zipfile entries:
zip -r -e -P ‘YOUR_PASSWORD_HERE’ output.zip /path/to/folder/

WARNING: The -P ‘YOUR_PASSWORD_HERE’ option to the zip IS INSECURE! Avoid it. Many multi-user operating systems such as Linux provide ways for any user to see the current command line of any other user; even on stand-alone systems there is always the threat of over-the-shoulder peeking. Storing the plaintext password as part of a command line in an automated script is even worse. Whenever possible, use the non-echoing, interactive prompt to enter passwords. And where security is truly important, use strong encryption such as Pretty Good Privacy (PGP/GPG) instead of the relatively weak standard encryption provided by zipfile utilities. See “ HowTo Encrypt And Decrypt Files With A Password Using GPG on Linux and Unix-like Systems” for more info.

Conclusion

You just learned how to compress a directory in Ubuntu Linux or Debian Linux using the zip command. The same command used to zip a folder in Linux. For more info please see this page here.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Источник

How to Zip a Folder in Linux

Installing Zip Utilities on Ubuntu/Debian

First update the apt package repository cache with the following command:

The apt package repository cache should be updated.

Now install zip and unzip packages with the following command:

Zip and unzip packages should be installed. In my case, they are already installed.

Installing Zip Utilities on RHEL 7/CentOS 7

First update the yum package repository cache with the following command:

Now install the zip and unzip packages with the following command:

Now press y and then press to continue.

zip and unzip packages should be installed.

Zipping a Folder/Directory Graphically

If you have any graphical desktop environment installed on your chosen Linux distribution, then you can use it to Zip archive any folder you like very easily.

First open your favorite File Manager and go to the location where you have the folder you want to Zip archive. In my case I am using the Nautilus file manager in GNOME 3 desktop environment.

Let’s say you want to Zip archive the Downloads/ directory as marked in the screenshot below.

Now right click on the Downloads/ directory and click on Compress… as marked in the screenshot below.

Now type in a name for your Zip archive and select .zip

Once you’re done, click on Create.

A backup.zip file should be created. This is the Zip archive of the Downloads/ directory.

Читайте также:  Как почистить windows 10 от ненужных служб

Zipping a Folder/Directory using the Command Line Interface (CLI)

If you don’t have any graphical desktop environment installed on your computer, don’t worry. You can still use the command line interface (CLI) to Zip archive a folder.

First go to the location where the folder you want to zip archive is available with the following command:

NOTE: PATH is the location where your desired folder is located.

For example, if you want to Zip archive the /etc directory. So the PATH should be the root directory /.

Again, if you want to Zip archive the /etc/apt directory, then the PATH should be /etc.

Let’s Zip archive, /etc/apt directory.

The command for Zipping a folder or directory is:

NOTE: Here FOLDER is the directory that you want to Zip archive. OUTPUT is the path to a file where the Zip archive of FOLDER will be saved.

For example, run the following command to Zip archive /etc/apt directory and save it to the HOME directory of your login user as apt_backup.zip:

/ apt_backup.zip apt /
Or
$ zip -r $HOME / apt_backup.zip apt /

The /etc/apt directory or folder should be Zip archived.

It should be save to

/apt_backup.zip file as you can see from the screenshot below.

Extracting the Zip Archive Graphically

If you have a graphical desktop environment installed, then extracting the Zip archive is very easy.

Just right click on the Zip archive you want to extract and you should see the following menu. Select either Extract Here or Extract to… to unzip it.

If you want to extract the archive to your current working directory (the directory you’re in right now), then click on Extract Here. It should be extracted as you can see from the marked section of the screenshot below.

If you want to extract it to a different directory, then click on Extract to…

A directory picker should be opened as you can see in the marked section of the screenshot below.

Select a directory and click on Select.

The Zip archive should be extracted in that directory as you can see in the marked section of the screenshot below.

Extracting the Zip Archive using the Command Line Interface (CLI)

If you don’t have the graphical desktop environment installed on your Linux distribution, don’t worry. You can extract the Zip archive using the command line interface (CLI).

First navigate to the directory where you want to extract the Zip archive with the following command:

NOTE: EXTRACT_DIR is the directory where you want to extract the Zip archive.

Then run the following command to extract the Zip archive:

NOTE: Here ZIP_ARCHIVE is the path to the Zip archive that you want to extract.

For example, let’s extract the

/apt_backup.zip file to

First navigate to the

Now run the following command to extract apt_backup.zip file:

/ apt_backup.zip file should be extracted.

The extracted apt/ directory.

That’s how you Zip and Unzip a Folder or Directory in Linux. Thanks for reading this article.

Источник

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