Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 36 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
36
Dung lượng
2,65 MB
Nội dung
PRINT A FILE ON A POSTSCRIPT PRINTER ⁄ Type enscript and a space. ¤ Type the name of a file and press Return. ■ The printer prints the file. PRINT AN UNDERLAY ⁄ Type enscript underlay=. ¤ Type the underlay text in single quotes, and a space. ‹ Type the name of the file and press Return. ■ The printer outputs the file with the text running diagonally beneath it. WORK WITH TEXT 4 Additional options in the lpr and enscript commands give you even greater control over the appearance of your printed page. The -o option of lpr allows you to set specific printing options. -O OPTION PRINT EFFECT -o landscape Print in landscape, or wide, mode. -o media=Legal Print on legal-sized paper. -o media=A4 Print on A4, European standard, paper. -o number-up=2 Print two pages per sheet of paper. -o number-up=4 Print four pages per sheet of paper. -o number-up=8 Print eight pages per sheet of paper. -o number-up=16 Print sixteen pages per sheet of paper. -o prettyprint Print a header with the date and filename. The enscript command has even more options that you can use to generate or print PostScript output. For a more complete list, see the manual page for the enscript command by typing man enscript. 59 04 53730X Ch04.qxd 3/25/03 8:56 AM Page 59 OPEN A FILE WITH PICO ⁄ Type pico and a space. ¤ Type the name of a text file and press Return. ■ The Pico editor opens the file and displays it for you. ■ This area displays the filename. ■ This area displays the document. ■ This area displays Pico commands. Y ou can edit text files with Pico, a basic and easy-to-use text editor. The function of a text editor is to enable you to open, edit, and save plain-text files. Mac OS X provides several text editors for this purpose. Text editors are less complex than word processors; they do not allow you to select fonts, layouts, or other factors that affect the look of the printed page. Three shell editors come with Mac OS X; they are Pico, vi, and emacs. Although they accomplish the same basic task of editing text, each one has its own strengths and limitations. Pico is the simplest to use, because all keystroke commands appear on-screen, and there are not many to learn. Because of its simplicity, Pico is a good choice for new users of the Mac OS X shell as well as experienced users who need to do simple text editing. You start the Pico editor by typing pico at the command prompt, along with an optional filename as an argument. If the filename argument exists and is a text file, Pico opens the file for editing; if it does not exist, you start with a blank file. The list of Pico commands appears at the bottom of the screen. A caret (^) before a letter means that you need to hold down the Control key while typing a key. For example, the notation ^X stands for Control + X. You can use your keyboard to easily move around in a Pico document. You use the arrow keys to move to the position you want to insert text, and then start typing. You use the delete key to erase text to the left of the cursor. OPEN A FILE WITH PICO UNIX FOR MAC 60 OPEN A FILE WITH PICO 05 53730X Ch05.qxd 3/25/03 8:56 AM Page 60 ENTER TEXT IN PICO ⁄ Position the cursor where you want to enter text. ¤ Type the text you want to add. ■ Pico inserts your text at the cursor. WORK WITH TEXT EDITORS 5 The basic keystrokes for Pico appear on-screen. The function of each keystroke is not immediately obvious, so this table summarizes the most useful Pico commands. Many of these commands are not intuitive, but the mnemonics may help. For example, to view the help screen you would press Control + G, not Control + H, so you might think of the command as getting help. KEYSTROKE MNEMONIC FUNCTION ^C Current location Display the location of the cursor. ^D Delete Delete the character under the cursor. ^G Get help Display the program help screens. ^J Justify Reformat a paragraph. ^O write Out Save the current file. ^R Read file Insert the contents of another file. ^X eXit Quit Pico; save if necessary. ^W Where is Find text in the current file. ^V - Scroll down a page. ^Y - Scroll up a page. 61 05 53730X Ch05.qxd 3/25/03 8:56 AM Page 61 FIND TEXT IN PICO ⁄ Press Control + W. ■ The search menu appears. ¤ Type the text you want to find and press Return. ■ Pico moves the cursor to the text. Y ou can edit text in the Pico editor, performing basic tasks such as finding specific text or saving a file. Pico is based on the text-editing functions of the Pine e-mail program, a shell application that allows you to compose, send, and read e-mail. You can learn more about installing and using the Pine e-mail program in Chapter 13. If you edit a file with long lines, Pico does not automatically wrap the lines of text to fit the size of the window. Instead, Pico shows a dollar sign ($) at the right side of the Terminal window for each line that extends beyond the width of the window. You can view those lines by moving the cursor up or down with the arrow keys, and then using the right and left arrows to move through the line. The Pico text editor has several command-line options that you can use when starting the editor. The -f option activates the function keys, although you should note that only the first four keys, F1 through F4, work in Mac OS X. The -v option opens a file in read-only mode, which means that you cannot make any changes in the file. The most useful Pico editing commands are those that find and modify text, save a file, and then allow you to exit the text editor. For example, to locate a phrase or word, you can press Control + W. Saving a file is the same as writing an output file, so you can use the Control + O command to save your work. If you do not save your file, and you press Control + X, Pico asks you whether you want to save the file. EDIT A FILE WITH PICO UNIX FOR MAC 62 EDIT A FILE WITH PICO 05 53730X Ch05.qxd 3/25/03 8:56 AM Page 62 SAVE A FILE WITH PICO ⁄ Press Control + O. ■ The Pico editor prompts you with the current filename. Note: You can change the filename by using the Delete key or adding text. ¤ Type the name of the file and press Return. ■ Pico saves the file. QUIT PICO ⁄ Press Control + X. ■ The Pico editor asks whether you want to save your file. ¤ Type y to save your file or n to exit without saving. ■ The Pico editor exits. WORK WITH TEXT EDITORS 5 You can move text within your file by using the cut-and-paste functions of Pico. Pico uses keyboard commands to mark, copy, delete, and move sections of text. Pico does not allow you to export text to other applications. To cut a section of text in Pico, move the cursor to the start of the text you want to cut by using the arrow keys. Press Control + Shift + 6. Pico marks the beginning of the text block that you want to select by highlighting it in black. Using the arrow keys, move the cursor to the end of the text selection and press Control + K. Pico cuts the block from the file. This is an easy way to delete large sections of text. To paste text into a new location, use the arrow keys to position the cursor where you want to move the deleted text and press Control + U. This command uncuts, or pastes, the text. 63 05 53730X Ch05.qxd 3/25/03 8:56 AM Page 63 EDIT A FILE IN VI ⁄ Type vi and a space. ¤ Type the name of a text file and press Return. ■ The vi editor opens and displays the file. ■ This area displays the filename. ■ This area displays the document. ‹ Press Control + Shift + X to exit the file. Y ou can use the vi editor to edit text files. The vi editor is more powerful than Pico and can perform many more text-editing functions. The name vi is short for visual; vi is a visual editor because you can edit the files on- screen as you see them, as opposed to using the command line as you would with sed, a stream editor. To begin using the vi editor, you can type vi at the command prompt with an optional filename argument: vi file-name If you do not specify a filename, the vi editor creates a temporary file for you and opens that temporary file for editing. The name of the temporary file consists of a seemingly random series of characters and numbers; a sample filename with the full path would be /tmp/vi.Y8pi7R, because vi stores temporary files in the /tmp directory. When vi displays a file, lines that are longer than the width of the Terminal screen continue on the next line. The vi editor breaks lines at the edge of the screen, which means that the first half of a word may appear at the end of one line, with the other half beginning on the next line. The word itself is still intact and whole; vi simply displays it this way for editing purposes. The vi editor automatically uses the full Terminal window. If there are additional lines on the screen that vi does not use to display the file, a tilde (~) appears at the beginning of each of these lines. These are not part of your file; they simply indicate the end of the content of the file. OPEN A FILE WITH VI UNIX FOR MAC 64 OPEN A FILE WITH VI 05 53730X Ch05.qxd 3/25/03 8:56 AM Page 64 CREATE A NEW FILE WITH VI ⁄ Type vi and a space. ¤ Type the name of a new document and press Return. ■ The vi editor starts and displays an empty file. ■ Tilde symbols indicate the end of the file. WORK WITH TEXT EDITORS 5 You can change the behavior of the vi editor by setting editor options. You do this by typing a colon (:), the word set, a space, and then the option name. For example, to turn on line numbers, type :set number.To turn off an option, type a colon, the word set, a space, the word no, and then — with no space before it — the name of the option. For example, to turn off line numbers, you type :set nonumber. OPTION FUNCTION autoindent Automatically indent new lines. list Display a $ symbol to indicate the end of each line. number Display line numbers on the left. ruler Display the current line number and character position. showmode Show the current mode, for example, insert, in the lower right corner. verbose Use wordy and informative warnings and messages. You can see which options are currently set if you type :set and press Return. For a full list of all vi editor options, type :set all. 65 05 53730X Ch05.qxd 3/25/03 8:56 AM Page 65 MOVING IN VI ⁄ With vi in Command mode, press Shift + H to move to the start of the file. ¤ Press Shift + G to move to the end of the file. ‹ Press Shift + 6 to move to the beginning of a line. › Press Shift + 4 to move to the end of the line. Y ou can use single keystroke commands to move through a file in the vi editor. One feature that distinguishes the vi editor from the other visual editors is the concept of modes. The vi editor is always in one of two states, Command mode or Input mode. Command mode allows you to use keystroke commands to delete lines, move text, or save files. Input mode allows you to type text into the document at the location of the cursor. While in Command mode, you can use keystroke commands to change to Input mode. The Command-mode keystrokes in the vi editor are usually a single letter, and, unlike the Pico editor commands, they are typed without holding down the Control key. However, the keystroke commands are case sensitive, which means that a is a different command than A. You need to use the Shift key, of course, to create the uppercase letters. To move within a document in vi, the application must be in Command mode. The vi editor offers many ways to navigate the content of a file, some of which appear on the facing page. The easiest way is to use the arrow keys to move the cursor, as you would in Pico. You can also use the lowercase letters h, j, k, and l to move the cursor around on-screen. The find command in vi is much like the find command in less. When you type a forward slash (/) and enter the word or phrase you are seeking, the vi editor automatically moves the cursor to the next occurrence of that text. If you type a question mark (?) instead of a forward slash, the search occurs backwards in the file from your current position. MOVEMENT WITHIN VI UNIX FOR MAC 66 MOVEMENT WITHIN VI 05 53730X Ch05.qxd 3/25/03 8:56 AM Page 66 FINDING TEXT IN VI ⁄ Type /. ¤ Type a word or phrase and press Return. ■ The vi editor moves the cursor to that word or phrase. WORK WITH TEXT EDITORS 5 The commands in the table below allow you to move quickly through a file in vi, repositioning the cursor and scrolling the screen when necessary. KEYSTROKE EFFECT H Move to the first line of the file. G Move to the last line of the file. h Move one character to the left. j Move down one line. k Move up one line. l Move one character to the right. ^ Move to the beginning of the current line. $ Move to the end of the current line. w Move ahead one word. /text Find text from the cursor forward. ?text Find text from the cursor backward. 67 05 53730X Ch05.qxd 3/25/03 8:56 AM Page 67 INSERT TEXT ⁄ Position the cursor where you want to enter text. ¤ Type the letter i. ■ The vi editor switches to Input mode. ‹ Type the text you want to insert. › Press Esc. ■ The vi editor switches to Command mode. Y ou can enter text into a document by switching to Input mode in vi. When you start the vi editor, it switches to Command mode by default, allowing you to move through the file or enter keystroke commands. If you try to enter text while in Command mode, you can produce some very strange results, because many characters correspond to keystroke commands in Command mode. It is therefore very important to know which mode you are in before you enter text. The easiest way to determine your current mode is to enable the option showmode. You can do this by typing :set showmode while in Command mode. Your current mode appears in the lower right corner. You can use a number of single keystrokes to switch to Input mode from Command mode. However, there is only one way to switch to Command mode from Input mode, and that is to press the Esc (Escape) key, located on the upper-left corner of most keyboards. If you are not sure which mode you are in, you can press the Esc key to return to Command mode. Pressing the Esc key while in Command mode does nothing, so it is safe to press this key several times to make sure. Many useful command-mode keystrokes appear in the table on the facing page. The most important keystrokes are i, which inserts text at the current cursor location, and o, which opens a new line below the current one and allows you to enter text directly. When you edit the text in your file, vi does not save your changes until you give the command to do so. ENTER TEXT IN VI UNIX FOR MAC 68 ENTER TEXT IN VI 05 53730X Ch05.qxd 3/25/03 8:56 AM Page 68 [...]... LINES OF TEXT ⁄ Position the cursor to the ¤ Press Shift + J ■ The vi editor joins the two lines together first of two lines you want to join 73 05 537 30X Ch05.qxd 3/ 25/ 03 8:56 AM Page 74 UNIX FOR MAC SAVE A FILE WITH VI W hen you finish editing a file with the vi editor, you can save your work It is a good practice to use the save command any time you make changes that you do not want to lose To save the. .. of the file M-> End of buffer Move to the end of the file INSERT TEXT IN EMACS ¤ Type your text directly ⁄ Position the cursor where into emacs ■ emacs adds the text to the file at the insertion point you want to insert text 77 05 537 30X Ch05.qxd 3/ 25/ 03 8:56 AM Page 78 UNIX FOR MAC EDIT A FILE WITH EMACS Y ou can edit and save text files in emacs with keystroke commands that use the Control and Meta... space 80 ■ The prompt changes space ■ The second prompt changes 06 537 30X Ch06.qxd 3/ 25/ 03 8:57 AM Page 81 CUSTOMIZE YOUR SHELL 6 set prompt = '[%m:%c3] %n%# ' is the standard shell prompt in Mac OS X The formatting Code table explains the meanings of these and other special codes FORMATTING CODE EXAMPLE MEANING %c Documents The current directory %d Fri The day of the week %D 06 The day of the month... right parenthesis, and press Return ■ The shell sets your path to ¤ Type a left parenthesis, space the directory list 88 space $path, and a space ■ The shell adds the new directories to your path 06 537 30X Ch06.qxd 3/ 25/ 03 8:57 AM Page 89 CUSTOMIZE YOUR SHELL 6 EDIT YOUR TCSHRC FILE ou can save the commands to set your prompt, your aliases, your shell variables, your environment variables, and your path... the commands to set ■ The text editor opens the ˇ Save the file, and exit the file for editing your preferences editor ■ When you start a new Terminal window, the shell executes the commands in the tcshrc file editor command and a space 89 06 537 30X Ch06.qxd 3/ 25/ 03 8:57 AM Page 90 UNIX FOR MAC RECALL YOUR COMMAND HISTORY Y ou can list the commands that you have typed before by using the history command... underneath the cursor by typing a lowercase x If there is more text on the line, it shifts to the left to fill the space formerly occupied by the deleted character A capital X deletes the character to the left of the cursor DELETE TEXT IN VI DELETE CHARACTERS ⁄ Position the cursor over the character you want to delete 70 ¤ Type the letter x ■ The vi editor deletes the character 05 537 30X Ch05.qxd 3/ 25/ 03 8:56... /sw/bin) set path = ($path /new-directory) $path tells the shell to insert the current value of the path variable before setting the value You type the pathname of the new directory after $path to append it to your path SET YOUR PATH SET PATH TO DIRECTORY LIST ¤ Type a list of directories APPEND TO YOUR PATH ‹ Type a list of directories ⁄ Type set path = and a within parentheses and press Return ⁄ Type set... Beginning of line Move to the start of the current line C-b Backward char Move one character to the left C-e End of line Move to the end of the current line C-f Forward char Move one character to the right C-n Next line Move down one line C-p Previous line Move up one line C-r Search backward Search backward for text C-s Search forward Search forward for text M-< Beginning of buffer Move to the start of the. .. coverage to vi because it is less complex than emacs However, if you do not find vi to your liking or you prefer to use a very flexible and adaptable text editor, the emacs editor is an excellent choice The basic functions of the emacs editor are easy to use To open a file, you can simply give the name of the file as an argument, as with other text editors Unlike vi, emacs does not have different modes for. .. OPEN A FILE WITH EMACS ¤ Type the name of the file ⁄ Type emacs and a space and press Return ■ The emacs editor displays ■ This area displays the ■ This area displays the ■ This area displays the the file filename 76 document status line 05 537 30X Ch05.qxd 3/ 25/ 03 8:56 AM Page 77 WORK WITH TEXT EDITORS 5 The following table is a summary of some of the most useful emacs commands for moving and finding . beginning of each of these lines. These are not part of your file; they simply indicate the end of the content of the file. OPEN A FILE WITH VI UNIX FOR MAC 64 OPEN A FILE WITH VI 05 537 30X Ch05.qxd 3/ 25/ 03. for text. C-s Search forward Search forward for text. M-< Beginning of buffer Move to the start of the file. M-> End of buffer Move to the end of the file. 77 05 537 30X Ch05.qxd 3/ 25/ 03. 537 30X Ch05.qxd 3/ 25/ 03 8:56 AM Page 72 JOIN TWO LINES OF TEXT ⁄ Position the cursor to the first of two lines you want to join. ¤ Press Shift + J. ■ The vi editor joins the two lines together. WORK