Zip command for Terminal 🤐
Tags: zip, unzip
Published: 2024-04-15 02:58:15



{% youtube https://youtu.be/wYmPXVmVB3U?si=qaul7Or3IrL9S-q4 %}

1. Creating a Zip File

To create a zip file, use the following syntax:
```bash
zip -r output.zip input_directory/
```
This will create a zip file called `output.zip` containing all the files and directories inside `input_directory/`.

2. Extracting a Zip File

To extract a zip file, use the following syntax:
```bash
unzip output.zip
```
This will extract all the files and directories inside `output.zip` to the current directory.

3. Listing the Contents of a Zip File

To list the contents of a zip file, use the following syntax:
```bash
unzip -l output.zip
```
This will display a list of all the files and directories inside `output.zip`.

4. Updating a Zip File

To update a file inside a zip file, use the following syntax:
```bash
zip -u output.zip input_file
```
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.

5. Testing a Zip File

To test the integrity of a zip file, use the following syntax:
```bash
zip -t output.zip
```
This will test the files inside `output.zip` with a cyclic redundancy check.

6. Extracting a Zip File to a Specific Directory

To extract a zip file to a specific directory, use the following syntax:
```bash
unzip output.zip -d /path/to/directory/
```
This will extract all the files and directories inside `output.zip` to the directory `/path/to/directory/`.

7. Creating a Zip File with a Specific Compression Method

To create a zip file with a specific compression method, use the following syntax:
```bash
zip -r -0 output.zip input_directory/
```
This will create a zip file called `output.zip` containing all the files and directories inside `input_directory/` with no compression.

8. Extracting a Zip File with a Password

To extract a zip file with a password, use the following syntax:
```bash
unzip -P password output.zip
```
This will extract all the files and directories inside `output.zip` with the password `password`.

9. Creating a Solid Zip Archive

To create a solid zip archive, use the following syntax:
```bash
zip -r -mson output.zip input_directory/
```
This will create a solid zip archive called `output.zip` containing all the files and directories inside `input_directory/`.

10. Extracting a Zip File with a Specific Compression Method

To extract a zip file with a specific compression method, use the following syntax:
```bash
unzip -a output.zip
```
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