RSS Subscription
Linux Howtos & Tutorials

Enter your email:

Delivered by


NOTE:New tutorials are from LinuxCareer.com

Poll

Do you own or wish to have iPhone?
 


Linux eBooks FREE Download
A guide to programming Linux kernel modules
Introduction to Linux - A Hands on Guide
A Newbie's Getting Started Guide to Linux

Linux from Scratch - Create Your Own Linux System - Free eBook

Linux: The Hacking Solution (v.3.0)

SQLite 3 with PHP Essential Training – Free Video Training Tutorials

This guide will introduce you to the world of GNU/Linux

The GNU/Linux Advanced Administration

A Complete Beginner's Manual for Ubuntu 10.04 (Lucid Lynx)

Advanced Bash-Scripting Guide

Set up, maintain, and secure a small office email server

Partner Linux Sites:
How-To.LinuxCareer.com
Jobs.LinuxCareer.com
TuxMachines
Monsterb
LinuxBloggers
AdamsInfo
LinuxScrew
All For Linux

head

Article Index
1. Name
2. Synopsis
3. Frequently used options
4. Examples

1. Name

head [man page] - output the first part of files

2. Synopsis

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

3. Frequently used options

-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 

4. Examples

Command head will by default print first 10 lines of a file. Lets prove it by creating test file from /etc/services which contains line numbers.

$ cat /etc/services | nl > /tmp/services.txt 

head command - create test file

$ head /tmp/services.txt 

head command - print first 10 lines of a file
with -n option we can instruct head command to print line numbers.

$ head -n /tmp/services.txt 

head command to print line numbers
make head command to print first 5 lines:

$ head -5 /tmp/services.txt 

head command to print first 5 lines
Same as with option -n with option -c we can print out number of bytes to the standard output. Lets do small test:

$ wc -l -c services.txt
$ head -c 22173 /tmp/services.txt | wc -l

head command to print number of bytes

Share this linux post:

Submit head in Delicious Submit head in Digg Submit head in FaceBook Submit head in Google Bookmarks Submit head in Stumbleupon Submit head in Technorati Submit head in Twitter
 
Comments for this page are closed !!!
Please visit our new Linux Forum for additional help or discussion.


Linux eBooks FREE Download