Cheatsheets
HomeWriteupsResourcesCheatsheets
Linux
Linux
  • Know Yourself and Your System
    • id
    • logname
    • uname
    • w
    • who
    • whoami
  • Surfing / Knowing Your File System
    • cd
    • df
    • du
    • ls
    • pwd
    • stat
    • tree
  • Knowing About Files / Commands
    • alias
    • file
    • info
    • whatis
    • apropos
    • man
    • help
    • history
    • script
  • Manipulating Files / Directories
    • touch
    • mkdir
    • rm
    • rmdir
    • cp
    • mv
    • ln
  • Interacting with Files
    • cat
    • head
    • less
    • middle
    • more
    • tail
  • STROPS / Text Manipulation
    • awk
    • cut
    • grep
    • jq
    • join
    • paste
    • sed
    • sort
    • tr
    • uniq
    • xargs
    • xclip
    • wc
    • tee
    • echo
    • comm
    • diff
    • patch
    • aspell
    • Combos
  • Formatting the Output
    • nl
    • fold
    • fmt
    • pr
    • printf
  • Searching / Finding
    • find
    • locate
    • which
    • whereis
    • type
  • Web Interaction
    • curl
    • wget
  • xxd
  • References
Powered by GitBook
On this page
  • Introduction
  • Syntax
  • Important Flags
  • Default Options
  • STYLE to be used with Options
  • FORMAT to be used with Options
  • Examples

Was this helpful?

  1. Formatting the Output

nl

nl linux command cheatsheet by Thamizhiniyan C S

Introduction

The nl command is used to number lines of files.


Syntax

nl [OPTION]... [FILE]...


Important Flags

Flags
Description

-b STYLE

Used for numbering body lines

-i NUMBER

Line number increment at each line

-n FORMAT

Insert line numbers according to FORMAT

-v NUMBER

Change first line number of the given input

-l NUMBER

Group of NUMBER empty lines are counted as one

-s STRING

Add any STRING after every logical line number

-w NUMBER

Use different NUMBER columns for line numbers

Default Options

-b t -d ':' -f n -h n -i 1 -l 1 -n 'rn' -s -v 1 -w 6

STYLE to be used with Options

Values
Description

a

Number all lines

t

Number only nonempty lines

n

Number no lines

pBRE

Number only lines that contain a match for the basic regular expression, BRE

FORMAT to be used with Options

Flags
Description

ln

Left justified, no leading zeros

rn

Right justified, no leading zeros

rz

Right justified, leading zeros


Examples

Command
Description

To display a file with line numbers (Numbers all non-empty lines)

To number all lines (including empty lines also)

Count multiple, consecutive, non-empty lines as one

Override default increment

To make the starting line number different

Add a string literal after line numbers

Change column for line numbers

To number all logical lines that match the specified REGEX (number those lines that begin with F)

To print the lines using left-justified, no leading zeros number format

To print the lines using right-justified, no leading zeros number format

To print the lines using right-justified with leading zeros format

PreviousCombosNextfold

Last updated 1 year ago

Was this helpful?

nl readme.md
nl -b a readme.md
nl -b a -l 3 readme.md
nl -i 3 readme.md
nl -v 4 readme.md
nl -s "..." readme.md
nl -w 6 readme.md
nl -b pF readme.md
nl -n ln readme.md
nl -n rn readme.md
nl -n rz readme.md