Tuesday, February 9, 2016

How to print the first and last parts of a file in Linux

First part
  1. Open terminal
  2. Type

    head -n {n} {file}
{n} is the number of lines to return
{file} name of the file

Last part
  1. Open terminal
  2. Type

    tail -n {n} {file}
{n} is the number of lines to return
{file} name of the file

Example

Print the first 10 lines of the blogger.log file
head -n 10 blogger.log

Print the last 10 lines of the blogger.log file
tail -n 10 blogger.log

Source: http://linux.die.net/man/1/head
http://linux.die.net/man/1/tail

No comments:

Post a Comment