File content display

Displaying the contents of a file on the screen

clear (clear screen)

Before you start the next section, you may like to clear the terminal window of the previous commands so the output of the following commands can be clearly understood.

At the prompt, type

$HOME $> clear

This will clear all text and leave you with the $HOME $> at the top of the window. Now create a file called cake with some lines.

cat (concatenate)

The command cat can be used to display the contents of a file on the screen. Type:

$HOME $> cat cake

will show you the content of a file called cake.

less

The command less writes the contents of a file onto the screen a page at a time. Type

$HOME $> less cake

Press the [space-bar] if you want to see another page, type q if you want to quit reading. As you can see, less is used in preference to cat for long files.

head

The head command writes the first ten lines of a file to the screen.

First clear the screen then type

$HOME $> head cake

Then type

$HOME $> head -5 cake

What difference did the -5 do to the head command?

tail

The tail command writes the last ten lines of a file to the screen.

Clear the screen and type

$HOME $> tail cake

How can you view the last 15 lines of the file?

wc (word count)

A handy little utility is the wc command, short for "word count". To do a word count on your file type

$HOME $> wc -w cake

To find out how many lines the file has, type

$HOME $> wc -l cake

Supported By

File Browser Reference
Department FHERIS
University of Galway
HEA Logo