Linux nl Guide - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
Linux nl Guide
Complete beginner-friendly guide to nl on Linux, covering Arch Linux, CachyOS, and other distributions including line numbering, text numbering, and file line counting.
Table of Contents
nl Basics
Number Lines
Basic usage:
# Number lines
nl file.txt
# Numbers all lines
From Input
Pipe input:
# Number from input
cat file.txt | nl
# Numbers piped input
Line Numbering
All Lines
Number all:
# Number all lines
nl file.txt
# Numbers every line
Starting Number
Start from:
# Start from number
nl -v 10 file.txt
# -v = start value (starts from 10)
Number Format
Format String
Custom format:
# Custom format
nl -n ln file.txt
# -n = number format (ln = left, no zero padding)
Format Options
Format types:
# ln = left, no padding
nl -n ln file.txt
# rn = right, no padding
nl -n rn file.txt
# rz = right, zero padded
nl -n rz file.txt
Selective Numbering
Only Numbered Lines
Number only body:
# Number only body lines
nl -b a file.txt
# -b = body numbering (a = all lines)
Skip Empty Lines
Skip blanks:
# Skip empty lines
nl -b t file.txt
# -b t = skip empty lines
Troubleshooting
nl Not Found
Check installation:
# nl is part of coreutils
# Usually pre-installed
# Check nl
which nl
Summary
This guide covered nl usage, line numbering, and text numbering for Arch Linux, CachyOS, and other distributions.
Next Steps
- cat Guide - Display files
- head Guide - View file beginnings
- Text Processing - Text manipulation
- nl Documentation:
man nl
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.