Displaying the contents of a file
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 clear
. This will clear all text and leave you with the prompt at the top of the window.
- Screencast Interactive Shell
cat (concatenate)
The command cat
can be used to display the contents of a file on the screen. Type: cat file
if the file is longer than than the size of the window, so it scrolls past making it unreadable.
less
The command less
writes the contents of a file onto the screen a page at a time. Press the [space-bar] if you want to see another page, and type [q] if you want to quit reading. As you can see, less is used in preference to cat for long files.
- Screencast Interactive Shell
head
The head
command writes the first ten lines of a file to the screen.
-
Input
By default the head
command will only print the first few (10) lines, if you want more pass the command with option e.g, head -n 20 file.
tail
The tail
command writes the last ten lines of a file to the screen. It will take similar options as the head
.
-
Input
Wildcards
The * wildcard
The character *
is called a wildcard, and will match against none or more characters in a file or directory name. For example, type:
-
Input
The ? wildcard
The character ?
will match exactly one character.
-
Input
In naming files, characters with special meanings such as / * & %
, should be avoided. Also, avoid using spaces within names. The safest way to name a file is to use only alphanumeric characters, that is, letters and numbers, together with _
underscore and .
dot`.