8 Examples For Linux Zip And UnZip Command

May 18, 2011 | By
| Reply More
Linux zip command

The 'zip and unzip' command is one of the programs used in Linux to create compressed files. However, these utilities are not installed by default. You can install both these utilities from the shell prompt but you must be a root user to do so. Using the 'yum' command you can install zip and unzip commands.

#yum install zip
#yum install unzip

1.Zip is a compression and file packaging utility for Linux and Unix
2.Unzip will list, test, or extract files from ZIP archive files.

The zip and unzip programs work exactly in the same way as PKZIP and PKUNZIP in the DOS environment. Compressed files use less disk space than normal files and they transfer faster than larger uncompressed files. In Linux, you can compress files with the help of Gzip or Zip.

If you exchange files with non-Linux users then you can use zip to avoid compatibility problems. Red Hat Linux can easily open zip or gzip files, but non-Linux operating systems may have problems with gzip files.

Following zip command shows how to compress a file with zip

The command given below creates a file "backupfile.zip" which contains a copy of the files named  file1, file2, and file3, located in the current directory.

#zip backupfile file1 file2 file3

The command given below will compress current directory and also all subdirectories:

#zip -r backupfile .

The command written below will create a file called "backupfile.zip" which contains all files in the current directory.File names that start with a "." are not included. Compressed file extension '.zip' will be added to the end of the file name automatically.

#zip backupfile *

The command given below will compress the directory "mydata" into the file name "backupfile.zip":

#zip -r backupfile mydata

You can also try "-9" option for best compression as shown below:

#zip -9 -r backupfile mydata

The command given will compress the directory "/home/linux/data" in the file name "backupfile.zip". This .zip file will be created in the current directory.

#zip -r backupfile /home/linux/data

To extract the files you can use the unzip command given below. This will extract all files from backupfile.zip file to the current directory.

#unzip backupfile.zip

To list all the files inside the .zip file you can try the "-l" option given below:

#unzip -l filename.zip


Tagged With : ,

Free Linux Ebook to Download

Leave a Reply

All comments are subject to moderation.