How to zip a folder in Ubuntu Linux / Debian Linux

I am a new Ubuntu Linux user. I would like to compress a folder named data in my home directory. How do I zip a folder in Ubuntu Linux? How do I compress a directory in Ubuntu Linux?

To compress archive files use zip command. The zip is a compression and file packaging utility for Linux and Unix command. A companion program called unzip unpacks zip archives. This page shows how to compress a folder on Ubuntu Linux or Debian Linux using the CLI and GUI methods.

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 to install zip unzip on Ubuntu Linux

How do I use zip command to compress a folder?

The syntax is
zip -r folder
zip -r folder1 folder2
zip -r /path/to/folder1 /path/to/file2

To create compressed archive named of data folder in the current directory, run:
zip -r data/

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

Enter password: 
Verify password: 
  adding: data/ (stored 0%)
  adding: data/music/ (stored 0%)
  adding: data/nightmare.jpg (deflated 2%)
  adding: data/resolv.conf (deflated 16%)
  adding: data/network.jpg (deflated 0%)
  adding: data/acct/ (stored 0%)
  adding: data/acct/MSR-201711.PDF (deflated 4%)
  adding: data/acct/0XL72233P04252837.pdf (deflated 32%)

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 /path/to/foldername
zip -r /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…“:

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 /path/to/folder/
We can also use and state password on the CLI to encrypt zipfile entries:
zip -r -e -P 'YOUR_PASSWORD_HERE' /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.


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 RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
1 comment… add one
  • Tommy Jul 21, 2017 @ 18:19

    worked like a charm on Ubuntu 16.04 LTS desktop and server

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum