Linux Classes
Share This With a Friend  
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
(Please feel free to answer questions posted by others!)

sohail     (20 Sep 2016, 02:41)
Hi ,

Tail -f /var/log/messages

What does the above command accomplish ?

Thanks
Sohail.

I welcome your comments. However... I am puzzled by many people who say "Please send me the Linux tutorial." This website *is* your Linux Tutorial! Read everything here, learn all you can, ask questions if you like. But don't ask me to send what you already have. :-)

NO SPAM! If you post garbage, it will be deleted, and you will be banned.
*Name:
Email:
Notify me about new comments on this page
Hide my email
*Text:
 
 


Ask Bob Rankin - Free Tech Support


Copyright © by - Privacy Policy
All rights reserved - Redistribution is allowed only with permission.