Home·Terminal commands

less

Files and directories

Usage

less [file]

Pages through a file without loading all of it; / searches and q quits, and unlike more it never closes by itself at the end.

Common flags

FlagMeaning
-NShow line numbers
-SChop long lines instead of wrapping them
-iIgnore case while searching unless the pattern has capitals
-RPass color escape codes through as colors
+FStart in follow mode, like tail -f
-XLeave the output on screen after quitting
/wordSearch forward; n repeats it, q quits less

Examples

less +F /var/log/syslog

Follows the log; Ctrl-C stops following and lets you scroll.

less -S wide.csv

Keeps each record on one row so columns stay aligned.

git log | less -R

Pages colored output with the colors kept.

Moving, deleting and finding. Some of these do not ask twice, which is why -i becomes a habit.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does less do?

Pages through a file without loading all of it; / searches and q quits, and unlike more it never closes by itself at the end.

Q. How do I type it?

less [file] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

7 are listed here; the full set is in man less. This command sits under Files and directories.

Related commands

man page: man less