Best zip command with examples on Linux

Zip Command is a tool used in Linux to compress a file or directory to reduce its size. There are so many other useful functions when compressing such as compressing so many files into a file file and so on.

Let’s take a scenario: I have to send an email with an attachment and the file size is 15 MB, but the maximum size for attachments is 12 MB. In this case I can use the zip command to compress and shrink the file.

Best zip commands with examples on Linux

Best zip command with examples on Linux:

In this article we will briefly discuss zip commands.

1. Compress a file with the zip command

Compress a zip file as shown below.

Example:

Here we have a file called doc.txt, Let’s compress the file using the following command.

   
   [[email protected] ~]# zip doc.zip doc.txt 
     adding: doc.txt (stored 0%)
   [[email protected] ~]# ls
   anaconda-ks.cfg  Desktop  doc.txt  doc.zip  install.log  install.log.syslog
   [[email protected] ~]# 

2. Compress multiple files with the zip command

Use the following command to compress multiple files.

Example:

We have some files like doc1.txt, doc2.txt, doc3.txt, doc4.txt, doc5.txt So we compress it with the zip command.

   
   [[email protected] ~]# ls
   anaconda-ks.cfg  doc1.txt  doc3.txt  doc5.txt     install.log.syslog
   Desktop          doc2.txt  doc4.txt  install.log

   [[email protected] ~]# zip doc.zip doc1.txt doc2.txt doc3.txt doc4.txt doc5.txt   #  Compress Multiple Files at Once
     adding: doc1.txt (stored 0%)
     adding: doc2.txt (stored 0%)
     adding: doc3.txt (stored 0%)
     adding: doc4.txt (stored 0%)
     adding: doc5.txt (stored 0%)
   [[email protected] ~]# ls
   anaconda-ks.cfg  doc1.txt  doc3.txt  doc5.txt  install.log
   Desktop          doc2.txt  doc4.txt  doc.zip   install.log.syslog
   [[email protected] ~]# 

3. Exclude files from the ZIP format

I have as much data as text files, office documents, PDF files etc. and I want to zip all files except for PDF files ( means that I don’t want to compress PDF files), So follow the command below to do the same. We can do this with the zip command with option x

Example:

   
   [[email protected] ~]# ls mydata/
   doc1.txt  doc3.txt  doc5.txt   file2.pdf  file4.pdf
   doc2.txt  doc4.txt  file1.pdf  file3.pdf  file5.pdf

   [[email protected] ~]# zip mydata.zip -r mydata/ -x *.pdf   # Compress all Files Excluding PDF Files 
     adding: mydata/ (stored 0%)
     adding: mydata/doc1.txt (stored 0%)
     adding: mydata/doc3.txt (stored 0%)
     adding: mydata/doc5.txt (stored 0%)
     adding: mydata/doc4.txt (stored 0%)
     adding: mydata/doc2.txt (stored 0%)
   [[email protected] ~]# ls
   anaconda-ks.cfg  Desktop  install.log  install.log.syslog  mydata  mydata.zip # As we can see below on the output all files are Compress Excluding PDF files.

   [[email protected] ~]# unzip -l mydata.zip  # List the Content of zip Archive
   Archive:  mydata.zip
     Length     Date   Time    Name
    --------    ----   ----    ----
           0  12-14-16 06:59   mydata/
           0  12-14-16 06:59   mydata/doc1.txt
           0  12-14-16 06:59   mydata/doc3.txt
           0  12-14-16 06:59   mydata/doc5.txt
           0  12-14-16 06:59   mydata/doc4.txt
           0  12-14-16 06:59   mydata/doc2.txt
    --------                   -------
           0                   6 files
   [[email protected] ~]# 

4. Compress a directory with the zip command

Here we have a directory called my data For some files, you can compress the directory using the following command.

