Introduction
In this challenge, you will learn how to use the cat, head, and tail commands in Linux. These commands are used to display the contents of a file, view the beginning or end of a file, and concatenate files.
Using Cat Command
The cat command is used to display the contents of a file. In this step, you will learn how to use the cat command to display the contents of example.txt.
Target
Display the contents of example.txt and store the output in a file named step1.txt.
Result Example
This is an example file.
It contains some text for the Linux challenge.
This is line 3.
This is line 4.
This is line 5.
Requirement
- You need to know how to use the
catcommand. - You need to know about the stream operators
>in Linux.
Using Head Command
The head command is used to display the beginning of a file. In this step, you will learn how to use the head command to display the first 2 lines of example.txt.
Target
Display the first 2 lines of example.txt and store the output in a file named step2.txt.
Result Example
This is an example file.
It contains some text for the Linux challenge.
Requirement
- You need to know how to use the
headcommand. - You need to know about the stream operators
>in Linux.
Using Tail Command
The tail command is used to display the end of a file. In this step, you will learn how to use the tail command to display the last line of example.txt.
Target
Display the last line of example.txt and store the output in a file named step3.txt.
Result Example
This is line 5.
Requirement
- You need to know how to use the
tailcommand. - You need to know about the stream operators
>in Linux.
Using Cat and Head Commands
The cat and head commands can be used together to display a range of lines from a file. In this step, you will learn how to use the cat and head commands to display the lines 3 to 4 of example.txt.
Target
Display the lines 3 to 4 of example.txt and store the output in a file named step4.txt.
Result Example
This is line 3.
This is line 4.
Requirement
- You need to know how to use it in conjunction with the
cat,tailandheadcommand. - You need to know the Linux pipe operators
|. - You need to know about the stream operators
>in Linux.
Using Cat and Tail Commands
The cat and tail commands can be used together to display the end of a file. In this step, you will learn how to use the cat and tail commands to display the last 3 lines of example.txt.
Target
Display the last 3 lines of example.txt and store the output in a file named step5.txt.
Result Example
This is line 3.
This is line 4.
This is line 5.
Requirement
- You need to know how to use it in conjunction with the
catcommand and thetailcommand. - You need to know the Linux pipe operators
|. - You need to know about the stream operators
>in Linux.
Summary
Congratulations! You have completed the challenge of File Viewing. You should now have a better understanding of how to use the cat, head, and tail commands in Linux. You can use these commands to quickly view and manipulate the contents of files in your Linux environment.



