Example Uses of the Command "less"

An Introductory Tutorial

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

The 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 set-up or installation.

The program less does not require the whole file to be loaded in memory to view parts of it. Therefore it starts up faster on large files than editors.

Unlike the program more which can only scroll forwards, less can scroll back as well.

To get started, simply type "less file-name" at a command prompt (terminal), where file-name 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

will display the top of file "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. The down-arrow key scrolls one line down. The up-arrow key scrolls one line up. The Page-Down key scrolls down one screen full, while the Page-Up key scrolls up a screen full.

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 "g" without number, to go the end of the file type "G".

To search for a word, number, or sequence of characters, type in "/" followed by the search string or regular expression. For more information see the less man page.