Example:

   
   [[email protected] ~]# ls mydata/
   test1.txt  test2.txt  test3.txt  test4.txt
   
   [[email protected] ~]# zip mydata.zip -r mydata/  # Compress a Directory using zip
     adding: mydata/ (stored 0%)
     adding: mydata/test2.txt (stored 0%)
     adding: mydata/test1.txt (stored 0%)
     adding: mydata/test4.txt (stored 0%)
     adding: mydata/test3.txt (stored 0%)
   [[email protected] ~]# ls
   anaconda-ks.cfg  file         install.log.syslog  mydata.zip
   Desktop          install.log  mydata
   [[email protected] ~]#

Read also – Compress files with Bz2 (Bzip2 Linux command) and unzip the Bz2 file on Linux

5. List files and directories in the ZIP archive

Use the following command to list files and directories that are compressed in the ZIP archive.

Method 1We can do this with the zip command with option l

   
   [[email protected] ~]# unzip -l documents.zip  # List the Content of the zip Archive
   Archive:  documents.zip
     Length     Date   Time    Name
    --------    ----   ----    ----
           0  12-14-16 06:29   doc1.txt
           0  12-14-16 06:29   doc2.txt
           0  12-14-16 06:29   doc3.txt
           0  12-14-16 06:29   doc4.txt
           0  12-14-16 06:29   doc5.txt
    --------                   -------
           0                   5 files

Method: 2OR we can use fewer Command to list the contents of the ZIP archive as shown below.

   
   [[email protected] ~]# less documents.zip   # List the Content of the zip Archive
   
   # The Output Would Look like as shown below :
   
   Archive:  documents.zip   526 bytes   4 files
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:40 doc1.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:40 doc2.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:40 doc3.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:40 doc4.txt
   4 files, 0 bytes uncompressed, 0 bytes compressed:  0.0%
   documents.zip (END) 

6. Compress a directory with all of its files and subdirectories

Suppose we have a directory with subdirectories and files. We can recursively compress it using the zip command with the option r,

Example:

Here we have a directory called my data with the files doc1.txt, doc2.txt… .doc5.txt and a subdirectory called Database For some files file1.txt, file2.txt… .file5.txt we use the following command.

   
   [[email protected] ~]# ls mydata/
   database  doc1.txt  doc2.txt  doc3.txt  doc4.txt  doc5.txt
   [[email protected] ~]# ls mydata/database/
   file1.txt  file2.txt  file3.txt  file4.txt  file5.txt
   
   [[email protected] ~]# zip -r mydata.zip mydata/  # Compress Directory with Sub-Directories with all its file Recursively
     adding: mydata/ (stored 0%)
     adding: mydata/doc1.txt (stored 0%)
     adding: mydata/doc3.txt (stored 0%)
     adding: mydata/database/ (stored 0%)
     adding: mydata/database/file5.txt (stored 0%)
     adding: mydata/database/file3.txt (stored 0%)
     adding: mydata/database/file2.txt (stored 0%)
     adding: mydata/database/file4.txt (stored 0%)
     adding: mydata/database/file1.txt (stored 0%)
     adding: mydata/doc5.txt (stored 0%)
     adding: mydata/doc4.txt (stored 0%)
     adding: mydata/doc2.txt (stored 0%)
   [[email protected] ~]# 

7. Check the valid zip archive file

To check whether the created zip file is valid or not, use the zip command with the option T

   
   [[email protected] ~]# ls
   anaconda-ks.cfg  data.zip  Desktop  install.log  install.log.syslog
   [[email protected] ~]# zip -T data.zip 
   test of data.zip OK     # This is a valid zip File

# For Example let's create a text file and change it's extension to .zip by renaming it.

   [[email protected] ~]# touch test.txt
   [[email protected] ~]# ls
   anaconda-ks.cfg  data.zip  Desktop  install.log  install.log.syslog  test.txt
   [[email protected] ~]# mv test.txt test.zip
   [[email protected] ~]# ls
   anaconda-ks.cfg  data.zip  Desktop  install.log  install.log.syslog  test.zip 

