If you wish to ignore lines at the start of output or in the beginning of a
file, you can use the more
command to do so. E.g., suppose I have a text file named fruit.txt
that contains the following lines:
apple banana clementine date eggplant fig grape
On a Linux,
Unix, or
OS X/macOS
system, if I want to see all lines of the file but the first one, I can use
the +n
, where n is a number, argument to the
more
command. In this case, I can use more +2 fruit.txt
to start the output at the second line in the file.
$ more +2 fruit.txt banana clementine date eggplant fig grape $
If I wanted to ignore the first four lines and start output at the fifth
line, I could use more +5
.
$ more +5 fruit.txt eggplant fig grape $
The more command found on Microsoft Windows systems treats the number you supply differently.
+n Start displaying the first file at line n
E.g.:
C:\Users\Public\Documents>type fruit.txt apple banana clementine date eggplant fig grape C:\Users\Public\Documents> C:\Users\Public\Documents>more +2 fruit.txt clementine date eggplant fig grape C:\Users\Public\Documents>more +5 fruit.txt fig grape C:\Users\Public\Documents>
On a Windows system, I need to consider the first line to be line zero.
C:\Users\Public\Documents>more +0 fruit.txt apple banana clementine date eggplant fig grape C:\Users\Public\Documents>more +1 fruit.txt banana clementine date eggplant fig grape C:\Users\Public\Documents>
On a Linux, Unix, or OS X system, if I only wanted to see the first line, I
could use the head command,
instead. A -n
argument followed by the number of lines from the
beginning of the file can be specified as shown below:
$ head -n1 fruit.txt apple $ head -n2 fruit.txt apple banana $
I could also use head -1
, omitting the n
as well.
I could also use the
tail command to ignore the
first 4 lines in the file, if I knew the number of lines in the file, which
can be determined with the wc
command. As with the head command, a -n
argument can be used, but
this time the number specified is the number of lines to be displayed from the
end of the file backwards. E.g.:
$ wc -l fruit.txt 7 fruit.txt $ tail -n 3 fruit.txt eggplant fig grape $