LinuxCommandLibrary

less

TLDR

View a file

$ less [file]
copy
View a file with line numbers
$ less -N [file]
copy
Search for a pattern after opening
$ /[pattern]
copy
View the output of a command
$ [command] | less
copy
Follow a file as it grows (like tail -f)
$ less +F [file]
copy
Open a file at a specific line
$ less +[line_number] [file]
copy

SYNOPSIS

less [-options] [file ...]

DESCRIPTION

less is a terminal pager program used to view the contents of text files one screen at a time. Unlike more, it allows backward navigation through files and does not require reading the entire file before displaying, making it efficient for large files.
The program provides powerful search capabilities with regular expression support, can display line numbers, and handles multiple files in a single session. It is commonly used as the default pager for manual pages and is invaluable for examining log files and command output.
Less can read from standard input, making it ideal for piping command output. The follow mode (+F) allows real-time monitoring of growing files, similar to tail -f but with the full navigation capabilities of less.

PARAMETERS

-N, --LINE-NUMBERS

Display line numbers at the beginning of each line
-S, --chop-long-lines
Chop long lines instead of wrapping
-i, --ignore-case
Ignore case in searches (unless pattern has uppercase)
-I, --IGNORE-CASE
Ignore case in searches unconditionally
-F, --quit-if-one-screen
Exit immediately if entire file fits on first screen
-R, --RAW-CONTROL-CHARS
Output raw control characters (preserves colors)
-X, --no-init
Don't clear the screen on exit
-g, --hilite-search
Highlight only the current match, not all matches
-n, --line-numbers
Suppress line numbers (for performance)
+F
Follow mode, scroll forward and wait for more data
+ command
Run specified command on startup (e.g., +/pattern to search)
-p pattern
Start at first occurrence of pattern
-o file
Copy input to file (when reading from pipe)

NAVIGATION

Space, f, PgDn

Forward one window
b, PgUp
Backward one window
d, u
Forward/backward half window
j, k or Arrow keys
Forward/backward one line
g, G
Go to beginning/end of file
/ pattern
Search forward for pattern
? pattern
Search backward for pattern
n, N
Repeat search forward/backward
q
Quit
h
Display help

CAVEATS

Binary files may display incorrectly or cause terminal issues. Very long lines can be slow to render without the -S option. The LESSOPEN and LESSCLOSE environment variables can preprocess files but may pose security risks if not properly configured.

HISTORY

less was written by Mark Nudelman and first released in 1984 as an improved replacement for the Unix more command. The name is a play on the phrase "less is more." It has become a standard utility on Unix-like systems and is the default pager on most Linux distributions. The program continues to be actively maintained with regular updates adding new features and improvements.

SEE ALSO

more(1), cat(1), tail(1), head(1), most(1)

> TERMINAL_GEAR

Curated for the Linux community

Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

$1,589.00
Raspberry Pi 5 8GB

Raspberry Pi 5 8GB

$134.50
New Raspberry Pi 3 Model B+ Board Raspberry PI 3B+

New Raspberry Pi 3 Model B+ Board Raspberry PI 3B+

$54.00
Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community

nuphy Air75 V2 Portable 75% Mechanical Keyboard,Wireless Keyboard

nuphy Air75 V2 Portable 75% Mechanical Keyboard,Wireless Keyboard

$129.95
KIWITATA 2X Classic SNES USB Controller for PC Gamings, Retro SNES Wired USB Game Emulator Controller for Windows XP 7 8 11 Mac Raspberry Pi

KIWITATA 2X Classic SNES USB Controller for PC Gamings, Retro SNES Wired USB Game Emulator Controller for Windows XP 7 8 11 Mac Raspberry Pi

$16.99
BOSGAME Mini PC N95, Intel 12th Mini Computers| 16GB DDR4 RAM| 512GB M.2 2280 SSD| 4K 60HZ Triple Displays by Dual HDMI+Type-C, 6W TDP Quiet Mini PC, WIFI5, BT 5.0 Office

BOSGAME Mini PC N95, Intel 12th Mini Computers| 16GB DDR4 RAM| 512GB M.2 2280 SSD| 4K 60HZ Triple Displays by Dual HDMI+Type-C, 6W TDP Quiet Mini PC, WIFI5, BT 5.0 Office

$239.99