---
layout: page
author: Agostino Monti
category-page: advanced
category-title: Advanced commands
tags: head tail text file
title: head-tail
---
head
The head
command reads the first few lines of any text given to it as an input
and writes them to standard output.
If more than one input file is provided, head will return the first ten lines
from each file, precede each set of lines by the name of the file and separate
each set of lines by one vertical space.
tail
The tail command is similar to the head command except that it reads the final lines in files rather than the first lines.
head file1.txt
head file1.txt file2.txt
tail fail1.txt
-n
option can be used followed by an integer indicating the number of lines desired.
-n is a very tolerant option, it is not necessary for the integer to directly
follow it without a space in between. In fact, the letter n does not
even need to be used at all. Just the hyphen and the integer
(with no intervening space) are sufficient to tell head how many lines to return.
head -n15 file1.txt
head -n 15 file1.txt
head -15 file1.txt
ls | head