# Now Let's check if Renamed zip file is valid or not.

   [[email protected] ~]# zip -T test.zip 
           zip warning: missing end signature--probably not a zip file (did you
           zip warning: remember to use binary mode when you transferred it?)

   zip error: Zip file structure invalid (test.zip)
   [[email protected] ~]# 

As we can see above, it is not a valid ZIP file because we did not create it with the zip command.

8. Extract a specific file from the zip archive

I have a zip archive file and want to extract / extract a specific file from it. We can do this with the following command.

Example:

Here I have a zip archive called mydata.zip with some files as shown below and i will extract the file doc1.txt from that.

   
   [[email protected] ~]# ls
   anaconda-ks.cfg  Desktop  install.log  install.log.syslog  mydata.zip
   [[email protected] ~]# less mydata.zip
   
   Archive:  mydata.zip   1788 bytes   12 files
   drwxr-xr-x  2.3 unx        0 bx stor 13-Dec-16 06:49 mydata/
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:37 mydata/doc1.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:37 mydata/doc3.txt
   drwxr-xr-x  2.3 unx        0 bx stor 13-Dec-16 06:49 mydata/database/
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:49 mydata/database/file5.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:49 mydata/database/file3.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:49 mydata/database/file2.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:49 mydata/database/file4.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:49 mydata/database/file1.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:37 mydata/doc5.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:37 mydata/doc4.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:37 mydata/doc2.txt
   12 files, 0 bytes uncompressed, 0 bytes compressed:  0.0%
   mydata.zip (END) 

   [[email protected] ~]# unzip mydata.zip mydata/doc1.txt  # To Unzip Particular File
   Archive:  mydata.zip
    extracting: mydata/doc1.txt         
   
   # As we can see below we unzip a file doc1.txt.

   [[email protected] ~]# ls
   anaconda-ks.cfg  Desktop  install.log  install.log.syslog  mydata  mydata.zip
   [[email protected] ~]# ls mydata 
   doc1.txt
   [[email protected] ~]# 

Note: You must provide the full path to extract a file or directory, as mentioned here mydata / doc1.txt,

9. Extract several files from the zip archive

We can also extract multiple files from the zip archive using the following command. Here I extract two files file5.txt and file4.txt.

Example:

   
   [[email protected] ~]# unzip mydata.zip mydata/database/file4.txt mydata/database/file5.txt
    Archive:  mydata.zip
    extracting: mydata/database/file5.txt  
    extracting: mydata/database/file4.txt  
   [[email protected] ~]# ls mydata/database/
   file4.txt  file5.txt
   [[email protected] ~]# 

Read Also – Best Linux Gzip Command (Gzip Compression) With Examples

10. Unzip multiple files with one WildCard

Suppose you want to extract so many files of the same type that, for example, you want to extract some files with the extension .TXT, We can do this with wildcard as shown below.Example:

   
   [[email protected] ~]# unzip mydata.zip mydata/*.txt  # Extract using WildCard
   Archive:  mydata.zip
    extracting: mydata/doc1.txt         
    extracting: mydata/doc3.txt         
    extracting: mydata/database/file5.txt  
    extracting: mydata/database/file3.txt  
    extracting: mydata/database/file2.txt  
    extracting: mydata/database/file4.txt  
    extracting: mydata/database/file1.txt  
    extracting: mydata/doc5.txt         
    extracting: mydata/doc4.txt         
    extracting: mydata/doc2.txt         
   [[email protected] ~]# ls
   anaconda-ks.cfg  Desktop  install.log  install.log.syslog  mydata  mydata.zip
   [[email protected] ~]# ls mydata
   database  doc1.txt  doc2.txt  doc3.txt  doc4.txt  doc5.txt
   [[email protected] ~]# ls mydata/database/
   file1.txt  file2.txt  file3.txt  file4.txt  file5.txt
   [[email protected] ~]# 

11. Unzip to another directory

To extract a zip archive to another directory, we can use it unzip Command with option dHere I extract the zip archive with the name mydata.zip named to the directory /testing,

