June 14, 2026 · by Meegrow Labs

The head Command in Linux: Peek at the Top of Any File

Picture a log file with ten thousand lines in it. You don’t want all of it scrolling past your eyes for two minutes. You just want a quick taste — the first few lines, to see what’s going on inside.

That tiny peek is exactly what one terminal command gives you, and it is one of the friendliest tools a beginner can learn. In this lesson we’ll meet the head command in Linux and use it to glance at the top of a file in a blink.

The head command in Linux shows you only the first few lines of a file (10 by default), so you can preview a big file instantly instead of opening the whole thing. You just type head, a space, and the file name.

What is the head command in Linux?

Think of a newspaper. You read the headline first to decide if the story matters to you. You don’t read every page — the top tells you plenty.

head works the same way. It means “show the top”, just like the top of your body. Instead of dumping the entire file into your terminal, it prints only the opening lines so you get the gist fast.

How do I use it?

The command has two simple parts. The first is the command itself, and the second is the file you want to peek into. Put them together like this:

head log.txt

Here, head is the command (“show the top”) and log.txt is the file — maybe a really big one. Run it, and only the first lines appear. No waiting, no endless scrolling, just a clean little preview.

Why does this help?

Big files are slow to open in full. If you open a giant log in a normal editor, you wait while your computer loads every single line. Most of the time you don’t need that.

The start of a file usually tells you enough — the format, the first few entries, whether you opened the right file at all. head gives you that start instantly, which makes it perfect for a fast check before you do anything heavier.

Can I try it right now?

Yes, and you should. Open a terminal and type:

head log.txt

Watch only the top lines show up. If you don’t have a file called log.txt handy, try head on any text file you already have — the idea is the same. That little preview is the start of your file, served in a flash.

This is one small step in a much bigger journey. We start with simple terminal foundations like this because they’re what let you truly command AI tools later. You can follow the whole path for free in the free Zero to AI Hero course, where each short lesson builds on the last.

Key takeaways

  • The head command in Linux prints only the first lines of a file (10 by default) so you can preview it instantly.
  • The format is simple: head + a space + the file name, like head log.txt.
  • Think of it as reading a newspaper headline — the top usually tells you enough.
  • It’s perfect for big files that are slow to open in full.
  • In the last lesson we learned about looking inside files; next up is peeking at the end of a file instead of the top.

🚀 Take the full free course: Zero to AI Hero — learn to build with AI from scratch. New lessons daily, in Hindi & English.

Meegrow Labs

We help India go from zero to AI hero — learn to use & build with AI from scratch, in Hindi & English. Start the free course →

Want to actually learn this?

151 free 2-minute lessons — from "what's a file?" to building with AI.

▶ Start the free course