Welcome guest


more and less

There are many times that you might want to read a text file, as they are used for a lot of things on computers. There are two Linux commands that can be used to read text files: more and less.

The more command will display the contents of a text file one screen (Terminal screen) full of text at a time and wait after each screen for you to press the "space bar." You can also press the "return" key to display one more line at a time. This will continue until the file has been completely displayed.

The less command does basically the same thing, with a few differences. When less reaches the end of the file you will have to press 'q' (quit) to exit the program. The less command has an unique feature that allows you to scroll back through text you have already seen using either the up arrow key or the 'b' key. You can also move down one line at a time using the "return" key.

Syntax

eos% more filename
eos% less filename

Example

If you wanted to read the textfile outlab2 and you were in your home directory, how would you do it?

more and less in the File Tree

Ask yourself:

Q: What am I doing? A: Reading a text file.
Q: How do I do that? A: Using either the more or the less command.
Q: What are the path names? A: I am in my home directory and the file is in the e115 locker.

There are several ways to do this:

  1. Change to the directory that the file is located in and then use the less or more command to read the file:

    eos% cd /afs/eos.ncsu.edu/courses/e/e115/common/EosLabs/Lab-2
    eos% more outlab2


    or

    eos% less outlab2
  2. Copy the file to your home directory and then read it using less or more:

    eos% cp /afs/eos.ncsu.edu/courses/e/e115/common/EosLabs/Lab-2/outlab2 ~/
    eos% more outlab2


    or

    eos% less outlab2
  3. Use the less or more command with the entire pathname of the file:

    eos% more /afs/eos.ncsu.edu/courses/e/e115/common/EosLabs/Lab-2/outlab2
    eos% less /afs/eos.ncsu.edu/courses/e/e115/common/EosLabs/Lab-2/outlab2

Over time you will find the way that is most comfortable for you.