An ad-free and cookie-free website.
Learn to print the top part of a file at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux head Command Summary with Examples (3:38)
Our twenty-seventh word, or command to memorize is
head from our category
head allows you to print the first
lines of a file.
||Print help screen|
||Print the first number of lines specified|
||Print the first number of bytes specified|
Recall from the previous video we counted lines in a file. Now we'll scope out only those we're interested in reviewing.
Before we start, it helps to think of commands as mini programs and
most follow this structure:
command -option(s) argument(s).
head command has
6 options and the argument is the file you'd like to
Like most commands, help is available with double-dash
The default is to print the first 10 lines, and the
-n option allows you to view more or
less than 10. And just like in the last video (tutorial) on
-c and not dash-b, for bytes.
So why is
head an important command?
head helps you get results
And now you know how to do that.
Okay, the best way to embed this in your memory is by typing in your own terminal window.
Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.
Here we go, let's look at the first 10 lines of the file from the
previous video, which was the help screen on the command
See how it prints right to the screen? Pretty easy huh?
Second, let's create a new file here using
head --help and redirect that
to a file called
video27.txt using the redirection
cat that to the screen.
Too much to look at, huh? So let's
the first 17 (lines) using
-n 17 the
And there you go.
And last, we'll print the first, say 220 bytes from the same file,
There we go, just the syntax for the command.
Okay now you know how to use
And you know the syntax for commands, options and arguments.
One last tip about the
head is a quick way to review
the structure of a file, right? Oh, and here's a clue about our next
video, if there's a head then there has to be a blank.
Okay, thanks for visiting today. I hope this was a helpful
introduction to the
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
Learn faster by pairing these web-based tutorials with videos, subscribe at YouTube and follow @factorpad on Twitter for updates.
wccommand, hit Back.
tailcommand, click Next.
A newly-updated free resource. Connect and refer a friend today.