head
the start of a filehead prints the beginning of a file and stops. It is how you look at what a file contains without printing all of it, and at the end of a pipe it cuts long output down to the first few lines.
A glance at the top is usually enough to know what kind of file you are holding.
At the terminal
Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.
What the numbered lines are telling you
Three lines are enough to see the columns and the shape of the data without scrolling through the rest.
ls -t lists newest first; head -1 keeps only the first line. Together: the most recently changed file.
-n -1 means "everything except the last line". The file has 121 lines, so 120 are passed on.
Switches
A switch changes how the command behaves. These are the ones used day to day; man head lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.
-n NUM- Print the first NUM lines instead of 10.
-n -NUM- Print everything except the last NUM lines.
-c NUM- Print the first NUM bytes.
-q- Do not print a header with the file name when given several files.
Variations worth knowing
The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.
head -c 100 file.binPrints the first 100 bytes rather than lines.
head -n 5 *.logPrints the start of several files, each under a header with its name.
head -n 20 app.log | tail -n 5Prints lines 16 to 20.
dmesg | headShows just the start of a long output.
In cybersecurity
Looking at the start of a file is a safe way to identify it before trusting it.
A file named invoice.pdf that begins with "MZ" or "#!/bin/sh" is a program, not a document. head -c 16 piped to xxd shows the first bytes.
The first lines of an install script show its interpreter and intent. Read the whole thing before piping it to a shell.
When checking that a key file exists and looks right, head -1 shows the header line without putting the key on screen.