• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

How to zip directory in linux explained with examples

October 18, 2013 by Sharad Chhetri Leave a Comment

Zip is command in linux is used for compressing files and directory.In this post we will learn how to zip the directory or folder in linux.

To compress directory use the below given format

zip -r give-file-name.zip Directory-name

example:

root@tuxworld:/opt# ls -ld teamviewer8/
drwxr-xr-x 6 root root 4096 Oct  2 08:43 teamviewer8/
root@tuxworld:/opt# zip -r teamviewer8.zip teamviewer8

To compress better and faster

To compress directory faster and better we can use the option -9 for better compress and -1 for faster.

example:

root@tuxworld:/opt# zip -1 -9 -r teamviewer8.zip teamviewer8

To zip multiple directory

You can also zip the directory by given below format

zip -r Give-filename.zip dir1 dir2 dir3 dirN

example:
In given below example,here I gave file name as twodir.zip and I am compressing two different directory called
testdir and teamviewer8

zip -r twodir.zip testdir teamviewer8

How to unzip

To decompress or unzip the .zip format file,you have to use simple command called unzip
Format:

unzip filename.zip

example:

unzip twodir.zip

How to list items inside zipped file

This command is useful when you want to only see the listed items inside zipped file without decompressing it.

Format:

unzip -l filename.zip

example:

root@tuxworld:/tmp# unzip -l mydir.zip 
Archive:  mydir.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2013-10-18 20:19   test/
       14  2013-10-18 20:19   test/file3
       14  2013-10-18 20:19   test/file2
        0  2013-10-18 20:19   test/file4
       14  2013-10-18 20:19   test/file1
        0  2013-07-31 02:00   testdir/
        0  2013-07-31 02:00   testdir/testfile
        0  2013-07-31 01:12   testdir/hgjh
---------                     -------
       42                     8 files
root@tuxworld:/tmp# 

how to test zipped file

It is good to test the file before unzip, doing test give you two advantages first you got a health check of zipped file and second you also got to know the list of directory and file inside zipped file without extracting.

To test the zip file use the option -t in given below format

format:

unzip -t filename.zip

Example:

root@tuxworld:/opt# ls -ld test testdir/
drwxr-xr-x 2 root root 4096 Oct 18 20:19 test
drwxrwx--- 2 joe  hr   4096 Jul 31 02:00 testdir/
root@tuxworld:/opt# zip -r mydir.zip test testdir/
  adding: test/ (stored 0%)
  adding: test/file3 (stored 0%)
  adding: test/file2 (stored 0%)
  adding: test/file4 (stored 0%)
  adding: test/file1 (stored 0%)
  adding: testdir/ (stored 0%)
  adding: testdir/testfile (stored 0%)
  adding: testdir/hgjh (stored 0%)
root@tuxworld:/opt# 
root@tuxworld:/opt# ls -l mydir.zip 
-rw-r--r-- 1 root root 1250 Oct 18 20:20 mydir.zip
root@tuxworld:/opt# 
root@tuxworld:/opt# unzip -t mydir.zip 
Archive:  mydir.zip
    testing: test/                    OK
    testing: test/file3               OK
    testing: test/file2               OK
    testing: test/file4               OK
    testing: test/file1               OK
    testing: testdir/                 OK
    testing: testdir/testfile         OK
    testing: testdir/hgjh             OK
No errors detected in compressed data of mydir.zip.
root@tuxworld:/opt#

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. How to zip the directory in linux with command line
  2. shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
  3. Learn Linux Date Command With Examples
  4. create iso image of directory in linux
  5. How to rename and move the directory and files in linux
  6. SCP file and directory in linux and Unix like operating system
  7. Linux command : To create new directory/folder
  8. print working directory ( pwd , PWD , OLDPWD ) in Linux / Unix
  9. 6 df Command Examples To Check Mounted Filesystem On Linux
  10. 6 important examples of cd command on Linux and Unix Systems

Filed Under: Linux, Tips And Tricks Tagged With: zip

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

How to empty Trash through command line in Ubuntu

Forward all incoming emails to other SMTP server or gateway

How to put slider shortcode only in home page in WordPress

How to see system load average in terminal with graphical representation

Change the default port number of ssh server

How to zip the directory in linux with command line

safest method to remove softlink in linux

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy