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.
[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]$ |
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.
tail -15 honeydo
Here, all you do is add a specific number of lines you want to view (-15).
tail honey* | more
Pipe the tail command and the files (multiple files indicated with *) to more (Code Listing 6.6).
[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.