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] archivoMost useful options
-baNumbers every line, even empty ones-w NWidth of the number-s SEPSeparator after the numberCopy-ready examples
$ printf 'a\nb\n' > n.txt && nl n.txtNumber linesYou 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.
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