Back to the command reference

nl

FilesBeginner In simulator In real Linux

Number the lines of files

Name: nl = number lines

You can practise it right away in the simulator, and use it in real Linux mode too.

Description

nl writes a file with line numbers added. Unlike cat -n it skips blank lines by default and lets you control the number format, width and start value.

Syntax

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

Common options

-b aNumber all lines, including blank ones
-w / --number-width NUMWidth of the line numbers
-s / --number-separator STRINGPut STRING between the number and the line (a tab by default)
-v / --starting-line-number NUMStart numbering at NUM
-i / --line-increment NUMCount up by NUM
-n / --number-format FORMATNumber format: ln left, rn right, rz right with zeros

Examples

  • $ nl notes.txt

    Show a file with line numbers

    Explain

Related