# Cheat Sheet #day60 - cmp

### `cmp` Command Cheatsheet

The `cmp` command in Unix-like systems is used to compare two files byte by byte. It is useful for finding the first difference between two files. Here’s a quick reference guide:

#### Basic Syntax

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

#### Common Options

* `-b`, `--print-bytes`: Output differing bytes in decimal format.
    
    ```sh
    cmp -b file1.txt file2.txt
    ```
    
* `-i POS`, `--ignore-initial=POS`: Ignore the first POS bytes of each file.
    
    ```sh
    cmp -i 10 file1.txt file2.txt
    ```
    
* `-l`, `--line-by-line`: Output the byte number and the differing bytes.
    
    ```sh
    cmp -l file1.txt file2.txt
    ```
    
* `-s`, `--silent`, `--quiet`: Suppress all output, only return exit status.
    
    ```sh
    cmp -s file1.txt file2.txt
    ```
    
* `-v`, `--verbose`: Output a message when files differ.
    
    ```sh
    cmp -v file1.txt file2.txt
    ```
    

#### Examples

1. **Compare two files and print the first difference:**
    
    ```sh
    cmp file1.txt file2.txt
    ```
    
2. **Compare files byte by byte and print differing bytes in decimal format:**
    
    ```sh
    cmp -b file1.txt file2.txt
    ```
    
3. **Ignore the first 10 bytes and compare the rest of the files:**
    
    ```sh
    cmp -i 10 file1.txt file2.txt
    ```
    
4. **Output the byte number and differing bytes:**
    
    ```sh
    cmp -l file1.txt file2.txt
    ```
    
5. **Silent comparison, only return exit status:**
    
    ```sh
    cmp -s file1.txt file2.txt
    ```
    
6. **Verbose output when files differ:**
    
    ```sh
    cmp -v file1.txt file2.txt
    ```
    

#### Additional Information

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

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