Reading Files
Reading files means printing the words inside a file on the screen. Cat prints a whole file from start to end.
One short file
Cat prints the one line in README.txt.
$ cat ~/practice/README.txtA list file
Cat prints the shopping list, four lines in order.
$ cat ~/practice/notes/shopping.txtTwo files at once
Cat prints the shopping list, then the todo list.
$ cat ~/practice/notes/shopping.txt ~/practice/notes/todo.txtA report file
Cat prints the report, four lines in order.
$ cat ~/practice/projects/report.txtExample
$ cat ~/practice/README.txt
$ cat ~/practice/notes/todo.txt
$ cat ~/practice/projects/report.txtKey points
- Cat prints every line of a file, from the first line to the last.
- Use cat to read a short file in one look.
- Cat prints files in the order you name them.
- Cat shows the lines exactly as they sit in the file.
In this example, three lines read three files. The first line prints the practice note. The second line prints the todo list. The third line prints the report. Each file prints from start to end.
Note
A long file scrolls past too fast with cat, so save cat for short files.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What does cat print?