The tail Command


The tail Command

The tail command is simple to remember. If you want to see the tail end of a file, use the tail command. If you want to see the top, use the head command. Now that you know the simplicity in remembering them, let's look at what each does starting with tail.

The tail command is powerful, quick, and simple to use. If you want to see the bottom 10 lines of a file, then you may want to just specify the tail command and the file you want to view the inside of.

 >tail hosts.allow 

Or

 >tail 20 hosts.allow 

The output of this command starts from the bottom up and displays (by default) 10 lines from the bottom up. If you specify the amount of lines you want to see, count the amount of lines from the bottom up and that is what you will view.

The inverse of this command is the head command. As mentioned earlier, the head is the top and you want to use the head command to show you the beginning of the file.

The head Command

In some instances you may need to see the top of a file just like you may have needed to see the bottom of a file. To use the head command, do the same as you would with the tail command.

 >head hosts.allow 

Or

 >head 20 hosts.allow 

The output of this command starts from the top down (not the bottom up) and displays (by default) 10 lines from the top down instead of the bottom up.

Heads or Tails? Let's Flip for It! A good tip to remember when using head and tail is that when you are changing the default number of lines shown from 10, specify the amount of lines you do want to see. This can be done with the -# option that we just previously touched on.

Remember, you can always use the help command or man pages to learn more about any command on your Unix system. If you'd like to change the number of lines that are displayed by default, you can override it with the use of -#. In this command, # is the number of lines you would like to view.


That wraps up our lesson on using the shell prompt to read files. There are more commands and options you can use, but as with anything in Unix, the amount you can do just keeps expanding as you open new doors. For a book this size, we have to cap what is covered to some degree. Make sure not to forget that Lesson 2, "Getting Help," shows you how to gather help. Continue to build up your skill level and experience using Unix. For file management, make sure you know how to read files using cat, more, less, head, and tail.



    SAMS Teach Yourself Unix in 10 Minutes
    Sams Teach Yourself Unix in 10 Minutes (2nd Edition)
    ISBN: 0672327643
    EAN: 2147483647
    Year: 2005
    Pages: 170

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net