Lesson 13: Viewing files with cat¶
The cat command displays the contents of the file (or files) and then returns you to the command prompt. We will use the echo command to put some text in a file and then view it:
[learner planets]$ echo "Earth is the only planet in the solar system that has life." > earth.txt
[learner planets]$ cat earth.txt
Earth is the only planet in the solar system that has life.
Using the
redirection
operand >
, we can redirect the quoted text to a file.
Warning
The redirection operand >
will overwrite any existing file of the
same name.
Without redirection, the output of echo
will have been displayed on
the terminal:
[learner planets]$ echo "everything is awesome"
everything is awesome
You can use cat
to quickly combine multiple files or, if you wanted
to, make a copy of an existing file:
[learner planets]$ cat earth.txt > earth.txt.bak