Shell Viewing Files
Viewing a file means printing its words on the screen. The cat command prints a whole file, start to finish.
Print a whole file
cat prints notes.txt in full, all four lines.
cat notes.txtPrint a table file
cat prints data.csv in full, header first.
cat data.csvPrint two files
cat prints notes.txt, then shopping.txt after it.
cat notes.txt shopping.txtPrint a file in a folder
Give cat a path, and it prints the file in that folder.
cat docs/readme.txtExample
echo "Shopping list" > my-list.txt
cat my-list.txt
cat notes.txtKey points
- cat: a command that prints a whole file.
- Use cat to read a short file in full.
- Use cat with two file names to print one file after the other.
- A long file scrolls past the top of the screen, so cat suits small files.
In this example, echo and > make a file with one line in it. Then cat prints that line. Next cat prints notes.txt in full, all four lines.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
Which command prints a whole file on the screen?