The blog provides Network Security Tips, Tricks, How To/Procedures. Products and areas not limited to Firewalls, Security, Check Point, Cisco, Nokia IPSO, Crossbeam, SecurePlatform, SPLAT, IP Appliance, GAiA, Unix/Linux.

Linux/Unix - Print The First 10 Lines of Each File

In Linux/Unix/GNU based system, "head <file-name>" command will print the first 10 lines of each file.


Syntax:

head <file-name>


Usage:

head [OPTION]... [FILE]...

With more than one FILE, precede each with a header giving the file name.
With no FILE, or when FILE is -, read standard input.

Mandatory arguments to long options are mandatory for short options too.
  -c, --bytes=[-]N         print the first N bytes of each file;
                             with the leading `-', print all but the last
                             N bytes of each file
  -n, --lines=[-]N         print the first N lines instead of the first 10;
                             with the leading `-', print all but the last
                             N lines of each file
  -q, --quiet, --silent    never print headers giving file names
  -v, --verbose            always print headers giving file names
      --help     display this help and exit
      --version  output version information and exit

N may have a multiplier suffix: b 512, k 1024, m 1024*1024.



Example:

!! One file example !!

Linux# head myfile1
myfile1-example-line1
myfile1-example-line2
myfile1-example-line3
myfile1-example-line4
myfile1-example-line5
myfile1-example-line6
myfile1-example-line7
myfile1-example-line8
myfile1-example-line9
myfile1-example-line10
Linux#


!! Multiple files example !!

Linux# head myfile1 myfile2
==> myfile1 <==
myfile1-example-line1
myfile1-example-line2
myfile1-example-line3
myfile1-example-line4
myfile1-example-line5
myfile1-example-line6
myfile1-example-line7
myfile1-example-line8
myfile1-example-line9
myfile1-example-line10

==> myfile2 <==
myfile2-example-line1
myfile2-example-line2
myfile2-example-line3
myfile2-example-line4
myfile2-example-line5
myfile2-example-line6
myfile2-example-line7
myfile2-example-line8
myfile2-example-line9
myfile2-example-line10
Linux#



Linux/Unix - Print The First 10 Lines of Each File Linux/Unix - Print The First 10 Lines of Each File Reviewed by Admin on 07:04:00 Rating: 5