Zipping and Unzipping Files Linux

Learn how to zip and unzip files in Unix alike operating systems|

1 min read

Linux has a Zip and Unzip program, which allows you to compress or decompress files, however most distributions does not come with it installed by default. You can install this programs with the Shell prompt. Open Application > System Tools > Terminal.

Type the following command to install on Debian based operating systems like, Ubuntu, Mint and so on:

apt-get install zip
apt-get install unzip

or

sudo apt-get install zip unzip

If you are on RedHat based operating systems like CentOS:

yum install zip
yum install unzip

Zipping files and directories

This will create a file called data.zip and will add all files to the compressed archive:

zip data *

Note: No need to add .zip extension or suffix as it is added automatically by zip command.

To zip the entire directory and files, that includes subdirectories as well type the following:

zip -r data *

Unzipping files and directories

To extract all files from data.zip you can do the following:

unzip  data.zip

To extract a single file called test.txt from data.zip you can do:

unzip data.zip  test.txt

To extract all files into the /opt directory simply do:

unzip data.zip  -d /opt

To list all files from data.zip:

unzip -l data.zip