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.
Comments - most recent first
(Please feel free to answer questions posted by others!)
$./ShellScriptName filename first-line last-line
How would I make this work for example:
./ShellScriptName filename 5 10 - will output lines 5 through 10 of the file. cheers!
I am trying to use tail to grab the last line of the customerinfo.dat file for the highest CustomerID and set a varible for that CustomerID number. Basically, I need to see if customerinfo.dat exists. If the file exists, then search the file for the last customerID, add 1 to that number to start creating a new customer. If that customerinfo.dat file does not exist, then it will set the CustomerID field to 1. Any help? I am a real newb to this.
This displays correctly using the more command. Using head or cat it displays backupbanner.good100666 000350 000001 00000001031 and a lot more gobbly gook.
Its all short and sweet.. Thanks buddy..
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.
NO SPAM! If you post garbage, it will be deleted, and you will be banned.
Copyright © by -
All rights reserved - Redistribution is allowed only with permission.