Linux Commands Training Quick Tips – Using the Linux Less & More Commands to View Files – Red Hat


The Linux more and less Commands

Both of these commands can be used to view the contents of a file, such as a text file. Linux scripts and system and server configuration files are examples of text files.

    Linux Commands Training Tips: A Linux text file contains only text (letters, numbers and other characters found on your keyboard) and does not contain any formatting, such as left and right margins, bold or underline.

The Linux more Command Example

Run the following command example to display the contents of the inittab configuration file in the etc directory, which is below the / (root) directory.

    $ more /etc/inittab

This shows the first “page” or “screenful” of the file.

Now press the spacebar to see the next “screenful”.

Now press the up arrow key and then the down arrow key and see that these keys don’t work!

Press q to quit out of the Linux more command.

The Linux less Command Example

This Linux command does everything that more does – and better – this is when less is more!

(A little (very little) Linux programmer humor ;).

Do the following steps to run the less command example below and display the contents of the inittab configuration file again:

Press the up arrow key once, press the Home key, press the Delete key four times to remove “more” and type in “less” (without the quotes). Your command should look like below. Press Enter. Cool.

    $ less /etc/inittab

This shows the first “page” or “screenful” of the file.

Now press the spacebar to see the next “screenful”.

Then press the down arrow a few times and the up arrow.

Then press the Page Down key a few times and then the Page Up key.

Press the End key to go to the end of this Linux text file and then Home to go to the top.

Searching for Text in a File When Using the Linux less Command

Need to quickly find some text in a text file? No problem.

You can easily search for text by pressing the / (slash) key and then typing the text you need to find.

Press Home to go to the top of the file and type in the following: /runlevel and all occurrences of this text appears highlighted.

To move to the next occurrence of the text you’re searching for, type the letter n and to go to the previous occurrence type the letter p. Easy!

Press q to quit out of the less command.

This “Linux Commands Training Quick Tips” show the use of the more and less commands, which are GNU Linux commands. And these commands are the “core” set of commands in ALL Linux distributions.

These “Linux Commands Training – Quick Tips” work in Ubuntu, Red Hat, SUSE, openSUSE, Debian, Slackware, Fedora – and ALL other Linux distros.


Leave a Reply