AI Crawler · Collection Records

Bot summary · Last 24 hours

nl — Number lines

Prints a text file with line numbers added.
Markdown source·Anything to add or correct?

Prints a text file with line numbers added.

Basic Information

Command Namenl
One-line IntroductionPrints a text file with line numbers added.
Provided byGNU coreutils
Official Documentationhttps://man7.org/linux/man-pages/man1/nl.1.html
Supported Operating SystemsLinux, macOS, BSD, WSL
Installation StatusInstalled by default
CategoryLinux basic commands (tags: Linux basic commands (tags: nl, line number, numbering, cat))

What is this command?

nl prints input with line numbers. It resembles cat -n but gives finer control over blank lines and number formatting.

-b selects which lines are numbered, -w sets the field width and -s the separator. It is useful when quoting code with line references.

What problems does it solve?

  • Quoting code or configuration with line numbers
  • Referring to a specific log line
  • Numbering only non-empty lines
  • Controlling number width and separator

Key features

Numbering

Adds a sequential number before each line.

  • When to use: Citing documents or code
  • What you get: You can reference exact lines.
  • Limitations: The original file is not modified.

Blank line control

-b a or -b t selects all or non-empty lines.

  • When to use: Reviewing files with many blank lines
  • What you get: Numbering stays contiguous and readable.
  • Limitations: By default only non-empty lines are numbered.

Formatting

-w and -s change width and separator.

  • When to use: Producing a consistent output format
  • What you get: Output stays aligned.
  • Limitations: The options can feel numerous at first.

Installation and usage

Check whether it is installed


nl --version

sudo apt install coreutils # Debian/Ubuntu sudo dnf install coreutils # Fedora

Real-world examples

Basic numbering

Number non-empty lines.


nl config.yml | head

Number all lines

Number blank lines too.


nl -b a notes.txt | head

Custom format

Change width and separator.


nl -w 3 -s ': ' app.py | sed -n '1,10p'

Source (HTML): https://games.aidebatehub.com/programs/linux/basics/nl.html This file is an auto-generated Markdown twin of the DevHub document.

Visitor Comments

Loading…
💬 Comments: 0 · Author type: human | Built: 2026-10-30T20:30:59+09:00