home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 25.14 How to Look at the End of a File: tail Chapter 25
Showing What's in a File
Next: 25.16 How to Look at a File as It Grows
 

25.15 Finer Control on tail

What if you need to look at the last 11 lines of the file? The command tail - n shows the final n  lines. The command tail + n discards the first n -1 lines, giving you line n and everything that follows it.

You can also tell tail to count the number of characters or the number of 512-byte blocks. To do so, use the -c option (count characters) or the -b option (count blocks). If you want to state explicitly that you're interested in lines, give the -l option.

NOTE: tail is one of the UNIX programs that likes its arguments to be smashed together. In other words, if you want to look at the last three blocks of a file, give the command tail -3b . If you give the command tail -3 -b , tail will happily assume that you want to look at the file -b . This also applies to the -f option, which we'll discuss a bit in article 25.16 . For example, the command tail -4b mail.txt dumps the last 2048 bytes (four blocks, each 512 bytes) of my mail.txt file to the screen.

Many versions of tail also have a -r option that shows the file in reverse order, starting from the last line. (Also see article 25.19 .)

Some versions of UNIX may limit the maximum number of lines that tail , especially tail -r , can display.

- ML


Previous: 25.14 How to Look at the End of a File: tail UNIX Power Tools Next: 25.16 How to Look at a File as It Grows
25.14 How to Look at the End of a File: tail Book Index 25.16 How to Look at a File as It Grows

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System