Lesson 5 of 17
Reading Files
Displaying File Contents
cat (short for concatenate) reads one or more files and prints their contents to the screen.
Basic Usage
cat hello.txt
If hello.txt contains Hello, Linux!, the output is:
Hello, Linux!
Reading Multiple Files
cat can read multiple files at once, printing them one after another (hence "concatenate"):
cat hello.txt notes.txt
Absolute Paths
You can always give an absolute path:
cat /etc/hosts
Output:
127.0.0.1 localhost
::1 localhost
The /etc/hosts file maps hostnames to IP addresses. It is one of the most commonly viewed system files.
Other File Viewing Commands
For large files, cat dumps everything at once. Alternatives:
head file— print just the first 10 linestail file— print just the last 10 linesless file— interactive pager (scroll up and down)
Your Task
Read the contents of hello.txt using cat.
Linux shell loading...
Loading...
Click "Run" to execute your code.