Text and processing

The nl command

Numbers the lines of a file. It is like cat -n but with fine control of the format.

Syntax

nl [opciones] archivo

Most useful options

-baNumbers every line, even empty ones
-w NWidth of the number
-s SEPSeparator after the number

Copy-ready examples

$ printf 'a\nb\n' > n.txt && nl n.txtNumber lines

You can try them in the browser terminal: it does not touch your computer.

Typical mistakes

  • By default it does not number blank lines; use -ba if you want them all.

Related commands

FAQ

Difference from cat -n?

cat -n numbers everything with no options; nl lets you choose what and how to number.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course