# Cheat Sheet #day58 - tail

### `tail` Command Cheatsheet

The `tail` command in Unix-like operating systems is used to display the last part of a file. Here’s a quick reference guide:

#### Basic Syntax

```sh
tail [OPTION]... [FILE]...
```

#### Common Options

* `-n NUM`, `--lines=NUM`: Output the last NUM lines. Default is 10.
    
    ```sh
    tail -n 20 file.txt
    ```
    
* `-c NUM`, `--bytes=NUM`: Output the last NUM bytes.
    
    ```sh
    tail -c 100 file.txt
    ```
    
* `-f`, `--follow`: Output appended data as the file grows. Useful for monitoring log files.
    
    ```sh
    tail -f /var/log/syslog
    ```
    
* `-F`, `--follow=name --retry`: Similar to `-f`, but will try to reopen the file if it is moved or rotated.
    
    ```sh
    tail -F /var/log/syslog
    ```
    
* `-q`, `--quiet`, `--silent`: Never output headers giving file names.
    
    ```sh
    tail -q file1.txt file2.txt
    ```
    
* `-v`, `--verbose`: Always output headers giving file names.
    
    ```sh
    tail -v file.txt
    ```
    

#### Examples

1. **Display the last 10 lines of a file:**
    
    ```sh
    tail file.txt
    ```
    
2. **Display the last 20 lines of a file:**
    
    ```sh
    tail -n 20 file.txt
    ```
    
3. **Display the last 100 bytes of a file:**
    
    ```sh
    tail -c 100 file.txt
    ```
    
4. **Follow a log file in real-time:**
    
    ```sh
    tail -f /var/log/syslog
    ```
    
5. **Follow a log file and retry if it is rotated:**
    
    ```sh
    tail -F /var/log/syslog
    ```
    
6. **Display the last 10 lines of multiple files:**
    
    ```sh
    tail file1.txt file2.txt
    ```
    
7. **Display the last 10 lines of multiple files with headers:**
    
    ```sh
    tail -v file1.txt file2.txt
    ```
    
8. **Quiet mode for multiple files without headers:**
    
    ```sh
    tail -q file1.txt file2.txt
    ```
    

### Additional Information

* **Display help:**
    
    ```sh
    tail --help
    ```
    
* **View** `tail` manual page:
    
    ```sh
    man tail
    ```
    

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