ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Home » Linux

ZIP files on command line in Linux

Here, we are going to learn about the ZIP files command in Linux, how to ZIP/UNZIP the files on command line in Linux?
Submitted by Himanshu Bhatt, on December 24, 2018

ZIP files

The most popular archiving utility in the Microsoft world is the ZIP file. It is not as established in Linux but is well sustained by the zip and unzip commands.

Like we have discussed earlier, we can use TAR or Gzip/bzip2 for compression or decompression, another popular alternative is ZIP.

Example 1: Zipping

Let's try with archiving some files and compressing them.

Zip in Linux

Let's break the code...

We have syntax of ZIP is:

    zip ZIP_name  Filename1 filename2 ...

So the first argument is ZIP_name that is the name of ZIP we wanted to be followed by list of files, in our case, we used wild-character (*) for the list of files. Zip provides a verbose output the files and the compression ratio, unlike in Tar or gzip.

Zip will not recurse into any subdirectories by default so we need to use –r option explicitly.

Example 2

In the above example (1), we can't recurse into subdirectories by default like we saw in case if tar but with option r we can:

Zip in Linux 2

ADVERTISEMENT

In the above example, in our folder (or directory) name 'File' contain 10 .jpg files and 1 zip file and now this will let zip command to recurse through subdirectories.

In the aboveexample (2), all files under 'File' directory added because of the –r option we used.

We can list files in the zip or unzip command by using –l option (list):

Example 3: Unzipping

For extracting files from the zip, we use unzip command, it is same as creating an archive.

Syntax:

    unzip ZipName.zip

As in Example 1, we will have the same option except this time files will extract. Let's unzip the file with –l option:

Zip in Linux 3

In the above image, we can see that we used –l option for listing, which produces size date of creation and name of the file on output.

Note: In case, we want to extract specific files we can use the following format:

    unzip ZIPname.zip filename

With the above command, only those specific file will extract which are mention there.

Recommended Articles:

ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.