Linux Classes
Linux Training
* Linux Classes *

LINUX CLASSES - DATA MANIPULATION

Heads or Tails?

The head command displays the first few lines at the top of a file. It can be useful when you want a quick peek at a large file, as an alternative to opening the file with a text editor. By default, head will show the first ten lines of a file, but you can also tell it how many lines to display. Here are a couple of examples:


head some.file Show first ten lines of some.file.

head -5 some.file Show first five lines of some.file.

The tail Command

The tail command displays the last few lines of a file. Like head, it can save you time, because it's a lot quicker than calling up a file with a text editor and scrolling all the way down to the bottom. By default, tail will show the last ten lines of a file, but you can also tell it how many lines to display:



tail some.file Show last ten lines of s ome.file.
tail -3 some.file Show last three lines of some.file.

Here's a practical example of how to use the tail command. Many Linux programs put diagnostic messages in the /var/syslog/messages file when they run, so this file can get pretty large after a while. To see if your most recent command issued any messages, look at the tail end of this file by entering the tail /var/syslog/messages command.

For more information on the head command, see the head manual.

For more information on the tail command, see the tail manual.

Previous Lesson: Slicing & Dicing
Next Lesson: Sorting Data

[ RETURN TO INDEX ]

Comments (most recent first)

Bob Rankin     (25 Aug 2010, 14:44)
@Abhilash - Thanks! I'll be waiting for you to send your updates. How soon should I expect the "full info"?
Abhilash     (25 Aug 2010, 01:40)
Thanq but u have not given full info about it
raghu     (10 Aug 2010, 07:24)
how to print 1st 10 lines using telnet command
deepak pandey     (03 May 2010, 20:52)
how many lines selected in head & tail command
Sam     (26 Apr 2010, 22:12)
There could be a empty line at the end of the file
Deepak Soni     (15 Apr 2010, 02:11)
When i using the tail command as
tail -1 "file_name". then it not show on the telnet screen. and using the command as
tail -2 "file_name". then it shows the last line of the file. why it not show the last line with tail -1 "file_name". please reply.
R.L.     (10 Apr 2010, 08:19)
Thanks a lot, this pages on Linux data manipulation helped me with my university's exam project.
Bob Rankin     (02 Apr 2010, 15:40)
Okay, let's play a mail game. You send me $1000 through mail, and then I'll guide you about command!
Gagandeep Singh     (01 Apr 2010, 23:29)
Guide me about command through mail...

*Name:
Email:
Notify me about new comments on this page
Hide my email
*Text:
 

Ask Bob Rankin - Free Tech Support
<Send This Link to a Friend>         <Bookmark This Page>


Copyright © by Bob Rankin
All rights reserved - Redistribution is allowed only with permission.