Viewing File Endings with tail


Viewing File Endings with tail

Occasionally, you might also need to use tail, which displays the last lines of a file. tail is particularly handy for checking footers or for updating information in a footer (see Code Listing 6.5). Just as with head (described in the previous pages), tail offers several options for viewing files.

Code Listing 6.5. tail lets you check out just the end of files.

[ejr@hobbes manipulate]$ tail honeydo Empty diaper pails Take garbage out. End of today's list Buy more garbage bags Get cleaning supplies at store Take cat to vet Fix lawnmower [ejr@hobbes manipulate]$

To view file endings with tail:

  • tail honeydo

    At the shell prompt, type tail followed by the filename. As Code Listing 6.5 shows, you'll see the last ten lines on the screen.

To view a specified number of lines:

  • tail -15 honeydo

    Here, all you do is add a specific number of lines you want to view (-15).

To view the endings of multiple files:

  • tail honey* | more

    Pipe the tail command and the files (multiple files indicated with *) to more (Code Listing 6.6).

Code Listing 6.6. Use tail with more to see the ends of multiple files.

[ejr@hobbesmanipulate]$ tailhoney*|more ==> honeyconsider <== Cat mess in entry to clean up Cat mess in living room to clean up Toddler mess in family room to clean up Cat and toddler mess in den to clean up IRS called again today Neighbors on both sides looking for donations           for the annual fund drive Boss called last Friday and said it's urgent -End of today's list- ==> honeydo <== Empty diaper pails Take garbage out End of today's list Buy more garbage bags Get cleaning supplies at store Take cat to vet Fix lawnmower More 

Tip

  • head and its counterpart, tail, are great for splitting long files. Use wc -l to count the lines. If the file has 500 lines, but you care about only the beginning and ending lines, then type head -25 filename > newfilename to put the first 25 lines of the file into a new file. Then do the same with tail to put the last 25 lines of the file into another new file.





Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

Similar book on Amazon

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