# Cheat Sheet #day57 - head

# `head` Command Cheatsheet

The `head` command is used to display the first part of a file or output. It is commonly used to quickly view the beginning of files or outputs, often to check file contents or inspect logs.

## Syntax

```bash
head [OPTION]... [FILE]...
```

## Common Options

* `-n NUM`: Output the first NUM lines. Default is 10.
    
* `-c NUM`: Output the first NUM bytes.
    
* `-q`: Suppress header showing file name.
    
* `-v`: Show file name header (default behavior).
    

## Examples and Use Cases

### Display the First 10 Lines of a File

```bash
head filename.txt
```

* Outputs the first 10 lines of `filename.txt`.
    

### Display the First 20 Lines of a File

```bash
head -n 20 filename.txt
```

* Outputs the first 20 lines of `filename.txt`.
    

### Display the First 10 Bytes of a File

```bash
head -c 10 filename.txt
```

* Outputs the first 10 bytes of `filename.txt`.
    

### Display the First 10 Lines of Multiple Files

```bash
head file1.txt file2.txt
```

* Outputs the first 10 lines of both `file1.txt` and `file2.txt`.
    

### Display the First 5 Lines of a File

```bash
head -n 5 filename.txt
```

* Outputs the first 5 lines of `filename.txt`.
    

### Suppress Header Showing File Name

```bash
head -n 10 -q filename.txt
```

* Outputs the first 10 lines without showing the file name header.
    

### Display the First 10 Lines of a File with a Specific Byte Range

```bash
head -c 50 filename.txt
```

* Outputs the first 50 bytes of `filename.txt`.
    

### View the First 10 Lines of a Pipe Output

```bash
cat filename.txt | head
```

* Outputs the first 10 lines of the content piped from `filename.txt`.
    

### Combine with `-n` and `-c` Options

```bash
head -n 15 -c 100 filename.txt
```

* Outputs the first 100 bytes of the first 15 lines of `filename.txt`.
    

## Additional Information

* **Man Page**: For more details, you can refer to the `head` man page:
    
    ```bash
    man head
    ```
    

---

This cheatsheet covers the most common usages and options for the `head` command. For more detailed information, you can always refer to the `head` man page. Let me know if you need more information or additional examples!
