Printing Out a File With cat

NOTE: this website is under construction for the new quarter. Please pardon our dust! The content of this website is subject to change as we put together resources for the new quarter. If you are a student who took the course last quarter, you should visit last quarter's class web site instead, accessible by visiting this link.

Written by Chris Gregg, with modifications by Nick Troccoli

Click here for a walkthrough video.

The cat command ("concatenation") is a simple command that prints files to the terminal, one after the other. We normally use it for a single file, and it is a quick way to see inside a file without opening an editor. Here is an example:

$ cat hello.c
#include<stdio.h>
#include<stdlib.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}
$

You can also use cat to print multiple files, e.g.,

cat file1 file2 file3

Another command, more, is similar to cat, but instead of displaying the entire file in one go, more lets you scroll through it. You can use these keystrokes to scroll:

  • space to scroll down
  • b to scroll up (b stands for "backward")
  • q to quit
  • / to open a search box at the bottom of the screen. After typing the word that you are looking for, its occurrences will be highlighted. Use n and p to jump to the next and previous occurrence of the word.