# Cheat Sheet #day63 - zip

### `zip` Command Cheatsheet

The `zip` command is used to compress files into a ZIP archive. It is a popular utility for archiving and compressing files in Unix-like systems. Here’s a quick reference guide:

#### Basic Syntax

```sh
zip [OPTION]... ZIP_FILE FILE...
```

#### Common Options

* `-r`, `--recurse-paths`: Recursively include directories and their contents.
    
    ```sh
    zip -r archive.zip directory/
    ```
    
* `-e`, `--encrypt`: Encrypt the archive with a password.
    
    ```sh
    zip -e archive.zip file.txt
    ```
    
* `-9`, `--best`: Use the best compression method.
    
    ```sh
    zip -9 archive.zip file.txt
    ```
    
* `-0`, `--store`: Store files without compression.
    
    ```sh
    zip -0 archive.zip file.txt
    ```
    
* `-q`, `--quiet`: Suppress all output except errors.
    
    ```sh
    zip -q archive.zip file.txt
    ```
    
* `-x`, `--exclude`: Exclude files matching the pattern.
    
    ```sh
    zip -r archive.zip * -x "*.bak"
    ```
    
* `-j`, `--junk-paths`: Do not store the full pathnames.
    
    ```sh
    zip -j archive.zip directory/*
    ```
    
* `-d`, `--delete`: Delete files from the archive.
    
    ```sh
    zip -d archive.zip file.txt
    ```
    
* `-l`, `--local`: Store symbolic links as symbolic links.
    
    ```sh
    zip -l archive.zip link.txt
    ```
    

#### Examples

1. **Create a ZIP archive with files:**
    
    ```sh
    zip archive.zip file1.txt file2.txt
    ```
    
2. **Compress a directory recursively:**
    
    ```sh
    zip -r archive.zip directory/
    ```
    
3. **Encrypt an archive with a password:**
    
    ```sh
    zip -e archive.zip file.txt
    ```
    
4. **Use maximum compression:**
    
    ```sh
    zip -9 archive.zip file.txt
    ```
    
5. **Store files without compression:**
    
    ```sh
    zip -0 archive.zip file.txt
    ```
    
6. **Suppress output except errors:**
    
    ```sh
    zip -q archive.zip file.txt
    ```
    
7. **Exclude files matching a pattern:**
    
    ```sh
    zip -r archive.zip * -x "*.bak"
    ```
    
8. **Store files without full pathnames:**
    
    ```sh
    zip -j archive.zip directory/*
    ```
    
9. **Delete a file from an archive:**
    
    ```sh
    zip -d archive.zip file.txt
    ```
    
10. **Store symbolic links as links:**
    
    ```sh
    zip -l archive.zip link.txt
    ```
    

#### Additional Information

* **Help option:**
    
    ```sh
    zip --help
    ```
    
* **View** `zip` manual page:
    
    ```sh
    man zip
    ```
    

This cheatsheet covers the essential options and usage scenarios for the `zip` command. For more detailed information, refer to the `man` page or use `zip --help`.
