Reading a Text File

To read a text file in your terminal window, use either the (more) or (less) commands.

The more command displays the contents of the text file one terminal screen at a time by printing the contents of the file to the terminal screen. To advance the file, press the SPACEBAR (for the next screen) or use the RETURN action (for the next line). RETURN is an action, sometimes using the ENTER key and sometimes using another key, but always advancing to the next line.  When the end of the file is reached, the user will immediately be prompted for another command, but the contents are still visible in the terminal window.

The less command also shows the contents of a file, but there are a few key differences.  First, you must press Q to exit when you reach the end of the file.  Second, the contents of the file are not printed, they are merely displayed, which means that when you type Q, the contents disappear. The less command also allows the user to scroll back through the text you have already seen using either the UP arrow or the B key. The less command will also allow you to search the text.

eos$ more filename.txt
eos$ less filename.txt

Example

How would you read the outlab3.txt file?

Option 1

eos$ cd /afs/eos.ncsu.edu/courses/e/e115/common/EosLabs/lab-3
eos$ more outlab3.txt

or

eos$ cd /afs/eos.ncsu.edu/courses/e/e115/common/EosLabs/lab-3
eos$ less outlab3.txt

Option 2

eos$ cp /afs/eos.ncsu.edu/courses/e/e115/common/EosLabs/lab-3/outlab3.txt ~/
eos$ more outlab3.txt

or

eos$ cp /afs/eos.ncsu.edu/courses/e/e115/common/EosLabs/lab-3/outlab3.txt ~/
eos$ less outlab3.txt

Option 3

eos$ more /afs/eos.ncsu.edu/courses/e/e115/common/EosLabs/lab-3/outlab3.txt

or

eos$ less /afs/eos.ncsu.edu/courses/e/e115/common/EosLabs/lab-3/outlab3.txt

Should I expect an output?

Yes:

The contents of the file will be displayed/printed to the screen.

NOTE: These two commands can also be used to read other types of files via the command window, but not all files will display correctly. For example, .html and .css files will display normally, but .docx files will not.