0
0
Linux CLIscripting~10 mins

head and tail in Linux CLI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the command to display the first 5 lines of a file named 'log.txt'.

Linux CLI
head -n [1] log.txt
Drag options to blanks, or click blank then click option'
A20
B10
C5
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using -n 10 shows 10 lines instead of 5.
Forgetting the -n option.
2fill in blank
medium

Complete the command to display the last 3 lines of a file named 'data.csv'.

Linux CLI
tail -n [1] data.csv
Drag options to blanks, or click blank then click option'
A5
B3
C10
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using -n 5 shows 5 lines instead of 3.
Confusing head with tail.
3fill in blank
hard

Fix the error in the command to show the first 8 lines of 'report.txt'.

Linux CLI
head [1] 8 report.txt
Drag options to blanks, or click blank then click option'
A-n
B-c
C-l
D-f
Attempts:
3 left
💡 Hint
Common Mistakes
Using -c which shows bytes instead of lines.
Using -f which follows the file continuously.
4fill in blank
hard

Fill both blanks to create a command that shows lines 5 to 10 of 'file.txt' using head and tail.

Linux CLI
head -n [1] file.txt | tail -n [2]
Drag options to blanks, or click blank then click option'
A10
B5
C6
D15
Attempts:
3 left
💡 Hint
Common Mistakes
Using head -n 6 instead of 10.
Using tail -n 5 instead of 6.
5fill in blank
hard

Fill all three blanks to create a command that shows lines containing 'error' (case-insensitive) from the last 4 lines of the first 20 lines of 'access.log'.

Linux CLI
head -n [1] access.log | tail -n [2] | grep -i [3]
Drag options to blanks, or click blank then click option'
A20
B4
C"error"
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong numbers for head or tail options.
Forgetting quotes around the grep pattern.