0
0
Linux CLIscripting~5 mins

head and tail in Linux CLI - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the head command do in Linux?
The head command shows the first few lines of a file or input. By default, it shows the first 10 lines.
Click to reveal answer
beginner
How do you use tail to see the last 5 lines of a file named log.txt?
Use tail -n 5 log.txt. This shows the last 5 lines of the file log.txt.
Click to reveal answer
beginner
What option do you use with head or tail to specify the number of lines?
Use the -n option followed by the number of lines you want to see. For example, head -n 3 file.txt shows the first 3 lines.
Click to reveal answer
intermediate
How can tail be used to watch a file as it grows?
Use tail -f filename. This shows the last lines and keeps updating the output as new lines are added, like watching a live log.
Click to reveal answer
beginner
If you want to see the first 20 lines of a file, which command would you use?
You would use head -n 20 filename to see the first 20 lines of the file.
Click to reveal answer
What is the default number of lines shown by the head command?
A10
B5
C20
D15
Which command shows the last 15 lines of a file named data.txt?
Ahead -n 15 data.txt
Btail -15 data.txt
Chead -15 data.txt
Dtail -n 15 data.txt
How do you continuously monitor new lines added to a file server.log?
Ahead -f server.log
Bhead -n server.log
Ctail -f server.log
Dtail -n server.log
What does head -n 0 file.txt display?
ANo lines
BThe first line
CThe entire file
DThe last line
Which command shows the first 10 lines of standard input?
Atail
Bhead
Chead -n 20
Dtail -n 10
Explain how you would use head and tail to view parts of a file.
Think about how you check the start or end of a long list or log.
You got /4 concepts.
    Describe a real-life situation where tail -f would be useful.
    Imagine you are watching a live scoreboard or chat messages.
    You got /4 concepts.