Menu
Coddy logo textTech

Read A File

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

The cat command stands for concatenate. Its most common use 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.

Cheat sheet

The cat command reads and displays the contents of a file in the terminal:

cat readme.txt

Other commands for reading files:

head displays the first 10 lines of a file:

head readme.txt

tail displays the last 10 lines of a file:

tail readme.txt

Use the -n option to specify the number of lines:

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

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