# Cheat Sheet #day59 - diff

### `diff` Command Cheatsheet

The `diff` command in Unix-like systems is used to compare two files line by line and display the differences between them. Here’s a quick reference guide:

#### Basic Syntax

```sh
diff [OPTION]... FILE1 FILE2
```

#### Common Options

* `-u`, `--unified`: Show differences in a unified format. This is the most commonly used format.
    
    ```sh
    diff -u file1.txt file2.txt
    ```
    
* `-c`, `--context`: Show differences in a context format, which includes a few lines of context before and after each change.
    
    ```sh
    diff -c file1.txt file2.txt
    ```
    
* `-i`, `--ignore-case`: Ignore case differences.
    
    ```sh
    diff -i file1.txt file2.txt
    ```
    
* `-w`, `--ignore-all-space`: Ignore all white space.
    
    ```sh
    diff -w file1.txt file2.txt
    ```
    
* `-B`, `--ignore-blank-lines`: Ignore changes whose lines are all blank.
    
    ```sh
    diff -B file1.txt file2.txt
    ```
    
* `-y`: Display differences side by side.
    
    ```sh
    diff -y file1.txt file2.txt
    ```
    
* `-Z`, `--ignore-trailing-space`: Ignore whitespace at the end of lines.
    
    ```sh
    diff -Z file1.txt file2.txt
    ```
    

#### Examples

1. **Basic difference between two files:**
    
    ```sh
    diff file1.txt file2.txt
    ```
    
2. **Unified format comparison:**
    
    ```sh
    diff -u file1.txt file2.txt
    ```
    
3. **Context format comparison:**
    
    ```sh
    diff -c file1.txt file2.txt
    ```
    
4. **Ignore case differences:**
    
    ```sh
    diff -i file1.txt file2.txt
    ```
    
5. **Ignore all white space:**
    
    ```sh
    diff -w file1.txt file2.txt
    ```
    
6. **Ignore blank lines:**
    
    ```sh
    diff -B file1.txt file2.txt
    ```
    
7. **Side-by-side comparison:**
    
    ```sh
    diff -y file1.txt file2.txt
    ```
    
8. **Ignore trailing spaces:**
    
    ```sh
    diff -Z file1.txt file2.txt
    ```
    

#### Displaying Differences with Line Numbers

* **Show line numbers in the output:**
    
    ```sh
    diff -n file1.txt file2.txt
    ```
    

### Additional Information

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

This cheatsheet covers the essential options and usage scenarios for the `diff` command. For more advanced features and details, refer to the `man` page or use `diff --help`.