Example:

   [[email protected] ~]# mkdir /testing
   [[email protected] ~]# unzip mydata.zip -d /testing/  # Unzip to a Different Directory
   Archive:  mydata.zip
      creating: /testing/mydata/
    extracting: /testing/mydata/doc1.txt  
    extracting: /testing/mydata/doc3.txt  
      creating: /testing/mydata/database/
    extracting: /testing/mydata/database/file5.txt  
    extracting: /testing/mydata/database/file3.txt  
    extracting: /testing/mydata/database/file2.txt  
    extracting: /testing/mydata/database/file4.txt  
    extracting: /testing/mydata/database/file1.txt  
    extracting: /testing/mydata/doc5.txt  
    extracting: /testing/mydata/doc4.txt  
    extracting: /testing/mydata/doc2.txt  
   [[email protected] ~]# ls /testing/
   mydata
   [[email protected] ~]# ls /testing/mydata/
   database  doc1.txt  doc2.txt  doc3.txt  doc4.txt  doc5.txt
   [[email protected] ~]# ls /testing/mydata/database/
   file1.txt  file2.txt  file3.txt  file4.txt  file5.txt
   [[email protected] ~]# 

12. Delete a file from the zip archive

We can delete a specific file from the zip archive using the zip command with the option dHere I delete a file with the name doc1.txt from the zip archive mydata.zip.

Example:

    
   [[email protected] ~]# ls
   anaconda-ks.cfg  Desktop  install.log  install.log.syslog  mydata.zip
   [[email protected] ~]# less mydata.zip  # To List Content of the zip Archive
   
   Archive:  mydata.zip   1788 bytes   12 files
   drwxr-xr-x  2.3 unx        0 bx stor 13-Dec-16 06:49 mydata/
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:37 mydata/doc1.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:37 mydata/doc3.txt
   drwxr-xr-x  2.3 unx        0 bx stor 13-Dec-16 06:49 mydata/database/
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:49 mydata/database/file5.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:49 mydata/database/file3.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:49 mydata/database/file2.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:49 mydata/database/file4.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:49 mydata/database/file1.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:37 mydata/doc5.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:37 mydata/doc4.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:37 mydata/doc2.txt
   12 files, 0 bytes uncompressed, 0 bytes compressed:  0.0%
   mydata.zip (END) 
   
   [[email protected] ~]# zip -d mydata.zip "mydata/doc1.txt"   # Delete a File from zip Archive
   deleting: mydata/doc1.txt

   Archive:  mydata.zip   1648 bytes   11 files
   drwxr-xr-x  2.3 unx        0 bx stor 13-Dec-16 06:49 mydata/
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:37 mydata/doc3.txt
   drwxr-xr-x  2.3 unx        0 bx stor 13-Dec-16 06:49 mydata/database/
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:49 mydata/database/file5.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:49 mydata/database/file3.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:49 mydata/database/file2.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:49 mydata/database/file4.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:49 mydata/database/file1.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:37 mydata/doc5.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:37 mydata/doc4.txt
   -rw-r--r--  2.3 unx        0 bx stor 13-Dec-16 06:37 mydata/doc2.txt
   11 files, 0 bytes uncompressed, 0 bytes compressed:  0.0%
   mydata.zip (END) 

13. Create a zip file with password protection

To create a zip archive with password protection, we can use the zip command with options P as shown in the command below.

