Head and Tail in Shell

Level 240 keystrokes

head and tail show the first and last lines of a file respectively.

Shell code

# head prints lines 1-5, then (&&: only if head succeeded) tail prints the last 5
# For a 100-line file the output is Line 1-5 followed by Line 96-100
1head -n 5 file.txt && tail -n 5 file.txt

Output

Line 1
Line 2
Line 3
Line 4
Line 5
Line 96
Line 97
Line 98
Line 99
Line 100
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Shell code and how often they appear.

  • -× 2
  • .× 2
  • &× 2

More Shell examples at level 2

← Shell typing practice