> For the complete documentation index, see [llms.txt](https://thamizhiniyancs.gitbook.io/cheatsheets/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://thamizhiniyancs.gitbook.io/cheatsheets/linux/formatting-the-output/nl.md).

# nl

nl linux command cheatsheet by Thamizhiniyan C S

## 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>
