Home·Terminal commands

nl

Text processing

Usage

nl [file]

Numbers lines as it prints them; by default it skips blank lines, which is why its numbers disagree with an editor until you pass -b a.

Common flags

FlagMeaning
-b aNumber every line; -b t, the default, skips the blank ones
-wHow wide the number field is
-sWhat goes between the number and the line
-vThe first number to use
-iHow much to add per line

Examples

nl -ba script.sh

Numbers every line, blank ones included.

nl -w1 -s': ' notes.txt

Compact numbering with a colon.

These were built to be piped together. Three joined commands are usually shorter than one that does everything.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does nl do?

Numbers lines as it prints them; by default it skips blank lines, which is why its numbers disagree with an editor until you pass -b a.

Q. How do I type it?

nl [file] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

5 are listed here; the full set is in man nl. This command sits under Text processing.

Related commands

man page: man nl