Printing Out a File With cat

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.