Text processing

Linux less command

Read long text one screen at a time. Search with / and quit with q.

Availability: Common Linux commands; shell built-ins and external implementations may differ by distribution.中文

Syntax

less [OPTION]... [FILE]...

Examples

Browse a log with line numbers.

less -N /var/log/syslog

Follow new log output, then press Ctrl+C to browse.

less +F app.log

Parameters, options and clauses

Option / clauseDescription
-N, --LINE-NUMBERSShow line numbers.
-S, --chop-long-linesDo not wrap long lines; scroll horizontally instead.
-iIgnore case in searches when the pattern has no uppercase letters.
-F, --quit-if-one-screenExit if the entire file fits on one screen.
-RAllow ANSI colour and control sequences to pass through.
+FFollow file growth, similar to tail -f; Ctrl+C returns to browsing.
Safety note

Review a command and its target before running it. Commands that alter files, services, accounts, disks, permissions or databases may be difficult to reverse. Test in a safe environment and keep backups.

Official reference ↗Back to directory