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?✗ Incorrect
By default,
head shows the first 10 lines of a file or input.Which command shows the last 15 lines of a file named
data.txt?✗ Incorrect
Use
tail -n 15 data.txt to see the last 15 lines.How do you continuously monitor new lines added to a file
server.log?✗ Incorrect
tail -f server.log shows the last lines and updates as new lines are added.What does
head -n 0 file.txt display?✗ Incorrect
Using
-n 0 means show zero lines, so no output is shown.Which command shows the first 10 lines of standard input?
✗ Incorrect
Running
head without a file reads from standard input and shows the first 10 lines by default.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.