Ad space (banner)
🖥️Linux Lessons
Lesson 45 / 61

Displaying with Line Numbers Using nl

nl is for when "I want to check a file's content with line numbers attached." nl stands for number lines, and it adds a line number to the start of each line in a file.

Use it in the form nl filename. cat -n has similar functionality, but nl has richer fine-grained options, like how it handles blank lines.

Running nl notes.txt displays notes.txt with each line prefixed by a line number, starting from 1.

A common early mistake is expecting blank lines to get numbered too, but being surprised by the default behavior, which actually skips them (leaving them unnumbered).

In real work, this is used when you want to share content with line numbers attached, for a code review or to point out a specific line in a log.

Linux
Try it (type this into the pseudo terminal)
nl notes.txt

🧑‍💻 You can type this command into the Linux pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)