Example Uses of the Linus "less" Command

Man working at computer
BJI/Blue Jean Images/Getty Images

The Linux command less allows you to quickly view any file and any section of a file. It comes with all major Linux distributions and does not require any setup or installation. It doesn't 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 at a command prompt (terminal), where filename would be the name of the file you want to inspect. This will show the beginning of the file, displaying as many lines as the screen can hold. For example:

less table1

Once the program is started up on a particular file, you can use the arrow keys and the page up and page down keys to move through the file's contents a full screen at a time, up or down. 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

You can 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.

You are also able to jump to locations of a file based on the percentage distance into the file. Type in a percentage for how far into the file you want to move, such as "50" for halfway, and press the "p" or "%" key. The percentage number may even be a decimal number, such as "50.75".

Searching for a pattern

You can 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.