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.    

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s