DEV Community

Sh Raj
Sh Raj

Posted on

Zip command for Terminal 🀐

  1. Creating a Zip File

To create a zip file, use the following syntax:

zip -r output.zip input_directory/
Enter fullscreen mode Exit fullscreen mode

This will create a zip file called output.zip containing all the files and directories inside input_directory/.

  1. Extracting a Zip File

To extract a zip file, use the following syntax:

unzip output.zip
Enter fullscreen mode Exit fullscreen mode

This will extract all the files and directories inside output.zip to the current directory.

  1. Listing the Contents of a Zip File

To list the contents of a zip file, use the following syntax:

unzip -l output.zip
Enter fullscreen mode Exit fullscreen mode

This will display a list of all the files and directories inside output.zip.

  1. Updating a Zip File

To update a file inside a zip file, use the following syntax:

zip -u output.zip input_file
Enter fullscreen mode Exit fullscreen mode

This will update the file input_file inside output.zip if it has been changed more recently than the version that already existed inside the zip archive.

  1. Testing a Zip File

To test the integrity of a zip file, use the following syntax:

zip -t output.zip
Enter fullscreen mode Exit fullscreen mode

This will test the files inside output.zip with a cyclic redundancy check.

  1. Extracting a Zip File to a Specific Directory

To extract a zip file to a specific directory, use the following syntax:

unzip output.zip -d /path/to/directory/
Enter fullscreen mode Exit fullscreen mode

This will extract all the files and directories inside output.zip to the directory /path/to/directory/.

  1. Creating a Zip File with a Specific Compression Method

To create a zip file with a specific compression method, use the following syntax:

zip -r -0 output.zip input_directory/
Enter fullscreen mode Exit fullscreen mode

This will create a zip file called output.zip containing all the files and directories inside input_directory/ with no compression.

  1. Extracting a Zip File with a Password

To extract a zip file with a password, use the following syntax:

unzip -P password output.zip
Enter fullscreen mode Exit fullscreen mode

This will extract all the files and directories inside output.zip with the password password.

  1. Creating a Solid Zip Archive

To create a solid zip archive, use the following syntax:

zip -r -mson output.zip input_directory/
Enter fullscreen mode Exit fullscreen mode

This will create a solid zip archive called output.zip containing all the files and directories inside input_directory/.

  1. Extracting a Zip File with a Specific Compression Method

To extract a zip file with a specific compression method, use the following syntax:

unzip -a output.zip
Enter fullscreen mode Exit fullscreen mode

This will extract all the files inside output.zip with the LZMA compression method, which usually offers the highest compression rates.

These are just some of the possible things you can do with the zip command in the terminal. For more information, you can refer to the man pages or online documentation.

Citations:
[1] https://www.javatpoint.com/linux-zip-command
[2] https://www.cyberciti.biz/faq/how-to-zip-a-folder-in-ubuntu-linux/
[3] https://askubuntu.com/questions/86849/how-to-unzip-a-zip-file-from-the-terminal
[4] https://realpython.com/lessons/zipfile-from-command-line/
[5] https://www.dotnetperls.com/7-zip-examples

Top comments (0)