Ad space (banner)
🖥️Linux Lessons
Lesson 17 / 61

Viewing Part of a File with head/tail

head and tail are for when "I just want a quick look at the start or end of a long file." head shows just the beginning of a file, and tail shows just the end.

Use them in the form head filename and tail filename. By default they show 10 lines from the start or end, and the -n option changes how many.

Running head notes.txt shows just the first 10 lines of notes.txt. Handy when displaying the whole file with cat would be too much.

A common early mistake is wanting to see the latest info in a large log file, but reaching for head and only seeing old information. Use tail when you want the most recent entries.

In real work, watching the end of a log file in real time with tail -f is an extremely common technique in server operations.

Linux
Try it (type this into the pseudo terminal)
head notes.txt

🧑‍💻 You can type this command into the Linux pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)