nl
text processingLinux/Unix
The nl command is one of the most frequently used commands in Linux/Unix-like operating systems. nl Number lines of files
Quick Reference
Command Name:
nl
Category:
text processing
Platform:
Linux/Unix
Basic Usage:
nl [options] [arguments]
Common Use Cases
Syntax
nl [options] [file]
Options
| Option | Description |
|---|---|
-b, --body-numbering=STYLE |
Use STYLE for numbering body lines: 'a' (number all), 't' (number non-empty - default), 'n' (number none), 'p REGEXP' (number only lines matching REGEXP) |
-d, --section-delimiter=CC |
Use CC for separating logical pages (default is \:) |
-f, --footer-numbering=STYLE |
Use STYLE for numbering footer lines (same as -b) |
-h, --header-numbering=STYLE |
Use STYLE for numbering header lines (same as -b) |
-i, --line-increment=NUMBER |
Increment line number by NUMBER at each line (default 1) |
-l, --join-blank-lines=NUMBER |
Group NUMBER empty lines counted as one |
-n, --number-format=FORMAT |
Insert line numbers according to FORMAT: 'ln' (left justified, no leading zeros), 'rn' (right justified, no leading zeros), 'rz' (right justified, leading zeros) |
-p, --no-renumber |
Do not reset line numbers at logical pages |
-s, --number-separator=STRING |
Add STRING after (possible) line number (default \t) |
-v, --starting-line-number=NUMBER |
First line number on each logical page (default 1) |
-w, --number-width=NUMBER |
Use NUMBER columns for line numbers (default 6) |
--help |
Display help and exit |
--version |
Output version information and exit |
Numbering Styles:
| Style | Description |
|---|---|
| a | Number all lines |
| t | Number only non-empty lines (default) |
| n | Number no lines |
| p'REGEXP' | Number only lines matching REGEXP |
Number Formats:
| Format | Description |
|---|---|
| ln | Left justified, no leading zeros |
| rn | Right justified, no leading zeros |
| rz | Right justified, with leading zeros |
Examples
How to Use These Examples
The examples below show common ways to use the nl command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.