Example:

   
   [[email protected] ~]# ls
   anaconda-ks.cfg  Desktop  doc.txt  install.log  install.log.syslog
   [[email protected] ~]# zip -P pass123 doc.zip doc.txt  # Create a zip file with Password Protected
     adding: doc.txt (stored 0%)
   [[email protected] ~]# ls
   anaconda-ks.cfg  Desktop  doc.txt  doc.zip  install.log  install.log.syslog
   [[email protected] ~]# rm doc.txt 
   rm: remove regular empty file `doc.txt'? y
   [[email protected] ~]# unzip doc.zip   # Unzip the file
   Archive:  doc.zip
   [doc.zip] doc.txt password:         # Enter the Password to Unzip the File as its Password Protected
    extracting: doc.txt                 
   [[email protected] ~]# ls
   anaconda-ks.cfg  Desktop  doc.txt  doc.zip  install.log  install.log.syslog
   [[email protected] ~]# 

14. Encrypt the zip archive with its content

To encrypt a zip file with all of its contents, we can compress the file using the zip command with the e option as shown below. During the encryption of the zip archive you will be asked for a password. So enter it twice as shown below.

Example:

   [[email protected] ~]# ls
   anaconda-ks.cfg  Desktop  doc.txt  install.log  install.log.syslog
   [[email protected] ~]# zip -e doc.zip doc.txt  # Encrypt a zip file
   Enter password: 
   Verify password: 
     adding: doc.txt (stored 0%)
   [[email protected] ~]# ls
   anaconda-ks.cfg  Desktop  doc.txt  doc.zip  install.log  install.log.syslog
   [[email protected] ~]# 

15. Add a file to the existing ZIP archive

Suppose we have a zip archive and want to add a file to the existing zip file.

Example:Here in this example I have a zip file named mydata.zip and i will add a file named test.txt to my existing zip archive, so follow the steps.

   
   [[email protected] ~]# ls
   anaconda-ks.cfg  Desktop  install.log  install.log.syslog  mydata.zip
   [[email protected] ~]# unzip -l mydata.zip  # List the files
   Archive:  mydata.zip
     Length     Date   Time    Name
    --------    ----   ----    ----
           0  12-14-16 07:48   doc1.txt
           0  12-14-16 07:48   doc2.txt
           0  12-14-16 07:48   doc3.txt
    --------                   -------
           0                   3 files
   [[email protected] ~]# touch test.txt
   [[email protected] ~]# ls
   anaconda-ks.cfg  Desktop  install.log  install.log.syslog  mydata.zip  test.txt
   [[email protected] ~]# zip mydata.zip test.txt  # Add file to Existing zip Archive
     adding: test.txt (stored 0%)
   [[email protected] ~]# unzip -l mydata.zip 
   Archive:  mydata.zip
     Length     Date   Time    Name
    --------    ----   ----    ----
           0  12-14-16 07:48   doc1.txt
           0  12-14-16 07:48   doc2.txt
           0  12-14-16 07:48   doc3.txt
           0  12-14-16 07:50   test.txt
    --------                   -------
           0                   4 files

Read also – How to install 7Zip (7z) Archive Tool in Ubuntu 18.04

16. Different degrees of compression

Another level of compression is available for zipping, e.g. B. 0, 1, 2. to 10. Here we have listed two examples, e.g.0” and “9“.

Level – 0 – For fast compression.

Level – 9 – For best compression.

Example:

   
   [[email protected] ~]# zip -0 data.zip file*   # For Fast Compression
   adding: file1.txt (stored 0%)
   adding: file2.txt (stored 0%)
   adding: file3.txt (stored 0%)
   adding: file4.txt (stored 0%)
   adding: file5.txt (stored 0%)
   
   [[email protected] ~]# zip -9 data.zip file*   # For Best Compression
   adding: file1.txt (stored 0%)
   adding: file2.txt (stored 0%)
   adding: file3.txt (stored 0%)
   adding: file4.txt (stored 0%)
   adding: file5.txt (stored 0%)

17. Check the contents of the file in a zip archive

Here I have archived a text file with zip that contains text. We can see this without extracting the file with the zcat command as shown below.

Example:

   
   [[email protected] ~]# ls
   anaconda-ks.cfg  Desktop  doc.zip  install.log  install.log.syslog
   [[email protected] ~]# zcat doc.zip    # To Check the content of the file
   Welcome to itsmarttricks.com

   Subscribe us for Updated Linux Tutorials, Guides, Tips and Tricks...
   [[email protected] ~]# 
 
# If the file is too long we can use zless command which have the feature to scroll the file by using UP & DOWN arrow to check the file.

   [[email protected] ~]# zip apache.zip /etc/httpd/conf/httpd.conf 
     adding: etc/httpd/conf/httpd.conf (deflated 65%)
   [[email protected] ~]# ls
   anaconda-ks.cfg  apache.zip  Desktop  install.log  install.log.syslog
   [[email protected] ~]# zless apache.zip 

Best zip command with examples on Linux

Zip log file

We can also use zmore Command to check the log file zlos Here, however, we cannot use the UP and DOWN arrow keys to scroll through the file. We have to press here space bar to scroll the file DOWN, and we can’t even scroll UP to scroll the file DOWN. zmore Command shows one page at a time.

   
   [[email protected] ~]# zmore apache.zip 

Best zip command with examples on Linux

Zip log file

18. Update existing files in a ZIP archive

Suppose we have a directory called my data that contains some files like doc1.txt, doc2.txt, doc3.txt and we make a backup of it every day. From three files doc1.txt contains text as shown below.Example:

# As shown below doc1.txt contains some text in it.

   [[email protected] ~]# ls mydata/
   doc1.txt  doc2.txt  doc3.txt
   [[email protected] ~]# cat mydata/doc1.txt 
   Welcome to itsmarttricks.com

# Now Create a Zip File of Directory mydata using below command

   [[email protected] ~]# zip mydata.zip -r mydata/
     adding: mydata/ (stored 0%)
     adding: mydata/doc1.txt (stored 0%)
     adding: mydata/doc3.txt (stored 0%)
     adding: mydata/doc2.txt (stored 0%)
   [[email protected] ~]# ls
   anaconda-ks.cfg  Desktop  file  install.log  install.log.syslog  mydata  mydata.zip # After creating a zip file let's update the file doc1.txt and add some more text in it as shown below.

   [[email protected] ~]# cat mydata/doc1.txt 
   Welcome to itsmarttricks.com Get All The Latest Updates Delivered Straight Into Your Inbox For Free!# Now let's Update the file doc1.txt in zip archive without Extracting it using command zip with Optionf 

   [[email protected] ~]# zip mydata.zip -rf mydata/ # Update the File in Existing zip Archive
   freshening: mydata/doc1.txt (deflated 7%)
   [[email protected] ~]# 

   # Now Let's delete our Source Directory "mydata" and extract the zip file to check the file doc1.txt is Updated on not.

   [[email protected] ~]# rm -rf mydata   # Delete the Source Directory
   [[email protected] ~]# ls
   anaconda-ks.cfg  Desktop  file  install.log  install.log.syslog  mydata.zip
   [[email protected] ~]# unzip mydata.zip # Unzip the mydata.zip Archive
   Archive:  mydata.zip
      creating: mydata/
     inflating: mydata/doc1.txt         
    extracting: mydata/doc3.txt         
    extracting: mydata/doc2.txt         
   [[email protected] ~]# ls
   anaconda-ks.cfg  Desktop  file  install.log  install.log.syslog  mydata  mydata.zip
   [[email protected] ~]# cat mydata/doc1.txt 
   Welcome to itsmarttricks.com Get All The Latest Updates Delivered Straight Into Your Inbox For Free!


   [[email protected] ~]#

   # As we can see above the file doc1.txt is updated Successfully

Some useful zip command options:

  • x – Exclude some files for compression
  • r – Recursively compress files and directories
  • d – Extract the zip file to another directory
  • d – Delete a file from an existing ZIP file

Note: The argument “d“We worked in a different place to work differently. We have included both examples above.

  • T – To check the zip file
  • l – To list the contents of the ZIP file
  • P – How to create a zip file with password protection
  • e – Encrypt a zip file
  • 0 – Degree of compression for fast compression
  • 9 – Degree of compression for best compression
  • f – How to update / update a file in an existing ZIP file

That’s all. We explained the best in this article Post Code Command with examples on Linux. I hope you like this article. If you like this article, just share it. If you have any questions about this article, please comment.

Sidebar