242 CHAPTER 15 WORKING (Free web hosting music) WITH TEXT FILES
Friday, November 9th, 2007242 CHAPTER 15 WORKING WITH TEXT FILES Let s look at using less to read the OpenOffice.Org README file, which contains information about the current release of the office suite. The file is located at /usr/lib/openoffice2/README, so to use less to read it, type the following: less /usr/lib/openoffice2/README You can scroll up and down within the less display by using the cursor keys. If you want to scroll by bigger amounts of text, you can use the Page Up and Page Down keys. Alternatively, you can use the spacebar and B key, both of which are commonly used by old-hand Linux users for the same function. In addition, the Home and End keys will take you to the start and end of the document, respectively. When using less, keep an eye on the bottom part of the screen, where you ll see a brief status bar. Alongside the filename, you ll see how many lines the document has and which line you re currently up to. In addition, you ll see as a percentage the amount of document you ve already read through, so you ll know how much is left to go. less lets you search forward through the file by typing a slash (/), and then entering your search term. Any words that are matched will be highlighted on screen. To repeat the search, type n. To search backward in a file from your current point, type a question mark (?). To quit less, simply type q. Although it s supposedly a simple program, less is packed with features. You can see what options are available by reading its man page or by typing less –help. Using the head and tail Commands A couple of other handy commands that you can use to view text files are head and tail. As their names suggest, these let you quickly view the beginning (head) of a file or the end (tail) of it. Using the commands is simple: tail mytextfile or head mytextfile By default, both commands will display ten lines of the file. You can override this by using the -n command option followed by the number of lines you want to see. For example, the following will show the last five lines of mytextfile: tail -n5 mytextfile These two commands are very useful when viewing log files that might contain hundreds of lines of text. The most recent information is always at the end, so tail can be used to see what s happened last on your system, as shown in the example in Figure 15-1. Although they re powerful, all of these shell commands don t let you do much more than view text files. If you want to edit files, you ll need to use a text editor such as vi.