Example Uses of the Linux "less" Command

Less gets you more—more context, that is

Incomplete text 'Less is more' on lightbox

Jorg Greuel / Getty Images

The Linux "less" command displays any file and any section of a file. It comes with all major Linux distributions and does not require any setup or installation. It does not require the whole file to be loaded into memory to view parts of it, so it starts up faster on large files than editors do. And unlike the program "more," which can only scroll forward, less can scroll back as well.

To get started, simply type less filename in a shell. The program loads the beginning of the file, displaying as many lines as the screen can hold. For example:


After the program loads a particular file, use the page-up and page-down keys to move through the file's contents a full screen at a time. The down-arrow key scrolls one line down, while the up-arrow key scrolls one line up.

Moving to a Specific Position in a File

Jump to any line in the file by typing in the line number followed by g. To go the beginning of the file, type a lowercase g without a number. To go the end of the file, type an uppercase G without a number.

Jump to locations of a file based on the percentage distance into the file. Type a percentage for how far into the file you want to move, such as "50" for halfway, then press the P or % key. The percentage number may be a decimal number, such as 50.75.

Searching for a Pattern

Use less to search for a specific word, number, or sequence of characters by typing / followed by the search string or regular expression. For example:

/"task 2"

This command will locate task 2 within the file.