Menu
Coddy logo textTech

Read A File

Part of the Fundamentals section of Coddy's Terminal journey — lesson 11 of 82.

The cat command is short for concatenate, which means to link things together. While its original purpose was to join files, its most common use today is to read and display the contents of a file directly in the terminal.Simply type cat followed by the filename:

cat readme.txt

The contents of the file will be printed to the terminal immediately.Other useful ways to read files:

head — displays only the first 10 lines of a file:

head readme.txt
tail — displays only the last 10 lines of a file:

tail readme.txt
You can control how many lines to show with the -n option:

head -n 5 readme.txt   # show first 5 lines
tail -n 3 readme.txt   # show last 3 lines
less — opens the file in a scrollable viewer. Press q to quit:

less readme.txt
Note: cat is best for short files. For long files, less is more comfortable to read.
challenge icon

Challenge

Beginner

Use the cat command to read and display the contents of readme.txt.

Hint: Type cat followed by the name of the file you want to read.

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals