maux
Star on GitHub Buy me a coffee

Manual / nl

nl(1)

NL(1) General Commands Manual NL(1)

nl - line numbering filter

nl [ -b type ] [ -f type ] [ -h type ] [ -d delim ] [ -i incr ] [ -n format ] [ -p ] [ -s sep ] [ -v start ] [ -w width ] [ file ]

Nl copies file (standard input if none is given) to standard output, adding a line number field to some or all lines. At most one file is accepted.

The input is read as a sequence of logical pages, each with a header, a body, and a footer section. A line that consists of exactly the two-character delimiter (backslash and colon, by default) repeated three, two, or one time — \:\:\:, \:\:, or \: — switches to the header, body, or footer section and is itself consumed: it is never numbered or printed. With no such lines at all, the whole input is one page's body.

-b type, -h type, and -f type select which lines of the body (default t), header (default n), and footer (default n) get a number: a numbers every line, t only non-empty ones, and n none. pbre numbers only the lines that contain a match for the basic regular expression bre, which follows the p with no separator (-b pfoo and -bpfoo are the same). The body, header, and footer each keep their own expression. An empty bre matches every line; a malformed one matches none.

-d delim sets the delimiter to delim's one or two characters (a single character leaves the second at its default colon). By default, and unless -p is given, encountering any delimiter line — header, body, or footer alike — resets the line number to the -v start value; -p suppresses every one of those resets.

-n format selects ln (left justified, no leading zeros), rn (right justified, no leading zeros — the default), or rz (right justified, zero-padded). -w width sets the field width (default 6, capped at 20 in this implementation). -s sep sets the text between the number field and the line (default one tab); an unnumbered line still prints the field's own width in blanks and the separator, just no digits. -v start sets the initial and reset line number (default 1); -i incr sets the increment (default 1, optionally signed).

/usr/man/NL this page

cat(1), fold(1)

Exit status is 0; 1 if the file operand could not be opened; 2 for a usage error, including more than one file operand, a malformed option value.

Line numbers are 16-bit; the ceiling is 65535, and -v / -i arithmetic past it wraps silently. A line longer than 200 bytes is truncated at that length before being printed back.

October 8, 2026 maux