Home  »  ArticlesGuidesTechnology   »   How to Zip Files in Ubuntu / Debian Linux Systems Terminal

How to Zip Files in Ubuntu / Debian Linux Systems Terminal

With Zip files being one of the most popular archive file formats, it is one of the most convenient ways to compress multiple files or directories into one file. Working with zip files in Ubuntu and Debian is quite simple.

Zipping or compressing allows the user to save disk space and network bandwidth. Zip is also a compression and file packaging utility for Linux and Unix commands. There is a companion program called unzip that is used to unpack zip archives.

Prerequisites to Zip Files in Ubuntu

Before you can create zip files in Ubuntu or Debian and subsequently unpack (unzip) the same archives you need to have the utilities installed in your system.

Run the following in the command line install zip and unzip support:

$ sudo apt install zip unzip

The syntax for using the zip command is as follows:

zip [option] output_file_name input1 [input2]

For example:

$ zip -r output.zip folder
$ zip -r output.zip file folder1 folder2
$ zip -r output.zip /path/to/folder1 /path/to/file2

Zip all files in current directory.

$ zip -r output.zip

Zip all files in the current directory and subdirectories too.

$ zip output.zip *

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.

Another important option is the -e option which password protects the output zip files. For example:

$ zip -r -e output.zip /path/to/folder/

You will then be prompted for the password.

You can also specify the password as part of the command like so:

$ zip -r -e -P 'YOUR_PASSWORD' output.zip /path/to/folder/

Note: The -P ‘YOUR_PASSWORD’ option to the zip is insecure. Many multi-user operating systems such as Linux provide ways for any user to see the current command line of any other user. Having the plaintext password as part of a command-line should always be avoided.

You can verify zip files with the ls command:

$ ls -l output.zip

Conclusion

You just learned how to compress a directory into zip files in Ubuntu or Debian Linux using the zip command.

See also  How to Disable Hyperlinks in Notepad++

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.

Share it!

Available under:
Articles, Guides, Technology