# nl

## Introduction

The nl command is used to number lines of files.

***

## Syntax

`nl [OPTION]... [FILE]...`

***

## Important Flags

<table><thead><tr><th width="301">Flags</th><th>Description</th></tr></thead><tbody><tr><td><code>-b STYLE</code> </td><td>Used for numbering body lines</td></tr><tr><td><code>-i NUMBER</code></td><td>Line number increment at each line</td></tr><tr><td><code>-n FORMAT</code></td><td>Insert line numbers according to FORMAT</td></tr><tr><td><code>-v NUMBER</code></td><td>Change first line number of the given input</td></tr><tr><td><code>-l NUMBER</code></td><td>Group of NUMBER empty lines are counted as one</td></tr><tr><td><code>-s STRING</code></td><td>Add any STRING after every logical line number</td></tr><tr><td><code>-w NUMBER</code></td><td>Use different NUMBER columns for line numbers</td></tr></tbody></table>

### Default Options

`-b t -d ':' -f n -h n -i 1 -l 1 -n 'rn' -s -v 1 -w 6`

### STYLE to be used with Options

| Values | Description                                                                  |
| ------ | ---------------------------------------------------------------------------- |
| `a`    | Number all lines                                                             |
| `t`    | Number only nonempty lines                                                   |
| `n`    | Number no lines                                                              |
| `pBRE` | Number only lines that contain a match for the basic regular expression, BRE |

### FORMAT to be used with Options

| Flags | Description                       |
| ----- | --------------------------------- |
| `ln`  | Left justified, no leading zeros  |
| `rn`  | Right justified, no leading zeros |
| `rz`  | Right justified, leading zeros    |

***

## Examples

<table><thead><tr><th>Command</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nl readme.md
</code></pre></td><td>To display a file with line numbers (Numbers all non-empty lines)</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nl -b a readme.md
</code></pre></td><td>To number all lines (including empty lines also)</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nl -b a -l 3 readme.md
</code></pre></td><td>Count multiple, consecutive, non-empty lines as one</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nl -i 3 readme.md
</code></pre></td><td>Override default increment</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nl -v 4 readme.md
</code></pre></td><td>To make the starting line number different</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nl -s "..." readme.md
</code></pre></td><td>Add a string literal after line numbers</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nl -w 6 readme.md
</code></pre></td><td>Change column for line numbers</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nl -b pF readme.md
</code></pre></td><td>To number all logical lines that match the specified REGEX (number those lines that begin with F)</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nl -n ln readme.md
</code></pre></td><td>To print the lines using left-justified, no leading zeros number format</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nl -n rn readme.md
</code></pre></td><td>To print the lines using right-justified, no leading zeros number format</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nl -n rz readme.md
</code></pre></td><td>To print the lines using right-justified with leading zeros format</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://thamizhiniyancs.gitbook.io/cheatsheets/linux/formatting-the-output/nl.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
