Saturday, 22 February 2014

How-to: Zip and Unzip Files under Linux

Windows has any number of programs such as Winzip, and in-built features - 'compressed folders'  - for handling 'zipped' or compressed archive files; anything ending in .zip.

Where various Linux distributions may come with Squeeze or File Roller, the zip format is not native to Linux and you will also need the compression routines to handle such files. Fortunately, Linux has both zip and unzip programs.

Zip is a compression and file packaging utility for Linux and Unix (including FreeBSD, Solaris etc). Unzip will list, test, or extract files from a ZIP archive files.

By default, these utilities are not usually installed, but you can install zip/unzip tools from your package manager or the shell prompt.

Open the Terminal by selecting Application > System Tools > Terminal. You must be a root user, which nneds a termianl session running as su or commanded prefixed sudo.

The command to install the zip and unzip programs on Debian or Ubuntu Linux:
# apt-get install zip unzip
$ sudo apt-get install zip unzip

If you are Red Hat Linux/Fedora/CentOS Linux user then you can use the yum command to install zip and unzip programs:
# yum install zip
# yum install unzip

Zipping files/directories examples
To create the archive and put all the files in the current directory in it in compressed form:
$ zip data * 

There's no need to add the .zip extension or suffix as it is added automatically by the zip command.

To zip up an entire directory (including all subdirectories):
$ zip -r data *

Unzipping files/directories examples
To use unzip to extract all files of the archive into the current directory and subdirectories:
$ unzip

You can also test, displaying only a summary message indicating whether the archive is OK or not:
$ unzip -tq

To extract the file called cv.doc from
$ unzip cv.doc

To extract all files into the /tmp directory:
$ unzip -d /tmp

To list all files from
$ unzip -l

Once installed, you may find Squeeze and File Roller ('Archive Manager') magically able to handle zip files. Which is nice. RC

Image credit: Plastic-_and_Nylonzipper By Rabensteiner - Bearbeitet von Rainer Z (Own work) [Public domain], via Wikimedia Commons

No comments:

Post a Comment

At least try to be nice, it won't kill you...