♦ ] i J Part Number: 800-3830-10 Revision A, of March 27, 1990 1 SunOS User’s Guide: Getting Started Sun Workstation, Sun Microsystems, and NFS are registered trademarks of Sun Microsystems, Inc. SunView, SunOS, and the combination of Sun with a numeric suffix are unre- gistered trademarks of Sun Microsystems, Inc. UNIX and RFS (Remote File System) are registered trademarks of AT&T Bell Laboratories. All other products or services mentioned in this document are identified by the trademarks or service marks of their respective companies or organizations, and Sun Microsystems, Inc., disclaims any responsibility for specifying which marks are owned by which companies or organizations. Copyright © 1990 Sun Microsystems, Inc. - Printed in U.S.A. All rights reserved. No part of this work covered by copyright hereon may be reproduced in any form or by any means - graphic, electronic, or mechanical - including photocopying, recording, taping, or storage in an information retrieval system, without the prior written permission of the copyright owner. Restricted rights legend: use, duplication, or disclosure by the U.S. government is subject to restrictions set forth in subparagraph (c)(l)(ii) of the Rights in Technical Data and Computer Software clause at DFARS 52.227-7013 and in similar clauses in the FAR and NASA FAR Supplement. The Sun Graphical User Interface was developed by Sun Microsystems, Inc. for its users and licensees. Sun acknowledges the pioneering efforts of Xerox in researching and developing the concept of visual or graphical user interfaces for the computer industry. Sun holds a non-exclusive license from Xerox to the Xerox Graphical User Interface, which license also covers Sun’s licensees. This product is protected by one or more of the following U.S. patents: 4,777,485 4,688,190 4,527,232 4,745,407 4,679,014 4,435,792 4,719,569 4,550,368 in addition to foreign patents and applications pending. Contents Chapter 1 The Keyboard 1 1.1. Keyboard Layout 1 The Return Key 1 The Space Bar and the Tab Key 2 The Delete and Back Space Keys 2 Control Keys 2 Escape Keys or Meta- Keys 3 Chapter 2 A Work Session 5 2.1. Logging In 5 2.2. Changing Your Password 7 Password Aging 8 2.3. Logging Out 8 Chapter 3 Files: Basic Concepts 9 3.1. What Is a File? 9 3.2. Files and Directories .. 9 Directories: Parents and Children 1 1 3.3. Pathnames: Absolute and Relative ................. 1 1 Relative Pathnames .. 12 3.4. Filesystems 12 3.5. Your Home Directory 14 3.6. Useful Abbreviations 14 3.7. The SunOS File Hierarchy 14 Contents — Continued Chapter 4 Manipulating Files 17 4.1. Moving Around: Changing Directories With cd 18 4.2. Where Am I Now? The pwd Command 19 4.3. Interlude: Two Abbreviations (" and . .) 19 The Home Directory (') 19 The Parent Directory ( . . ) 21 4.4. More Shortcuts to Changing Directories: pushd, popd, and dirs 23 4.5. Making New Directories With mkdir 23 4.6. Removing Directories 24 4.7. What Files Are in This Directory? (Is) 25 Seeing Hidden Files (Is -a) 25 What Kinds of Files Are These? (Is -F) 26 What Kinds of Files Are These? (file) 26 Full Information on Files (Is -1) 27 Information on Directories (Is -Id) 28 Combining Options 28 4.8. Interlude: Two More Abbreviations (* and ?) 28 The* Wild Card 29 The ? Wild Card 29 4.9. Viewing Files With more 29 4.10. Copying Files and Directories 30 Copying Files (Same Machine) 30 Copying Directories (Same Machine) 31 Interlude: The . Abbreviation 32 Copying Files (Different Machines) 32 To Your Machine 32 From Your Machine 32 Copying Directories (Different Machines) 33 4.11. Moving (Renaming) Files 33 4.12. Removing Files 34 4.13. Creating Files 34 4.14. Printing Files 35 - iv - Contents — Continued Printing With lpr 35 Sending to a Different Printer 35 Printing Formatted Text 35 Printing Without Header Pages 36 Checking the Printer Status 36 Removing Print Jobs 36 4.15. Permissions and Ownership 37 Permissions 37 Determining Permissions 38 What Those Letters Mean 39 Setting Permissions With chmod 40 Setting Default Permissions With umask 41 Ownerships 42 Changing File Ownership With chown 42 Groups 42 4.16. Making Links 43 Chapter 5 Editing and Writing With vi 45 5.1. What Is vi? 45 5.2. Creating a File 45 Starting vi 45 Entering Text 46 Saving Your Work 47 Quitting vi 48 Printing a File 48 Some Theory: Command, Last-Line, and Input Modes 48 5.3. Moving Around in a File 48 Moving the Cursor 48 Arrow Keys 48 Arrow Key Substitutes: h, j, k, 1 49 One Word: w, b; W, B 50 Down: Return 50 Left: Back Space 50 Contents — Continued Right: Space Bar 50 Top: H 50 Middle: M 50 Bottom: L 50 Scrolling 50 Scroll Forward: Ctrl-F 50 Scroll Down: Qrl-D 50 Scroll Backward: Ctrl-B 50 Scroll Up: Ctrl-U 50 5.4. Inserting Text 50 Append: a, A 50 Insert: i, I 51 Open Line: o,0 51 5.5. Changing Text 51 Change Word: cw 51 Change Line: cc 51 Change Part of Line: C 5 1 Substitute Characters): s 51 Replace Character: r 51 Transpose Characters: xp 52 Undo Previous Command: u 52 Undo Changes to Line: U 52 Break or Join Lines: r+Retum, J 52 5.6. Deleting Text 52 Delete Character: x 52 Delete Word: dw 52 Delete Line: dd 52 Delete Part of Line: D 52 5.7. Using Repeat Factors and Repeating Commands 52 5.8. Copying and Moving Text — Yank, Delete, and Put 53 Copying Lines 53 Moving Lines 53 5.9. Copying, Moving, and Deleting Text — Last-Line Commands 53 - vi- Contents — Continued Turning on Line Numbers 54 Copying Lines 55 Moving Lines 56 5.10. Searching and Replacing 56 Finding a Character String 56 Refining the Search 57 Replacing a Character String 58 Finding a Specific Line 58 Going to a Line With G 58 Opening a File at a Specific Line 59 Opening a File at a Pattern 59 5.1 1. Inserting a File Into a File 59 5.12. Ending a Session 60 Using the Buffer 60 Saving Changes and Quitting vi 60 Saving 60 Saving and Quitting 60 Quitting Without Saving 60 Recovering From a Crash 61 5.13. Customizing vi 61 5.14. Problems With vi 61 5.15. A Note on ex 61 Chapter 6 Formatting and Printing Documents 65 6.1. Sample Memo 65 6.2. Basic Formatting Commands 67 6.3. Formatting and Printing the File 68 Using nroff 69 Using troff 69 6.4. Where To Find Out More About Formatting 69 Chapter 7 Basic Command Syntax 71 7.1. SunOS Commands: An Overview 71 — vii- Contents — Continued 7.2. Starting a C Shell 72 7.3. Arguments and Options 72 Options 73 7.4. Matching Filenames 73 Other Syntaxes for Matching Filenames 73 Single-Character Matching with [ and ] 73 7.5. Command Sequences 73 7.6. Redirecting Input and Output 74 Redirecting the Standard Output 74 Appending to an Existing File 75 Redirecting Input 75 Pipes and Pipelines 76 Filters 76 Redirecting the Standard Error 79 Using Backquotes 80 cat vs. more 81 7.7. Command Line Editing 81 Using the history Command 81 Command Substitution and Repetition 81 Changing Prompt To Display History Number 83 7.8. Processes, PiDs, and Daemons 83 What Commands are Running Now? (ps) 83 Terminating a Process With kill 85 7.9. Aliases 85 Argument Designators 86 Making Aliases Global and Permanent 87 Seeing Current Aliases 87 Escaping an Alias 87 Unaliasing an Alias 88 7.10. Running Commands in the Background 88 The at Command 90 at q and atrm 91 batch 91 - viii - Contents — Continued 7.11. Searching for Patterns With grep 91 grep as a Filter 92 More on grep 93 Searching for Metacharacters 94 Single vs. Double Quotes on Command Lines 95 Chapter 8 Using the Network 97 8.1. What Is a Network? 97 Sharing Files Over a Network: NFS and RFS 97 The Network Information Service ( NIS) 100 8.2. Remote Login With rlogin 101 Logging in to Another Machine With rlogin 101 rlogin to a Machine Where You Don’t Have a Home Directory 102 rlogin to a Machine as Someone Else 102 rlogin to a Non-Existent Machine 103 Aborting an rlogin Connection 103 Suspending an rlogin Connection 104 Verifying Your Identity With who am i 104 8.3. Who’s Logged in to This Machine? users, who, and w 105 8.4. Status Information: ping, rup, and perfmeter 106 Dead or Alive: ping 106 Remote Uptime: rup 106 Remote User Information With rusers 106 The finger Command 107 8.5. Remote Command Execution With rsh 108 Chapter 9 Messages Ill 9.1. Using talk Ill 9.2. Using write 114 9.3. Broadcast Messages: wall 115 9.4. System Messages 116 Chapter 10 Mail Tool 117 — ix — Contents — Continued 10.1. What Is Mail Tool? 117 10.2. Who Can Use Mail Tool? 1 17 10.3. Starting Mail Tool 117 Starting From a Command Line 1 1 7 Starting From the SunView Menu 1 17 10.4. Opening Mail Tool 1 1 g 10.5. A Glimpse at Mail Tool Windows 120 The Header List Window 120 The Command Panel Window 121 The Message Window 12 1 The Composition Window 122 10.6. Receiving Mail 123 10.7. Retrieving New Mail and Committing Changes 123 Choosing Letters 124 Looking at the Next (or Previous) Letter 124 Looking at Other Letters With the Show Button 124 Displaying the Full Header 124 10.8. Printing Mail 126 10.9. Saving Mail 126 Setting Up Folders and the Folder Directory 127 Selecting and Retrieving Files and Folders 127 Changing Directories With the Misc Button 128 10.10. Deleting (and Undeleting) Mail 128 10.11. Composing Mail 129 Inserting Names and Addresses 129 Sending a Letter Directly to a File or Folder 129 Using Word-Wrap 130 10.12. Replying to Mail 130 10.13. Including a Letter or File 130 U sing the Include Button 1 3 1 Using the Compose and Reply Buttons 133 Using ‘Include File’ 133 10.14. Delivering a Letter 134 Contents — Continued 10.15. Canceling a Letter 134 10.16. Reusing a Composition Window 135 10.17. Closing Mail Tool 136 10.18. Quitting Mail Tool 136 10.19. Changing Mail Tool: Mysteries of the Misc Button 137 Chapter 11 Mail 139 11.1. What Is mail? 139 11.2. mail Basics 139 Starting mail 139 Sending Yourself a Letter 139 Reading a Letter 140 Sending Someone Else a Letter 141 Quitting mail 142 11.3. Reading and Deleting Letters 142 Selecting a Letter 143 Deleting (and Undeleting) Letters From the Mailbox 143 1 1.4. Printing a Hard Copy 144 11.5. Sending Letters 145 Canceling an Unsent Letter 145 Adding Carbon and Blind Carbon Copies 145 Inserting a Copy of a Letter or File 146 Inserting a Letter 146 Inserting a File 147 Replying to a Letter 148 11.6. Saving and Retrieving Letters 148 Saving and Copying Letters in Files 148 Saving and Copying Letters in Folders 149 Setting the Folder Directory 149 Designating Folders 149 Sending a Letter Directly to a File or Folder 150 Reading Letters in Files and Folders 150 11.7. Using vi With mail 151 - xi- Contents — Continued 11.8. Getting Help: Other mail Commands 151 Chapter 12 Other Mail Features j§5 12.1. Mail From Whom? The from Command 155 12.2. The vacation Program 155 Saving Mail With the . forward File 156 12.3. Changing Your Name With chfn 157 Chapter 13 Mail Over Networks I59 13.1. What Networks Are Out There? 159 The UUCP Network 159 Sending Mail to People on the UUCP Network 159 How Does Someone Send Mail to Me on the UUCP Network? IgO The Internet Igl Appendix A Mail Aliases 163 A. l. Aliases in .mailrc 163 Aliases in /etc/aliases 164 Appendix B Modifying mail and Mail Tool 167 B. l. Using the Defaults Editor 168 B.2. Mail Tool-Related Options 170 B.3. Options Affecting Both mail and Mail Tool 172 B.4. Options That Affect Only Mail 174 B.5. Suppressing Header Lines in Letters 177 Index 179 — xii — Tables Table 1-1 Some Useful Control Keys 3 Table 2-1 Problems Logging Out 8 Table 4-1 Basic Commands for Manipulating Files 1 8 Table 4-2 Abbreviations for Files and Directories 18 Table 4-3 Is and Its Options 28 Table 4-4 Printing Commands 35 Table 4-5 Examples of Permissions Shown by Is -1 40 Table 4-6 Values and Permissions for New Files 41 Table 5-1 Basic vi Commands 62 Table 7-1 Summary of Redirection Symbols 80 Table 7-2 Information Displayed by ps 84 Table 7-3 grep Search Pattern Elements 95 Table 8-1 Network Error Notifications: Problems and Solutions 109 Table A-l Comparing Aliases: .mailrcand /etc/aliases 166 - xiii — Figures Figure 1-1 The Type 4 Keyboard 1 Figure 3-1 Visualizing Files and Directories 10 Figure 3-2 A Simple File Hierarchy 1 1 Figure 3-3 The usr Filesystem (Partial) 13 Figure 3-4 The /usr/ lib Filesystem (Partial) 13 Figure 3-5 The /usr /lib/ fonts Filesystem (Partial) 14 Figure 4-1 A Home Directory 20 Figure 4-2 Moving Laterally With 22 Figure 4-3 Information Provided by Is -1 27 Figure 4-4 Copying a File to Another Directory (Same Name) 3 1 Figure 4-5 Result of Moving a File 33 Figure 4-6 Information Provided by Is -1 38 Figure 4-7 Permissions Information 38 Figure 4-8 Permissions Information 39 Figure 5-1 New File 46 Figure 5-2 Giving the Write Command 47 Figure 5-3 File Saved 48 Figure 5-4 Arrow Keys 49 Figure 5-5 Cursor Moving Keys for vi 49 Figure 5-6 Setting Line Numbers 54 Figure 5-7 Line Numbers Displayed 55 - XV - Figures — Continued Figure 7-1 Where the C Shell Sits 71 Figure 8-1 A Non-Network Environment 9g Figure 8-2 A Typical Network Set-Up 99 Figure 10-1 The Iconic Open Menu \\g Figure 10-2 Mail Tool Running Open 120 Figure 10-3 The Header List Window 120 Figure 10-4 Command Panel Window 12 1 Figure 10-5 The Message Window 122 Figure 10-6 The Composition Window 123 Figure 10-7 A Typical Mail Header 125 Figure 10-8 Full Letter Header 126 Figure 10-9 A Folder Directory 128 Figure 10-10 The Change Directory Pop-up Window 128 Figure 10-11 Composition Window Buttons 129 Figure 10-12 Subject and Address Fields in a Composition Window 129 Figure 10-13 Multiple Addresses 130 Figure 10-14 A Received Letter 131 Figure 10-15 Including a Letter 132 Figure 10-16 Including a Letter, Indented 133 Figure 10-17 The Text Edit Menu in Mail Tool 134 Figure 10-18 Confirming a Cancellation 135 Figure 11-1 mail Prompt Commands 152 Figure 11-2 mail Tilde Commands 153 Figure 12-1 ASample . vacation. msg File 156 Figure 13-1 Sequence of Machines in Network 160 Figure A-l A .mailrc Alias 164 Figure A-2 /etc/aliases Aliases 165 - xvi - Figures — Continued Figure B-l The Default Mai lrc File 168 Figure B-2 .mailrc in the Defaults Editor Window 169 ' Preface Companion Documents Book Conventions SunOS User’s Guide: Getting Started introduces the basic knowledge you need to use the SunOS™ operating system and the Sun Workstation®. It assumes that you are new to the Sun Workstation and have little or no experience with the operating system. This manual provides tutorials, not detailed explanations of the inner workings of commands and programs. SunOS User’s Guide: Getting Started introduces □ Special characteristics of the keyboard. □ The essential concepts of the SunOS file system. □ The basic commands for working with files. □ Use of the vi text editor. □ The nrof f and trof f text formatters. a Use of the SunOS C shell command inteipreter. □ Commands and concepts associated with using the network. □ Sending and receiving messages and mail. Not covered in this manual is the use of windows systems. There is, however, a chapter on the SunView™ Mail Tool. Other manuals in this series cover more specialized topics. We suggest you read them in the following order: SunView User’s Guide (if your system is running SunView), SunOS User’s Guide: Customizing Your Environment, SunOS User’s Guide: Doing More, SunOS User’s Guide: Basic Troubleshooting. Italic font is used for emphasis and for variables that you replace with a specific word or string. Bold font is used for SunView buttons. 1 Kevs 1 on the keyboard are shown this way. Typewriter font is used for what you see on the screen or for file names. Bold typewriter font is represents text you type exactly as shown. 1 The Keyboard In this chapter you’ll learn some of the special features of the Sun Workstation keyboard and how it differs from a standard typewriter keyboard. Control keys and escape keys, which extend the keyboard’s functionality, are introduced. 1.1. Keyboard Layout The keyboard of a Sun Workstation is like the keyboard of a standard typewriter, with the addition of some special keys. Figure 1-1 The Type 4 Keyboard Caps Scroll Num Lock Compose Lock Lock • « r ) i i i See the SunView User’s Guide for more information on the use of windows- related keys. NOTE Remember that the SunOS operating system distinguishes between lowercase and uppercase characters and that it generally prefers lowercase. The Return Key I Return I makes the system interpret a command line and execute it. Until you type I Return ) you can correct the command line. ®sun microsystems 1 Revision A, of 27 March 1990 2 SunOS User’s Guide: Getting Started The Space Bar and the Tab Key Use the 1 Space Bari to add spaces to the command line when necessary. The 1 Tab j key inserts up to eight spaces until the next tab stop. Tab stops are regular divisions of the input line. The Delete and Back Space Depending on your system, either the fPeTI (delete) or the I Back Space ) key Keys allows you to back up one character and “rub out” or erase characters in the com- mands you type. To correct typing mistakes, rub out characters and then retype. You can rub out characters only back to the beginning of a command line. The SunOS operating system allows you to change the functions of these and other keys. See SunOS User’s Guide: Customizing Your Environment for more information. Control Keys Control keys are keys that require you to hold down fCuD while typing another key. [ Ctrl-U I , the line-kill character, erases the entire command line. For example, to erase the entire pas swd command, hold down the [ Ctrl ) key and type [u] or CE: Before: / — venus% pas sdw ^ — ----- After: venus % N / [ Ctrl-U I doesn’t appear on the screen when you type it. Some control keys appear on the screen; others don’t. Revision A, of 27 March 1990 Chapter 1 — The Keyboard 3 Table 1-1 A word is a sequence of characters surrounded by space(s) and/or tab(s). Escape Keys or Meta-Keys In contrast to control keys, escape keys require that you type the [Esc] key, release it, and then type the complementing key. For example, to type I Esc-U 1 . press the [Esc 1 key, release it, and then type QD- Some Useful Control Keys Key Appearance Function ICtrl-UJ invisible Erases entire command line; the kill character I Ctrl-W 1 invisible Erases last word on command line (Ctrl-CI Interrupts many programs and shell scripts 1 Ctrl-Z 1 Suspends many programs and shell scripts ( Ctrl-S ) invisible Stops output of running program; prevents output from running off end of screen. (Ctrl-O) invisible Resumes output from program stopped by [ Ctrl-S 1 l Ctrl-O 1 "0 Throws away output from program without interrupting the program ICtrl-D) End-of-file character used for logout; also terminates file input ( Ctrl A) Quits program and saves image of program in file called core for later debugging microsystems Revision A, of 27 March 1990 2 A Work Session Before you start your first SunOS work session, make sure that your system hardware is set up and that you have an account on your system. (Your system adminstrator should have arranged this for you.) This chapter will teach you how to □ Log in to the machine, □ Set and change your password, and □ Log out. Turn on the workstation and use it to while you work through this tutorial. If you get stuck, try asking a regular user of the system for help. Or look in SunOS User’s Guide: Basic Troubleshooting. Don’t be afraid to play with the computer: the best way to learn is to dig in and try the examples. 2.1. Logging In Your workstation screen will look something like this: ( ” A venus login% J This is called the system login prompt. Usually, the word before login : is the name of your machine. In this example, the machine name (also called hostname ) is venus. Since the SunOS operating system will allow more than one person to use the system at the same time, it requires you to identify yourself. When you get your account on the system, remember your username and pass- word. Your username (also known as a login name, a login id, a user id, or an account) identifies you to the system and to other users. Your password restricts use of your account to those people who know the password. You’ll learn how to change your password in Section 2.2 . □ At the login prompt, type your username, followed by I Return I . #sun XT microsystems 5 Revision A, of 27 March 1990 6 SunOS User’s Guide: Getting Started If you make a mistake in typing a character of your username or password, use the I Del 1 key to delete the character, and then type the correct character. ( — — — - \ venus login: medici Password: v The username is medici in this example. The system does not do anything until you complete the command by typing I Return 1 . After it accepts your username, it prompts you for your password. (If your account does not have a password assigned to it, the system will log you in without asking for a password.) □ Type your password at the password prompt. The system does not echo (type out) your password on the screen. This prevents other users discovering your password. □ Type 1 Return 1 after your password, so the system will interpret what you typed. (From now on, type I Return 1 after each command.) If you mistype your username or your password, the system responds with: A venus login: mdci Password: Login incorrect. login: v Simply retype your username and password to log in. (If the system persists in refusing to log you in, your account may not be set up properly. Try talking with your system administrator or look in the System and Network Administration manual.) After you correctly type your username and password, the system will pause briefly and then type out something like this: ^ !" . ; N venus login: medici Password: Last login: Fri Oct 31 23:59:59 from console SunOS Release 4.1 (DIONE_CLIENT) #1: Fri Feb 14 00: venus % ^ — — In addition, the system may type a login message that the operator has entered on the system to keep you informed about important system events, such as “down- time,” when the system is shut down, usually for system maintenance. All the information that the system types just after you log in is known as the “message of the day.” The system may also inform you that You have mail. Revision A, of 27 March 1990 Chapter 2 — A Work Session 7 2.2. Changing Your Password For more on security, see SunOS User’s Guide: Doing More. For information on how to read your mail, see Chapters 10 and 11. The last line in this example is the command prompt, consisting of the machine name and a percent sign (%). Right after logging in for the first time, you should change your password: this will ensure that you are the only user with easy access to your account. In the interests of your own security, change your password immediately if you believe someone has used your account without your permission. Your personal password is your choice entirely. Pick a password that you can remember without writing it down. For security’s sake, pick a password that is at least six characters long, has at least one number in it, and is not obvious or easy to guess. Do not use your own name or the name of your spouse. Do not use the names of pets or common objects. Then type the pas swd command. A venus % passwd Changing password for medici on venus Old password: New password: Retype new password: venus % J □ When the system prompts you for Old password:, type in your current password. (If no password was assigned to your account, the system will skip the Old Password: prompt.) Just as during log-in, the sys- tem will not display passwords. □ Now type in the new password at the next system prompt: New password: The password does not echo. The system asks you to retype your new pass- word to verify spelling. If you don’t remember or mistype your old password, the system refuses to change your password and responds with Sorry. If this happens repeatedly, contact your system administrator to get a new password. If you pick a password less than six characters long, the system does not allow you to enter it. microsystems Revision A, of 27 March 1990 8 SunOS User’s Guide: Getting Started Password Aging If your system is using the password aging process, your password may have a maximum or a maximum and minimum lifespan. This could mean that your password will have to be changed by a certain date or cannot be changed until after a certain date. Maximum and minimum lifespans are set by your system administrator. See SunOS User’s Guide: Doing More and System and Network Administration for more information. 2.3. Logging Out When you’ve finished your work session, you should secure your screen to pro- tect the integrity of your files. Logging out, which ends a work session, is one way to do this. If you’re running SunView, you can lock your screen so that others can- not use your terminal. You can also exit SunView and logout. See Sun- View User's Guide. Log out using the logout command: venus % logout venus login: V - / Another way to log out is to type ( Ctrl-D ) , the end-of-file character . Note that even though (jCuLDJ specifies an uppercase D, you can type a lowercase dhere: venus % venus login: , Turning off the workstation does not necessarily log you out. Most Sun systems do not have a “time-out” mechanism: unless you log out explicitly, you will probably remain logged in to the system. After you log out, the system displays the login prompt again. The following table may help if you have trouble logging out: Table 2-1 Problems Logging Out Problem Solution System says: There are stopped jobs Type: logout two or three times System says: Not login shell Type: exit then type: logout You’re just completely stuck. (This might happen when logged into a machine over the network.) Try typing: 1 Return 1 1 Return ) microsystems Revision A, of 27 March 1990 3 Files: Basic Concepts This chapter introduces some basic concepts having to do with files. Chapter 4 presents commands for manipulating files. If you’re familiar with the following, you may want to skip to Chapter 4: □ Different kinds of files; □ Directories and filesystems; □ The SunOS file hierarchy and parent vs. child directories; □ Absolute vs. relative pathnames; and □ Your home directory. 3.1. What Is a File? Th efile is the basic unit of the SunOS operating system. Almost everything is treated as a file, including: □ Documents. These include text files, such as letters, computer source code, or anything else you might write. □ Commands. Most commands are executable files; that is, they are files that you can run. For example, the chess command, which (as you might guess) plays chess, is an executable file. □ Devices. The SunOS operating system treats your terminal, your printer, and your disk drive as files. □ Absolutely nothing. There’s even a special file, called / dev/null, that is a “black hole” — any sort of data sent there is discarded. □ Directories. A directory is a file that contains other files. Section 3.2 explains them further. 3.2. Files and Directories As mentioned above, a directory is a file that holds other files. Directories can also contain other directories, that can contain other directories, and so on. You move around from directory to directory in order to manipulate the files they contain. 9 Revision A, of 27 March 1990 10 SunOS User’s Guide: Getting Started The symbol / has two meanings: it’s used to separate a file’s name from the name of the directory it’s in, and it also is the name of the very first (or ’lop” or “root”) direc- tory in the operating system. The chess game is located in a directory called games, which is itself located in a directory called usr, which is located in a directory called / (pronounced “slash”). We use the / symbol to separate the names of directories and files; here’s how we represent the location of chess: /usr /games /chess Here’s one way to visualize the layout: Figure 3- 1 Visualizing Files and Directories However, it’s better to visualize the system as a hierarchy. Revision A, of 27 March 1990 Chapter 3 — Files: Basic Concepts 11 Directories: Parents and Figure 3-2 bears a passing resemblance to a family tree. Indeed, we use the term Children parent directory to describe a directory that contains another directory. The directory it contains is a child directory, also called a subdirectory. In Figure 3- 2, us r is the parent directory of games; likewise, games is the child directory of usr. 3.3. Pathnames: Absolute The name of the chess program is chess, /usr/games/chess is th epath- and Relative name of the chess program; that is, it’s the name of the file (chess) plus its location (/usr/games). If chess were located in /usr/lib (a different directory), its pathname would be /usr/lib/ chess To run the chess program, type: To find out how to play che ss, type man chess. Type 1 Ctrl-D I to Quit the chess game. Pathnames are important because you can’t use a file unless you can find it. Now we come to a bit of a tricky concept. #sun Xr microsystems Revision A, of 27 March 1990 12 SunOS User’s Guide: Getting Started /usr/games/chess is an absolute pathname. This means that it gives the location of chess in terms of its overall position in the whole SunOS file hierar- chy. To find chess, you go up to /, and then back down through us r and game s . (We normally say that chess is located in the directory /usr/games.) Relative Pathnames It’s inconvenient to have to give the full, absolute pathname every time you want to access a file. A relative pathname describes the file’s location not in terms of the whole SunOS hierarchy, but relative to your location in that hierarchy. Suppose you’re in the directory /usr. 1 Since this directory contains the direc- tory games, which contains the chess program, you don’t have to specify the /usr part— you’re already there. So instead of playing chess by typing /usr/ game s / che s s , you can play by just typing: / venus% games/chess ' (the chess game begins) J By the same token, if you’re located in /usr/games, you need only type: ( ~~ \ venus% chess ( the chess game begins) v : : You can’t move to /usr/games/chess, because it’s a file, not a directory. Relative Pathname to Play Chess If You’re Located In... ...The Command Is: anywhere / /usr /usr/games / usr/ games/chess ( absolute pathname ) usr/games/chess games /chess chess 3.4. Filesystems The SunOS filesystem is a hierarchical collection of a great number of directories and files. Some files are private to one machine, some files are shareable between different kinds of machines, and some files are shareable by only the same kind of machine. Your home directory, and all the files that descend from it, are part of the larger filesystem. At the same time, your home directory and its files constitute a filesystem. In this sense, a filesystem can be considered any parent directory and its children. Figure 3-2 shows a very simple hierarchy. You’d need a very large piece of paper to show all the files and directories located under /. Figure 3-3 shows a very stripped-down /usr filesystem. In point of fact, it is much, much larger, with many more files and directories, but for the purposes of 1 Chapter 4 explains how to move around from directory to directory. microsystems Revision A, of 27 March 1990 Chapter 3 — Files: Basic Concepts 13 this discussion we will limit ourselves to just what’s shown in the figure. Figure 3-3 The usr Filesystem ( Partial) The /usr filesystem (as depicted here) contains other filesystems, as well. One such filesystem is /usr/lib. The /usr/lib filesystem contains the direc- tories fonts and uucp, plus everything these two directories contain: Figure 3-4 The /usr /lib Filesystem (Partial) /usr/lib itself contains the /usr/lib /fonts filesystem. /usr/lib/f onts contains the directory tekf ont s, which contains the file tekf ontO. • sun \r microsystems Revision A, of 27 March 1990 14 SunOS User’s Guide: Getting Started Figure 3-5 The / usr/ lib/ fonts Filesystem ( Partial ) fonts tekfonts 3.5. Your Home Directory You have a home directory that you go to when you log in. This is the starting point for your own filesystem, containing your own files. To find out what your home directory is, type as follows: / A venusl cd venus % pwd ( your home directory is displayed) j You can create files and subdirectories in your home directory. 3.6. Useful Abbreviations The SunOS operating system has some useful abbreviations. Their usefulness will become more apparent in Chapter 4, but you should take a moment to glance at them now. They’ll come in handy. The current directory, i.e., the directory you’re in. . . The directory “above” the one you’re in (the parent directory). Useful when you want to move or operate near your current position in the file hierarchy. Your home directory. Allows you to operate on files and directories relative to your home base. ? Any single character in a filename. * Any group of characters in a filename. To find out about the various files and directories that make up the SunOS operating system, check the hier and filesystem pages in Section 7 of the SunOS Reference Manual. You can also get this information by typing at a sys- tem prompt 3.7. The SunOS File Hierarchy venus% man hier or ©sun microsystems Revision A, of 27 March 1990 Chapter 3 — Files: Basic Concepts 15 venus % man filesystem ©sun microsystems Revision A, of 27 March 1990 Manipulating Files This chapter gives some useful commands for manipulating files. We assume you are already familiar with most of the concepts in Chapter 3. You may want to review that chapter before reading this one. This chapter covers □ Changing directories; □ Finding your place in the file hierarchy; □ Listing the contents of a directory; □ Creating, removing, moving, and copying files and directories; □ Printing files; □ File permissions and ownerships; and □ Some useful abbreviations. Here’s an overview of the commands discussed in this chapter: ®sun microsystems 17 Revision A, of 27 March 1990 1 8 SunOS User’s Guide: Getting Started Table 4-1 Basic Commands for Manipulating Files File Manipulation Commands Command Action cd moves you to another directory pwd tells which directory you’re in pushd moves to directory and creates stack popd returns through directory stack dirs displays directories in stack mkdir creates a directory rmdir removes a directory Is lists the contents of a directory file displays the type of file more displays the contents of a file cat displays the contents of a file cp copies a file rep copies a file to & from other machines mv moves or renames a file rm removes a file touch creates or updates a file lpr prints a file lpq checks printer status lprm removes a printing job chmod sets permissions on a file umask sets default permissions chown changes ownership of a file In makes links between files Additionally, this chapter covers the following abbreviations: T able 4-2 Abbreviations for Files and Directories Useful Abbreviations the current directory the “parent” directory home directory ? a single character in a file’s name * a group of characters in a file’s name 4.1. Moving Around: Changing Directories With cd Remember to press I Return I after typing commands. In order to manipulate files, you need to be able to get to them. The cd com- mand moves you from directory to directory. Its syntax is cd directory where directory is the name of the directory to which you want to go. Here’s how you would go to the directory /usr/games: microsystems Revision A, of 27 March 1990 Chapter 4 — Manipulating Files 19 4.2. Where Am I Now? The pwd Command 4.3. Interlude: Two Abbreviations (“ and The Home Directory (~) r venus % cd /usr/games venus% < .... _____ J The cd command by itself (without a directory) moves you to your home direc- tory: venus % cd ( move to home directory ) venusl cd /usr/games (move to /usr/games) venus% cd (back to home directory) venus % V — The pwd (for print woiking directory) command tells you where you are when you change directories. In the example below, assume that your home directory is /home / venus /medici: — _ venus % pwd /home/venus/medici venus % cd /usr/games venus % pwd / usr/games venus% cd (go to home directory) venus % pwd /home/venus/medici venus % V — . J The SunOS operating system has a number of abbreviations that can make life a little simpler for you. Let’s look at two. Your home directory may be abbreviated as The notation '/file refers to a file in your home directory. (This is also true for directories in your home directory.) The notation ' user refers to the home directory of another user. Therefore, the notation ' user/ file refers to a file located in that user’s home directory. Suppose your home directory is /home/venus/medici and that it contains two subdirectories, called us a and ussr. The directory usa contains the file georgia, while the directory ussr contains the file Ukraine. This is •sun microsystems Revision A, of 27 March 1990 20 SunOS User’s Guide: Getting Started illustrated in Figure 4- 1 : Figure 4-1 A Home Directory If you want to get to us sr , you could type r ' venus% cd /home/venus/medici/ussr " ' ' venus % l i > but it’s easier to type ' — : — ' . venus% cd ~/ussr 'S venus% V. i — i — J instead. microsystems Revision A, of 27 March 1990 Chapter 4 — Manipulating Files 21 The Parent Directory ( . . ) See Section 3.3 for more on relative vs. absolute pathnames. The abbreviation . . refers to the directory just above the one you’re in (known as the parent directory ). Suppose that you’ve moved to /home/venus/medici/ussr. If you want to move up one directory, simply type cd . . , as shown below: ( venus % pwd (where ami?) /home/venus/medici/ussr venus% cd . . venus % pwd ( where am I now ? ) /home/venus/medici venus% l -J You’re now in /home/ venus /medici. The abbreviation . . is a relative pathname. The directory above the one your in is called its parent directory. Suppose once again that you’re in /home/venus/medici/ ussr. This time you want to move over one step laterally (not vertically) to usa. osun \r microsystems Revision A, of 27 March 1990 22 SunOS User’s Guide: Getting Started One way to move from ussr to us a is to type That’s using an absolute pathname. An easier way is to use a relative pathname. Since you’re already in ussr, you can type ‘cd . . /usa" means “go up one directory, and then back down to usa.” microsystems Revision A, of 27 March 1990 Chapter 4 — Manipulating Files 23 4.4. More Shortcuts to Changing Directories: pushd, popd, and dirs Using the cd command to change directories has a disadvantage when you’re switching directories often: it doesn’t remember where you’ve been. As an alter- native to changing directories with cd, you can create a directory stack — an ordered listing of directories you’ve used — and then return to these directories without having to recall complicated pathnames. These commands are available only Three related commands let you do this: in the C shell; see Chapter 7 and SunOS User's Guide: Doing More. □ pushd: when you’re in a directory that you know you’ll want to return to, use this command to change to a new directory and add the current directory to the directory stack. Use the command form pushd directory where directory is the directory you want to move to. a popd: use this command to work your way back through the directory stack, a directory at a time. Note that this command effectively dismantles the stack you created by changing directories with pushd. □ dirs: use this command to see a list of the directories in the stack, dirs -1 display the full pathnames of stacked directories. Note that pushd and popd also display the directory stack, with the current directory at the left. The example below shows all three commands in use: r — > venus % pwd (checks name of current directory) /var/spool/mail venus % pushd ' /var/spool/mail venus % pushd /etc /etc ' /var/spool/mail venus% dirs /etc ' /var/spool/mail venus % popd ' /var/spool/mail venus % popd /var/spool/mail V — 4.5. Making New Directories With mkdir The mkdir command creates directories. Its syntax is mkdir directory where directory is the name of the directory you want to create. Suppose your home directory is /home/venus/medici and you want to create a directory there called letters to store copies of the letters you write. Revision A, of 27 March 1990 24 SunOS User’s Guide: Getting Started You could have used mkdir without changing directories. In this case, you must give the full, or absolute, pathname of the directory you want to create. This is true of all file-manipulating commands. See Chapter 3 for more on relative vs. absolute pathnames. In this case, the shortest way to create letters is to use the ~ abbreviation, explained in Sec- tion 4.3. The commands in the three examples above are equivalent. Sometimes you’ll be denied permission when you try to create a directory. One of the most common problems is when you see the message: mkdir: Permission denied. or something similar. Often the problem is that the directory containing the one you want to create doesn’t have the right permissions. See Section 4.15 for information on permissions. For more help with problems, see SunOS User’s Guide: Basic Troubleshooting. 4.6. Removing Directories rmdir does the opposite of mkdir: it removes existing directories. Its syntax is rmdir directory where directory is the name of the directory you want to remove. A directory must be empty before you can remove it. It must contain no files and no directories that contain files. (Section 4.12 explains how to remove files.) You can remove a directory and all its contents, including subdirectories and all their contents, with the rm -r command. CAUTION Be very careful when using this command! You may accidentally wipe out whole hierarchies of important files. Revision A, of 27 March 1990 Chapter 4 — Manipulating Files 25 ( ^ A venus % rm -r "/letters venus % V • J There’s a safer way to remove a directory and its contents. Use rm -ir to have the operating system query you for confirmation before it removes any files: > venus % rm -ir "/letters remove "/letters? y remove "/letters/subdirectory/otherfile? n venus % s 4.7. What Files Are in This Directory? (Is) Seeing Hidden Files (1 s -a) . . represents the parent directory; . is the current directory. The Is command tells you what files (and directories) are in a directory. Next to the cd command, Is is probably the most-used command in the SunOS operat- ing system. The syntax Is is Is directory where directory is the name of the directory you want to look at. — venus% Is /var adm log spool yp crash venus % preserve tmp V y If you don’t specify a directory, Is lists the contents of the directory you’re in. — \ venus% Is alabama Colorado idaho iowa alaska georgia Illinois California hawaii indiana venus % V — — Files starting with a dot ( . ) are hidden. That means that Is won’t normally display them. However, Is -a does (the a stands for “all”). Why would you want to hide a file? Generally, because the file is important enough that you want to keep it around — it may get used a lot — but there’s no reason to have 1 s display it under most circumstances. Revision A, of 27 March 1990 26 SunOS User’s Guide: Getting Started What Kinds of Files Are These? (Is -F) What Kinds of Files Are These? (file) (One example of a hidden file is . cshrc, kept in your home directory. It con- tains parameters governing how the SunOS operating system behaves for you. See SunOS User's Guide: Customizing Your Environment for more on . cshrc.) Is followed by -F can also tell you what kind of files are in a directory. There are five file types displayed by Is -F: Directories Is appends a slash (/) to the filename to indicate that this file is really a directory. Executables Is appends an asterisk (*) to the filename to indicate that this file is execut- able, that is, it’s a program you can run. Plain Files If only the file name appears, with nothing appended, then the file is a plain file. Links Is appends an “at” symbol (@) to indicate a link. Links are explained in Section 4.16. AFJJNIX Sockets Indicated by a trailing equals sign (=). These are for specialized program- ming applications. r \ venus % Is -F animals/ go_carts* letter . 1 states/ food/ venus % hangman* letter . 2 V The example above shows that the directory contains three subdirectories (animals, food, and states), two programs (go_carts and hangman), and two plain files (letter . 1 and letter . 2). The file command gives you more information than Is -F about files: , N venus% file go_carts animals letter. 1 go_carts: spare demand paged dynamically linked executable animals: directory letter. 1: English text Note that, like most SunOS commands, you can use file on more than one file at a time. microsystems Revision A, of 27 March 1990 Chapter 4 — Manipulating Files 27 Full Information on Files (Is Is -1 (lowercase “L”) yields yet more information about the contents of a - 1 ) directory, including who owns a file, its size, when it was last modified, and so on. f venus % Is -1 total 108 ' -rwxr-xr-x 1 medici 133490 Jun 16 18:30 go_carts -rw-r — r — 1 medici 8111 Jun 16 18:31 letter. 1 drwxr-xr-x 2 venus % s medici 1024 Jun 16 18:33 states Here’s how we break down this information: Figure 4-3 Information Provided by Is -1 c permissions / owner / / drwxr-xr-x 2 medici A date & time last modified \ 1024 Jun 16 18:33 states / / 7 / ' filename size (bytes) links And here’s what those things mean: Permissions What you can do with this file. See Section 4. 15 for more on permissions. For now, just note that if the file is a directory, the first letter here is a d. Links Links are discussed in Section 4.16; basically, think of each file (or filename, including directories) as taking up a certain number of allotted spots on the system. Owner The owner of the file. See Section 4.15 for more on ownership. For now, just note that in most cases the owner is the person who created the file. Size The size of the file in bytes. Time of modification When the file was created, edited, or otherwise changed. Name The name of the file or directory. Revision A, of 27 March 1990 28 SunOS User’s Guide: Getting Started Information on Directories (Is -id) Typing Is -Id gives you the same information as Is -1, except that it does so for the directory itself, not its contents. ( ' v: : : . N venus % Is -Id /usr/lib drwxr-sr-x 21 bin 3072 Dec 15 1988 /usr/lib venus% v > Combining Options You can combine all the options to Is that we’ve covered. (There are many more options to Is; see the SunOS Reference Manual or type man Is at a sys- tem prompt.) The syntax is Is -options directory where options are one or more of 1, a, or F, as discussed above, and directory is the name of a directory to look at. (If you don’t specify a directory, you look at the one you’re in.) r > venus% Is - laF drwxr-xr-x 5 medici 512 Jun 19 10:23 ./ drwxr-xr-x 5 medic i 512 Jun 16 18:30 . ./ -rw-r — r — 1 medici 1234 Jun 19 10:23 . cshrc -rw-r — r — 1 medici 12272 Jun 19 10:23 . rootmenu drwxr-xr-x 2 medici 512 Jun 16 18:32 animals/ drwxr-xr-x 2 medici 512 Jun 16 18 : 32 food / -rwxr-xr-x 1 medici 133490 Jun 16 18:30 go carts* -rwxr-xr-x 1 medici 23441 Jun 16 18:30 hangman* -rw-r— r— 1 medici 8111 Jun 16 18:31 letter. 1 -rw-r— r— 1 medici 2130 Jun 16 18:31 letter . 2 drwxr-xr-x V 2 medici 1024 Jun 16 18:33 states/ v In the example above, the options -1, -a, and -F are combined: -1 causes Is to print out full information on the files; -F displays the type of file after the filename; and -a displays hidden files (ones starting with a dot). Table 4-3 Is and Its Options Command Action Is shows files in a directory Is -a shows hidden files Is -F shows file types Is -1 shows full information on files Is -Id shows full information on directories 4.8. Interlude: Two More Abbreviations (* and ?) The SunOS operating system allows you to work with more than one file at once by providing two wild card characters, so called because they stand for any char- acter, or group of characters, in a file’s name. In this way, you can operate on a number of files whose names match the pattern you give. Revision A, of 27 March 1990 Chapter 4 — Manipulating Files 29 The* Wild Card An asterisk by itself represents all the files in a directory, except hidden ones. ( venus% Is states/m* maine michigan mississippi montana ma ryland minnesota missouri venus % V An asterisk (*) represents any number of characters in a file’s name. Suppose you have a directory, states that contains files with names of states. The following command would give you a list of all files starting with m: The next command would give a list of files starting with m and ending with a: ■N venus% Is states /m*a minnesota montana venus% V The ? Wild Card 4.9. Viewing Files With more The cat Command The question mark (?) wild card represents any single character in a file’s name. Therefore, you can use it to select a group of files matching a given pattern, with the same number of letters in them. This command would list all files with names seven characters long, and that begin and end with a: r • A venus% Is states/a?????a arizona alabama venusl l y Note that Is didn’t display alaska, because the word has too few characters to match the pattern. The more command displays the contents of a file: . venus % more filename v . more displays one screenful at a time; if the file is more than one screen long, it displays the word -More- followed by the percentage of the file displayed so far, at the bottom of the screen. Press the I Space Bar 1 to see the next screen of the file. Press q to quit. To search for a string, type /, and then the string to be searched for. Press h for help (this displays a list of commands). Type man page at a prompt for additional information. The cat command also displays the contents of a file, but not page-by-page. Chapter 7 shows some ways in which cat is more useful than more. microsystems Revision A, of 27 March 1990 30 SunOS User’s Guide: Getting Started 4.1®. Copying Files and Copying files and copying directories is pretty much the same, whether you’re Directories copying on the same machine or from one machine to the next. We introduce another abbreviation ( . ) that is especially useful here. Note that copying a file isn’t the same as moving a file. When you copy a file, you leave a copy of it where it was. Copying Files (Same Machine) To copy files on the same machine, use the cp command, cp has the following syntax: cp source- file destination- file where source-file is the name of the file you want to copy, and destination-file is the name of the file you want it copied to. Here’s how you make a copy — with a new name — of a file in the same direc- tory: r venus% cp georgia georgia.copy venus% V J If you’re copying a file to another directory — without changing its name — the syntax is: cp source-file directory where directory is the place to which you’re copying the file. Here’s how you copy a file — keeping the same name — to another directory. Sup- pose you have the filesystem shown in Figure 4-2: represents your home directory. f \ venus % cp "/usa/georgia '/ussr venus % V J This is the result (again, compare this with Figure 4-2): Revision A, of 27 March 1990 Chapter 4 — Manipulating Files 3 1 Figure 4-4 Copying a File to Another Directory (Same Name) And here’s how you make a copy — with a new name — in another directory (in this case, /tmp): To copy the contents of one directory to another, use the * abbreviation explained in Section 4.8. This is the way you would copy all the files starting with m and ending with a, in the directory states, into the directory /tmp: Use cp -r to copy an entire directory, plus all its subdirectories, into another directory. The syntax is the same as above: cp -r source destination where source is the directory you’re copying and destination is the directory you’re copying to. This is how you’d copy your entire home directory and all its subdirectories and their contents into the directory /tmp: Revision A, of 27 March 1990 Copying Directories (Same Machine) 32 SunOS User’s Guide: Getting Started Interlude: The . A single dot ( . ) represents whatever directory you’re currently in (called the Abbreviation current or working directory)> This abbreviation comes in handy when copying files. For example, if you want to copy the file chess from /usr/ games to the directory you’re in, you type: Use rep to copy from one machine to another, rep’s syntax is similar to cp’s. To copy from another machine to yours, the syntax is: rep machine : source destination where machine is the name of the other machine; source is the name of the file(s) you want to copy; and destination is the place on your machine to which you’re copying. The example below shows how to copy the file /home/earth/terran/notes from the machine earth to the directory /tmp: The example below is similar to the previous one. We include it here so that you can see how to combine various abbreviations and syntaxes. It shows how you copy all the files ending in . c from user holly’s home directory on the machine mars to your current directory on your machine: 'holly is Holly’s home directory; * . c represents files ending in .c, and . represents your current directory. From Your Machine To copy files from your machine to another, simply reverse the syntax: rep file(s) machine : destination where file(s) are the file(s) you want to copy; machine is the name of the other machine; and destination is the place (directory) on the other machine where the file’s to go. The example below shows how you’d copy the file buzz cut from your direc- tory ~ /haircut s/usa to the directory 'holly/trivia on the machine Revision A, of 27 March 1990 Copying Files (Different Machines) To Your Machine Chapter 4 — Manipulating Files 33 mars: ~ is your home directory; 'holly is user holly’s home directory . / venus% rep ~/haircuts/usa/buzzcut mars : 'holly /trivia venus% V / Copying Directories (Different Use rep -r to copy subdirectories and their contents. Machines) 4.11. Moving (Renaming) Use the mv command to move files. Files Moving files is similar to copying files, except that it removes the old version of the file. And renaming a file is the same as moving it; you are simply “moving” it to a new name. The syntax for mv is mv old new where old is the old filename and new is the new location or name. The example below shows how you move a file (georgia) from one directory to another (usatoussr). r venus% mv '/usa/georgia ~/ussr venus% l : Figure 4-5 Result of Moving a File Revision A, of 27 March 1990 34 SunOS User’s Guide: Getting Started Renaming Files Technically, we renamed the file ~/usa/georgia as ~/ussr/georgia. Usually, though, we think of this as moving it from usa to ussr. That’s why we use the mv command to rename files. This is how you rename the file aga- tha as bernice: / A venus % mv agatha bernice venus% V __ ------ 4.12. Removing Files Use rm to remove a file or files. Here’s how you remove all files starting with the letter m and ending with the letter a: f A venus % rm m*a venus% V a CAUTION Be very careful using this command! Once you remove a file, you can’t get it back. A safer way to remove files is to add the -i option to rm. This causes the operating system to query you for confirmation before deleting a file: r A venus % rm -i m*a rm: remove minnesota? y rm: remove montana? n venus% V V 4.13. Creating Files There are a number of ways to create files. □ Copying or moving an existing file. (You’ve already learned how to do this.) □ Using an editor. This is the most common way to make a file; it’s how you compose letters, write programs, create documents. Chapter 5 explains vi, the basic SunOS editor. □ Using the output of a program. The cc command, for example, produces executable (“runnable”) programs from the C programming language. □ Using the touch command, touch creates empty files, or updates (“time- stamps”) existing ones. □ Using the cat command. When you want to create a text file but don’t want to use an editor — say, the file is very small and you want to do it fast — use the cat command. The syntax is cat > filename where filename is the name of the file you want to create. First, type the command. Then enter the text you want, pressing I Return 1 at the end of each line. End your input by pressing [ Ctrl-D 1 on a new line. Revision A, of 27 March 1990 Chapter 4 — Manipulating Files 35 4.14. Printing Files Table 4-4 Printing With lpr Sending to a Different Printer Printing Formatted Text venus % cat > dogs Of all breeds, the rare German Schnaubel- Gotterdammerung is most prized by collectors. It has wiry hair, short legs, and pince-nez glasses. It can also sing Cole Porter, although, to be fair, only when it's "had a few." 1 Ctrl-Dj venus % . This section introduces a few of the commands used in printing. Printing Commands Printing Commands Command Action lpr prints out unformatted or nrof f -formatted file lpr -t prints trof f -formatted file lpr -P printer prints out to named printer lpr -h prints out without a header page lpq reports on the status of the printer lprm removes a printing job Use lpr to print out files. This command will send unformatted files to your default printer. / > venus % lpr textfile venus % . > To send a job to a different printer, use lpr -P. The syntax is lpr -Sprinter filename (s) where printer is the name of the other printer and filename is the name of the file(s) to print. — \ venus % lpr -Pprinter2 textfile venus % V V Use lpr to print out files formatted with nrof f . Use lpr -t to print out text you’ve formatted with trof f . (Chapter 6 introduces nrof f and trof f and discusses the use of macro packages in formatting and printing text.) XT microsystems Revision A, of 27 March 1990 36 SunOS User’s Guide: Getting Started Printing Without Header Pages Checking the Printer Status Removing Print Jobs r venus% troff tjsource > t_output { create formatted file ) venus % lpr -t t_output (print it) venus % vi Normally when you print a file, you also produce a cover sheet that identifies the output. This is useful if your file is going to get printed along with a lot of others or if you don’t want people reading what you’re printing. Such sheets are called header pages. When it’s not important to have a header page, you can save part of a tree by using lpr -h to specify that you don’t want one printed. venus% lpr -h textfile venus % V — / When you print a file, you send a copy of the file to a print queue. A print queue is all the files waiting to be printed on that printer. Each file waiting to be printed is called a printer job. Each printer job has a number associated with it. The lpq command tells you what’s in the print queue and whether the printer is printing correctly or not. You can use the -P printer option to check the status of other printers. venus% lpq printerl is ready and printing Rank Owner Job Files Total Size active medic i 16 textfile 149576 bytes venus% lpq -Pprinter2 printer2 is ready and printing Rank Owner Job Files Total Size active medic i 16 textfile2 1398791 bytes active carlos 17 big_plans 34311 bytes active scotty 18 proposal 102296 bytes venus% If you send something to the print queue and then decide not to print it, use the lprm command. There are two ways to use lprm. One way is to remove a single print job at a time. First, use lpq to determine the job number associated with that file. Then type lprm followed by that job number: #sun microsystems Revision A, of 27 March 1990 Chapter 4 — Manipulating Files 37 f venus% lpr textfile (print file) venus % lpq (check printer) lw is ready and printing \ Rank Owner Job Files Total Size active medici 16 textfile venus % lprm 16 (remove print job) printerl : dfA016Venus dequeued printerl: cfA016venus dequeued 149576 bytes venus % Another way is to remove all your print jobs at once. To do this, type Iprm fol- lowed by a hyphen (-): Of course, you may just want to put more paper in the printer. . . . As with lpr and lpq, you can use the -P option with lprm to remove files from a specified printer. Section 4.7 discusses the output of the Is -1 command. Two things this output displays are permissions and ownership. These two concepts are very important to using the SunOS operating system. Permissions determine what users may do with a file or a directory. The follow- ing are the permissions associated with files and directories: Readable A file must be readable to be looked at or copied. A directory must be readable for you to list its contents. Writable A file must be writable in order for you to modify it, remove it, or rename it. A directory must be writable in order for you to add or delete files in it. Executable ( files only) A file with executable permissions is one you can run, such as a program or a shell script. 2 4.15. Permissions and Ownership Permissions venus% lpr textfile letter (print files) venus % lpq (check printer) Printer Error : may need attention! (out of paper) Rank Owner Job Files Total Size active medici 16 textfile 139879 bytes active medici 17 letter 4201 bytes venus % lprm - (remove all print jobs) printerl: dfA016venus dequeued printerl: cfA016venus dequeued printerl: dfA017venus dequeued printerl: cfA017venus dequeued venus% V J 2 You can give any file executable permission, but if the file isn’t runnable as a program in the first place — Revision A, of 27 March 1990 38 SunOS User’s Guide: Getting Started Searchable ( directories only) A directory must be searchable in order for you to cd to it, list its contents, or create or delete files there. Determining Permissions Use the Is -1 command, as described in Section 4.7, to determine what per- missions files and directories have. Here’s a close-up of part of the typical output of Is -1: note the area to the left, labeled “permissions.” It is this region that tells you what permissions a file has. Figure 4-6 Information Provided by Is -1 Now let’s zoom in. Here’s how the permissions area breaks down: Figure 4-7 Permissions Information Figure 4-7, from left to right: Is! is not a directory If the letter d appears here, then this is a directory. If a hyphen appears like an ordinary text file — it doesn’t make sense for it to have executable permission. On the other hand, if you have a program that doesn’t have executable permission, it won’t run. Revision A, of 27 March 1990 Chapter 4 — Manipulating Files 39 instead, then it’s a file. Owner permissions These three letters tell what permissions the owner of the file has with respect to the file or directory. That is, whether he or she can read it, write it, execute it (file), or search it (directory). Group permissions These three letters tell what permissions users belonging to the same group as the file’s owner have with respect to the file or directory. Groups are explained below. Other user permissions These three letters tell what permissions any other user has with respect to the file or directory. What Those Letters Mean Here’s what each letter means. r The file or directory is readable. w The file or directory is writable. x The file is executable, or the directory is searchable. - The hyphen appears when the permission is switched off — if it appears in place of an r, then the file or directory is not readable; if it appears in place of a w, then the file or directory is not writable; and if it appears in place of an x, then the file isn’t executable (or the directory isn’t searchable). This then is what Figure 4-7 means: Figure 4-8 Permissions Information Most files are created so that they are readable and writable by their owner, and readable by others. Revision A, of 27 March 1990 40 SunOS User’s Guide: Getting Started Table 4-5 Examples of Permissions Shown by Is -1 Example Meaning -rw-r — r — file is read/write for owner, read only for others -rwx file is read/write/execute for owner only dr-xr-x directory is read/search for owner and his group -rwxr-xr-x file is read/write/executable for owner, read/execute for others drwxr-x — x directory is read/write/search for owner, read/search for group, searchable only for oth- ers Setting Permissions With chmod Use chmod (change mode) to change the permissions on a file or directory, chmod’s syntax is chmod who op permission filename where: Who is the user(s) to change permissions for. The letter u means set permissions for the file’s owner; g means to do so for the owner’s group; o means other users not in that group; and a means all users. Op is the operation to perform on the file or directory, op can be +, meaning add this permission for this person(s), or to take it away. Permission is r for readable, w for writable, and x for executable (files) or searchable (directories). Filename The name of the file or directory you’re setting permissions on. In the example below, we make the file go_cart s readable and writable for all users (it already was readable): venus% Is -1 go_carts (get current permissions) -rw-r — r — 1 medici 1024 Jun 27 17:06 go_carts venus % chmod a+rw go_carts venus % Is -1 go_carts -rw-rw-rw- 1 medici 1024 Jun 27 17:06 go_carts venus% ^ , Now, we set go_carts to be executable for the its owner (medici): microsystems Revision A, of 27 March 1990 Chapter 4 — Manipulating Files 4 1 venus % chmod u+x go_carts venus % Is -1 go_carts -rwxrw-rw- 1 medic i 1024 Jun 27 17:06 go_carts venus % V — — - i — — And, finally, we make go_cart s unreadable and unwritable for other users: r venus % chmod go-rw go_carts venus % Is -1 go_carts -rwx 1 medici 1024 Jun 27 17:06 go_carts venus % ■ J Setting Default Permissions When you create a new file or directory, the system automatically assigns per- With umask missions. The default setting for new files is -rw-r — r — For new directories, the default is drwxr-xr-x You can change the default permission setting for the current session with the umask command: umask ogp where o, g and p are digits corresponding to the permission masks of the owner, group, and public, respectively. You can change the permissions for umask uses three digits to determine the permissions. Permissions are com- all sessions by placing a umask p Uted accor ding to the following table: command in your .cshrc file. See SunOS User' s Guide: Customizing Your Environment. Table 4-6 Values and Permissions for New Files Files Directories value Permissions value Permissions 0 rw- 0 rwx 1 rw- 1 rw- 2 r — 2 r-x 3 r — 3 r — 4 -w- 4 -wx 5 -w- 5 -w- 6 — 6 — X 7 — 7 — umask does not activate execute permission for files. »sun microsystems Revision A, of 27 March 1990 42 SunOS User’s Guide: Getting Started Thus the command umask 2 or umask 002 yields permissions of -rw-rw-r — for files, and drwxrwxr-x for directories. The command umask 22 yields permissions of -rw-r — r — for files and drwxr-xr-x for directories. Ownerships Changing File Ownership With chown Files generally belong to the person or process that creates them. The ownership of a file can be changed with the chown command. Its syntax is chown new-owner filename NOTE For security reasons, only the “superuser” can change ownership with chown. See SunOS User’s Guide: Doing More. Here’s how you can reassign the file minnesota to the user holly: ' ’ — — \ venus % Is -1 minnesota -rw-r— r— 1 medici 30458 Jun 27 17:35 minnesota venus % su Password: (enter superuser password) venus# venus# chown holly minnesota venus# ~D venus% Is -1 minnesota -rw-r— r — 1 holly 30458 Jun 27 17:35 minnesota venus % ^ > Groups Each user may belong to one or more groups. Examples of groups are: everyone in marketing, all software engineers, or all users on a system. To find out which groups you belong to, use the groups command: f N venus% groups staff doc venus% V > The Is -lg command is very similar to Is -1; in addition to showing you who owns a file, it tells what the group ownership of a file is: A microsystems Revision A, of 27 March 1990 Chapter 4 — Manipulating Files 43 r A venus % Is -lg total 108 -rwxr-xr-x 1 medici staff 1024 Jun 27 17 :06 go_carts -rw-r — r — 1 medici staff 8111 Jun 16 18:31 letter. 1 drwxr-xr-x 2 venus % medici staff 1024 & 3 16 18:33 states V 4.16. Making Links A link is a name associated with a file. The SunOS operating system allows several links to a file at any one time, so the same file can have more than one name. This is useful when you want to get at a file quickly from within different directories. Moreover, you can keep a link to a file in a restricted directory, thus allowing people access to the file without giving them access to the forbidden directory. When you create a file, the system makes the first link, or filename, for you. To make an additional link, use the In command: In oldname newname If you attempt to make a link to a file in a directory that is on a different disk or disk partition than that of oldname, you will get an error message of the form: newname: Cross-device link In this case, you can use the -s option of In to make a symbolic link to the file: In -s oldname newname A symbolic link is an entry in the directory that points to the name of another file, rather than to the file itself. A symbolic link can be made across devices, and can be made even when oldname does not exist. Because a symbolic link refers to another file’s name, rather than to the file itself, it may be to your advan- tage to use a symbolic link instead of a regular link when you want to specify an alternate pathname to the same file. Both regular (hard) and symbolic links allow you to use newname instead of old- name to gain permitted access to a file. But neither a regular (hard) link nor a symbolic link changes the ownership, group, or permissions of a file. So even though you can make a link to a file that you can’t read, you still won’t be able to read its contents. In the case of a hard link, you can remove either the original file or the link, and you are still left with a copy of the file. In the case of a symbolic link, if you remove the original file you are left only with the link; that is, a pointer to a file that does not exist anymore. Revision A, of 27 March 1990 5 5.1. What Is vi? 5.2. Creating a File Starting vi vi is found in the directory /usr/ucb. Editing and Writing With vi vi is the standard SunOS text editor (“vi” stands for “visual display editor”). Since vi is not window-based, it can be used on any kind of terminal. You can enter and edit text with vi, but it is not a word-processor: you format vi text by inserting codes that are then interpreted by another program, a for- matter. (Chapter 6 teaches you the basics of formatting a page using nr of f and trof f codes.) In this chapter you’ll learn many of the most useful vi commands. You’ll find that it is a powerful text editor, but that it will take a little time in order to become proficient. More — and more technical — information can be found in “Using vi, the Visual Display Editor,” in Editing Text Files. Note that there is a read-only version of vi, called view. When you open a file with view, you can use vi commands, but you cannot write (or save) your changes. In this section you’ll leam how to start vi, enter text in a file, save (write) the file, and quit vi. A few simple commands will be introduced, and you’ll make a practice file that you’ll use for the rest of this tutorial. You’ll also leam about the three modes of vi: command mode, last-line mode, and input mode. To start vi, type at a prompt the command vi, leave a space, type a filename, and then press I Return I . (If this file already exists, vi will open it; if this is a new file, vi will create it.) For example, if you wanted to create a file called malleable, you would type: venus % vi malleable The vi screen will appear in a moment. microsystems 45 Revision A, of 27 March 1990 46 SunOS User’s Guide: Getting Started Entering Text Figure 5-1 New File \ "malleable" [New file] The cursor appears in the upper lefthand comer of the screen. Blank lines are indicated by a vertical series of tildes ( ~). The last line of the screen shows the name of the file and indicates that you’re creating a new file. One way to enter text in malleable is to type the letter a. This is a command meaning “append” — it won’t show on the screen. Now type a few short lines of text, ending every line with a I Return 1 . For the moment, you can correct your mistakes by backspacing and retyping a line before you press [ Return ] . Later you’ll learn how to make corrections in more sophisticated ways. When you’ve finished entering text in malleable, type fEsc) (“escape”). The cursor will move back onto the last character entered. Revision A, of 27 March 1990 Chapter 5 — Editing and Writing With vi 47 Saving Your Work Saving your work creates a record on disk of your file and any changes you’ve made to it. To save the text you’ve entered in malleable, type [ Esc ] (to ensure that vi doesn’t think you’re still adding text). Now type a colon (:) followed by a w (for “write”). Press I Return ) . Figure 5-2 Giving the Write Command According to Webster's Ninth New Collegiate Dictionary, "malleable" derives from the Latin [word "malleus," which means "hammer." The second definition given is "capable of being altered or controlled by outside forces or influences." In other words, a malleable person can be hammered into shape. :uQ After you type ( Return 1 . vi displays the filename, the number of lines in the file, and the number of characters in the file. Revision A, of 27 March 1990 48 SunOS User’s Guide: Getting Started Figure 5-3 File Saved "malleable" [New file] 8 lines, 298 characters * Quitting vi Now that you’ve saved (or written) the contents of malleable, you can safely quit vi. To quit vi, type a colon (:) followed by a q. Press ( Return 1 . The system will display the command prompt to indicate that you have quit vi. Printing a File Unformatted files can be printed out with the command lpr filename. This command will send the file to your default printer. See Section 4.14 and Chapter 6 for information on printing files formatted with nr of f and trof f. Some Theory: Command, vi has three modes — commmand, last-line, and input. You have already used Last-Line, and Input Modes features of each: When you started vi, it came up in command mode. Typing a put you in input mode. Typing I Esc ) took you out of input mode and put you back in command mode. Typing the colon in commands like : w or : q put you in last-line mode (also called “colon mode”). If vi seems to respond unpredictably, you may have inadvertently entered the wrong mode. You can always be sure that you’re in command mode by pressing [ Esc ) . 5.3. Moving Around in a File In the previous section you learned how to create a file. Now that you have some- thing to work with, you’ll want to find out how to look at different parts of the file and how to move around. Moving the Cursor When you start vi, the cursor is in the upper lefthand comer of the vi screen. You can move the cursor with a number of keyboard commands. Some letters, the arrow keys, and the keys for [ Return 1 . [ Back Space"! , and 1 Space Bar ] can all be used to move the cursor when in command mode. CAUTION Most vi commands are case-sensitive: the “same” command typed in lower- case and uppercase could have radically different effects. Arrow Keys If your machine is equipped with arrow keys, try these now. You should be able to move the cursor freely about the screen using combinations of the up, down, right, and left arrow keys. Of course, you can move the cursor only across already existing text or input spaces. (If you’re using a remote terminal, how- ever, the arrow keys may not work correctly, depending on your terminal emula- tor. Arrow key substitutes are discussed below.) microsystems Revision A, of 27 March 1990 Chapter 5 — Editing and Writing With vi 49 Figure 5-4 Arrow Keys Arrow Key Substitutes: h, j, k, 1 These keys work like arrow keys: To move left: press h. To move right: press 1. To move down: press j . To move up: press k. You can move a character or line at a time or, by holding down a key longer, move the cursor rapidly across the text. Figure 5-5 Cursor Moving Keys for vi ID 1 HI id PI IlflHH ImhI |W frsun Xr microsystems Revision A, of 27 March 1990 50 SunOS User’s Guide: Getting Started One Word: w, b; W, B Down: Return Left: Back Space Right: Space Bar Top: H Middle: M Bottom: L Scrolling Scroll Forward: Ctrl-F Scroll Down: Ctrl-D Scroll Backward: Ctrl-B Scroll Up: Ctrl-U 5.4. Inserting Text Append: a, A Pressing w (“word”) moves the cursor to the right a word at a time. Pressing b (“back”) moves the cursor left a word at a time. Pressing w or B moves the cursor past the adjacent punctuation, to the next or previous blank space. Pressing the I Return I key moves the cursor down. Pressing the I Back Space I key moves the cursor left. Pressing the I Space Bar ) moves the cursor right. Pressing H (“high”) moves the cursor to the top of the screen. Pressing M moves the cursor to the middle of the screen. Pressing L (“low”) moves the cursor to the bottom of the screen. You may have noticed that moving the cursor either to the bottom or top of the screen had the effect of scrolling text up or down. This may work okay for a very short file, but it’s a tedious way to move through a long file. By pressing the I Ctrl 1 key in combination with either f r d, b, or u, you can scroll through a file a screen or a half-screen at a time, backwards or forwards. (You might want to add text to malleable now to give yourself a longer file to experiment with.) To scroll forward (i.e., move down) one screenful, press [ Ctrl-F] , (By conven- tion, uppercase letters are used to designate these combinations, but lowercase letters are used in practice.) The cursor will move to the upper lefthand comer of the new screen. To scroll down one half-screenful, press [ Ctrl-D 1 . To scroll backward one screenful, press [ Ctrl-B 1 . To scroll up one half-screenful, press [ Ctrl-U 1 . vi has many commands for inserting text; this section introduces you to the most useful. By using a combination of cursor keys and the letters a , A, i , I , o, and 0, followed by 1 Esc 1 (“Escape”), you’ll leam how to insert text any- where in a file. Note that each of these commands puts vi in input mode. Starting from command mode (remember: press I Esc ) to be sure you’re in com- mand mode), you can insert text to the right of the cursor using a. Experiment by moving the cursor anywhere on a line and typing a, followed by the text you want to add. Press 1 Esc 1 when you’ve finished. Revision A, of 27 March 1990 Chapter 5 — Editing and Writing With vi 51 Insert: i, I Open Line: o, O 5.5. Changing Text Change Word: cw Change Line: cc Change Part of Line: C Substitute Character(s): s Replace Character: r Type A (uppercase!) to add text to the end of a line. To see how this works, posi- tion the cursor anywhere on a line and then type A. The cursor will move to the end of the line, where you can type your additions. Press I Esc I when you’re done. Insert text to the left of the cursor by typing i from command mode. Type I to insert text at the beginning of a line. (The command will move the cursor from any position on a line.) Again, as with all the commands in this sec- tion, press I Esc 1 to return to command mode. These commands are used to open new lines, either above or below the current cursor position. Typing o opens a line below the current cursor position. To experiment, type o, followed by a bit of text. Press I Esc I when you’ve finished. Typing 0 opens a line above the current cursor position. NOTE Occasionally you may need to instruct vi to clear or redraw the screen to elim- inate, e.g., extraneous system messages. Redraw the screen by entering com- mand mode and pressing [ Ctrl-L 1 . Changing text involves substituting one bit of text for another, vi has several ways of doing this, depending on circumstances. To replace a word, position the cursor at the beginning of the word to be replaced. Type cw, followed by the new word. To finish, type [ Esc ) . To change part of a word, place the cursor on the word, to the right of the portion to be saved. Type cw, the correction, and I Esc 1 . To replace a line, position the cursor anywhere on the line and type cc. The line will disappear, leaving a blank line for your new text (which can be of any length). Press I Esc 1 to finish. Typing C allows you to replace part of a line: that part to the right of the cursor. Press [Esc ) to finish. To substitute one or more characters for the character under the cursor, type s, followed by the new text. Press I Esc ) to return to command mode. This command is given to replace the character under the cursor with another character. To use it, position the cursor over a character and type r, followed by just one replacement character. After the substitution, vi returns automatically to command mode (there’s no need to press 1 Esc ] ). microsystems Revision A, of 27 March 1990 52 SunOS User’s Guide: Getting Started Transpose Characters: xp Undo Previous Command: u Undo Changes to Line: U Break or Join Lines: r+Retum, J 5.6. Deleting Text Delete Character: x Delete Word: dw Delete Line: dd Delete Part of Line: D 5.7. Using Repeat Factors and Repeating Commands Correcting transposed characters takes just two keystrokes in vi. Say you find that you’ve typed teh when you meant to enter the (this writer does it all the time!). Make the correction by putting the cursor over the first letter to be moved (in this case, e) and then giving the command: xp. The e and the h will trade places — and vi will automatically return to command mode. When making corrections, you’ll sometimes wish you had not changed some- thing. In vi you can “undo” your last command simply by pressing u. (Pressing u a second time undoes the “undo.”) Type U to undo all changes you’ve made to a line. This command will work only if you haven’t moved the cursor off the line. To break a line without affecting text, move the cursor to the breaking point (so to speak) and give the command r (for “replace”) followed by [ Return 1 . To join two lines, place the cursor on the upper line and type the command J. These vi commands simply delete the character, word, or line you indicate, vi stays in command mode, so any insertions have to made with additional com- mands to enter input mode. To delete one character, position the cursor over the character to be deleted and type x. Using x to delete a letter will also delete the space the letter occupied — when a letter is removed from the middle of a word, the remaining letters will close up, leaving no gap. You can also delete blank spaces in a line with the x command. To delete a word, position the cursor at the beginning of the word and type the command dw. The word and the space it occupied will be removed. To delete part of a word, position the cursor on the word, to the right of the part to be saved. Type dw to delete the rest of the word. To delete a line, position the cursor anywhere on the line and type the command dd. The line and the space it occupied will be removed. You can also delete part of a line — everything to the right of the cursor. To do this, position the cursor to the left of the part of the line you want to delete and type D. To leam how to delete text using last-line commands, see below. Many vi commands can be preceded by a repeat factor — a number that pre- cedes the command and tells it how many times to operate. All the commands in the previous section take repeat factors. For instance, 3dd would delete three lines, 2dw would delete two words, and 4x would delete four characters or spaces. Ip sun Xr microsystems Revision A, of 27 March 1990 Chapter 5 — Editing and Writing With vi 53 5.8. Copying and Moving Text — Yank, Delete, and Put Copying Lines Y is synonymous with yy. Typing a period (.) repeats the previous text-changing command. So if you’ve deleted a line with dd, you can move the cursor to another line and delete it by typing just a period. Many word-processors allow you to “copy and paste” and “cut and paste” lines of text. Fortunately, vi follows suit in this regard. The vi command-mode equivalent of “copy and paste” is yank and pur, the equivalent of “cut and paste” is delete and put. You can also copy and move text using last-line commands. Both methods are disussed below. An easy way to copy or move small blocks of text is to use a combination of yank, delete, and put commands. To copy a line requires two commands, using yy or Y (“yank”) and either p (“put below”) or P (“put above”). To yank one line, position the cursor anywhere on the line and type the command yy. Now move the cursor to the line above where you want the yanked line to be put (copied). Type the command p. A copy of the yanked line will appear in a new line below the cursor. You have the option of putting the yanked line in a new line above the cursor: type the command P to do this. The yy command works well with a repeat factor: to yank 1 1 lines, for example, just type llyy. Eleven lines, counting down from the cursor, will be yanked, and vi will indicate this with a message at the bottom of the screen: 11 lines yanked. Moving Lines Moving lines also requires two commands: dd (“delete”) and either p or P. To move one line, position the cursor anywhere on the line and type the com- mand dd; to delete, e.g., five lines, type 5dd. Next, move the cursor to the line above where you want the deleted line rein- serted. Type the command p. Again, you can put the deleted line above the cursor by typing P. CAUTION Use only cursor-moving commands between yanking or deleting and put- ting. You can also use the search commands — / , ? , n — discussed below. 5.9. Copying, Moving, and Last-line commands are more accurate and convenient than yank, delete, and put Deleting Text — Last- when you’re dealing with large blocks of text. Rather than counting lines on the Line Commands screen and then searching for an insertion point, you give vi a range of lines to be moved or copied and then specify the line before the insertion point. (Of course, with the delete command there is no insertion point.) microsystems Revision A, of 27 March 1990 54 SunOS User’s Guide: Getting Started Turning on Line Numbers Turn line numbers on by typing the command : set nu and pressing I Return ) . Figure 5-6 Setting Line Numbers Department of Defense, for example. Philosophically related to newspeak is the :set niQ ^ Line numbers will appear in the left margin. Note that these numbers do not print out on hard copy of a file. They are visible only on the screen. Turn line numbers off by typing the command r — — x :set nonu ^ , and pressing [ Return ] . #sun microsystems Revision A, of 27 March 1990 Chapter 5 — Editing and Writing With v i 55 Copying Lines Figure 5-7 Line Numbers Displayed 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 :set nu QccorcHn^tQ ' Webster ' s Ninth New Collegiate Dictionary, "malleable" derives from the Latin word "malleus," which means "hammer." The second definition given is "capable of being altered or controlled by outside forces or influences." In other words, a malleable person can be hammered into shape. The malleability of the individual has long been an acknowledged fact of life in modern societies. Some may object that this is true of all societies throughout history. Perhaps. Still, the second half of this century has seen the manufacture of consent become industrialized, thanks to the mass media and the ruling elites that effectively control them. George Orwell, in his famous novel "1984," was one of the first to sketch the outlines of the world in which we've lived since the close of World War II. Less part of the science-fiction genre than is commonly supposed, "1984" presents the essential characteristics of post-war life as found in both the West and the East. Orwell^s book was originally to have been entitled "1948," a year when many thought the State ruled supreme. (It was about this time that Andre Breton, founder of the Surrealist movement, declared that while the Nazis had lost the war, they had won a moral victory!) It was Orwell who critically codified "newspeak," which was already widely used by the new bureaucracies engendered by the demands— and opportunities — of the war. In the USA, the War Department became the Department of Defense, for example. Philosophically related to newspeak is the The basic form of the last-line copy command is : line#, line# co line# The first two numbers (separated by a comma) specify the range of lines to be copied. The third number is the line before the insertion point. For example, to copy lines 15 through 20 of malleable and place the copy after line 30, you would give the command 1 : 15,20 co 30 J and press I Return 1 . microsystems Revision A, of 27 March 1990 56 SunOS User’s Guide: Getting Started When specifying line ranges, you can use the abbreviations . (period) to denote “from cursor” and $ (dollar sign) to denote “to end of file.” Thus, to copy the range “from cursor position through line 20” and insert this block after line 30, you would give the command : . , 2 0 co 30. To copy the range “from line 15 through the end of the file” and insert this block after line 5, you would give the command : 15, $ co 5. Moving Lines The basic form of the last-line move command is similar to the copy command discussed above: : line# , line# m line# Line ranges and insertion points are specified in the same ways, including use of the abbreviations . and $. The difference in function is simply that “move” deletes a block from one location and reinserts it elsewhere. For example, to move lines 3 through 12 to the line following 21, you would give the command ( — — : 3 , 12 m 21 -\ v : : and press I Return I . You can delete a range of lines using the command form : line#, line d So, to delete lines 19 through 31, you would give the command / 1 — : 19, 31 d NOTE To “undo" last-line commands, give the command : u and press I Return 1 . Or just type u without first typing a colon. 5.10. Searching and vi provides several ways of finding your place in file (either by line number or Replacing by locating a string) or finding a specific bits of text and editing them. It also has a powerful replace function. Finding a Character String A character string is simply one or more characters in a row. It may include letters, numbers, punctuation, special characters, blank spaces, tabs, and carriage returns. A string may be a grammatical word or it may be part of a word. To find a character string, type / followed by the string, and then press I Return 1 . vi positions the cursor at the next occurrence of this string. Type n to go to the next occurrence of the string; type N to go to the previous occurrence. You can type ? instead of / to search backward in a file. In this case, the direc- tions of n and N are reversed. In any event, vi searches in either direction wrap around the end of a file, looking for the string wherever it may occur. Revision A, of 27 March 1990 Chapter 5 — Editing and Writing With vi 57 Refining the Search Searches normally are case-sensitive: a search for “china” will not find “China.” To look for a string in malleable, first type / and then type a common word, disinformation, for example. Press I Return j . If vi finds the string, the cursor will stop at its first occurrence. If the string is not found, vi will display Pattern not found on the last line of the screen. For the advanced user: You can make searches more precise by tagging the string with indicators for, among other things, “beginning of line,” “end of line,” “beginning of word,” and “end of word.” You can also generalize a search by using wild-card characters. (More information on these special search characters can be found in the section on grep in Section 7.1 1.) To match the beginning of a line, start the search string with a caret ( '). To find the next line beginning with “Disinformation,” give the command — — /^Disinformation To match the end of a line, end the search string with a dollar sign ( $). To find the next line ending with “disinformation.”, give the command (Note that the period is quoted with a backslash.) To match the beginning of a word, type \< at the beginning of the string; to match the end of a word, type \> at the end of the string. Thus, to match a word, combine the end-of-word and beginning-of-word tags in the search pattern. To find the next occurrence of the word — as opposed to the string — “disinformation,” give the command /\ > To match any (unknown or variable) character, type a period (.) in the string. To find the next occurrence of “disinformation” or “misinformation,” give the com- mand f ~ 7 "T - / . isinf ormation J microsystems Revision A, of 27 March 1990 58 SunOS User’s Guide: Getting Started Because this is a string, and not a word, this search pattern will also find “misin- formationalist” and “disinformationism.” Brackets may be used to search for alternative characters in a string. / [md] string will find strings beginning with either “m” or “d.” On the other hand, [d-m] string will find strings beginning with any letter from “d” through “m.” To match zero or more occurrences of the last character, type an asterisk (*) in the string. You can effectively combine brackets and the asterisk to look for well-defined alternatives. To find all strings beginning with “a” through “z” and ending with “isinformation” and to find all occurrences of the string “isinforma- tion,” give the command / [a-z] *isinformation , Replacing a Character String The procedure for replacing a text string is based on the search procedures dis- cussed above. All the special matching characters for searches may be used in search-and-replace. The basic command form is :g/ search-string/ s/ / replace-string / g followed by I Return 1 . Thus, to replace every occurrence of the string “disinformation” with “newspeak,” you would give the command c — — — — : g/disinf ormation/s//newspeak/g v. _ y and press [ Return 1 . You can modify this command to halt the search and make vi query whether you want to make the replacement in each instance. The commmand : g/ disinformation/ s//newspeak/gc (adding the c for “consult”) will make vi stop at every occurrence of “disinformation” and ask whether you want to make the substitution. Respond with y for yes or n for no. NOTE You can cancel a “ consulted ” search-and-replace by pressing {Ctrl-C 1 . Finding a Specific Line vi provides ways of accessing parts of a file by either opening the file to a specific line or by finding a line in an already opened file. Going to a Line With G You can go to the last line of an open file by typing G. Return to the first line of the file by typing 1G. You can go to any other line by typing its number followed by G. For example, say you’ve quit the malleable file while editing line 51. You can access that line by opening the file and typing 51G. Revision A, of 27 March 1990 Chapter 5 — Editing and Writing With vi 59 Opening a File at a Specific You can also start vi and open a file at a specific line. At a command prompt, Line type vi +line # filename To start and open malleable at line 51, give the command r venus% vi +51 malleable \ — (By not supplying a line number after the plus sign, you can make vi open malleable at the tot line of the file.) Opening a File at a Pattern You can open a file to the first line containing a specific string by typing at a command prompt vi +/ pattern filename For example, to open malleable at the first line containing the string “2+2=5,” you would give the command r venus % vi +/2+2=5 malleable and press 1 Return 1. Enclose multiple-word strings in double quotation marks, e.g.: ( venus % vi +/"Andre Breton 1 ' malleable V ' ■ 5.11. Inserting a File Into a vi makes it convenient to “read” (insert) a file into the file you’re editing. The File general form of the command is -.line# r filename If you do not specify a line number, vi puts the file at the current cursor posi- tion. If you were working on the file malleable and you wanted to read in another file called orwell, and you wanted it placed at line 84, you would give the command Revision A, of 27 March 1990 60 SunOS User’s Guide: Getting Started 5.12. Ending a Session Using the Buffer When writing or editing a file in vi, your changes are not made directly to the file. Instead, they are applied to a copy of the file that vi creates in a temporary memory space called the buffer. The permanent disk copy of the file is modified only when you write (save) the contents of the buffer. This arrangement has its good and bad points. On the one hand, it means that you can quit a file and discard all the changes you’ve made during an editing session, leaving the disk copy intact. On the other hand, you could lose the (unsaved) contents of the work buffer if the system crashes. (People on remote terminals connected by phone lines are especially vulnerable to unplanned interruptions.) Probably the best policy is to save your work frequently, especially when making substantive changes. CAUTION Although it’s possible to run multiple, simultaneous vi sessions on one file, it is not a good idea. Great confusion could result when you try to determine which changes have been written to the file. Saving Changes and Quitting vi is rich in more or less synonymous commands that control saving the buffer v i contents to a file and quitting vi. These commands give you the option of sav- ing, saving-and-quitting, or quitting-without-saving. Savin S Save the contents of the buffer (or, write the buffer to the file) by giving the com- mand followed by I Return 1 . Saving and Quitting Save and quit by giving the command r — : wq Alternatively, type z Z. Note that this command is neither preceded by a colon nor followed by I Return I . Quitting Without Saving When you’ve made no changes to a file and simply want to quit, give the com- mand :q V If you have made changes, vi will not let you quit. Instead, it will display the message, No write since last change (:quit! overrides). If you do not want to save your changes, give the command Revision A, of 27 March 1990 Chapter 5 — Editing and Writing With vi 61 NOTE You can “ suspend ” or interrupt vi by typing \Ctrl-Z) . A comman d promp t will appear. To return to vi , type fg at the command prompt. Press ( Return ) . Recovering From a Crash If the system crashes, the contents of your buffer are at risk. Often, though, you can recover most of your work by restarting vi with the command form vi -r filename The system will usually send you mail about this. You would recover malle- able by giving the command r ” venus % vi -r malleable — 5.13. Customizing vi vi has many variables that affect its behavior and appearance. You can view a list of these variables (with their current settings) by giving the command r~ > : set all « — ,, , J followed by I Return 1 . Refer to “vi and the . exrc File” in SunOS User’s Guide: Customizing Your Environment for information on how to set the options you want as defaults every time that you start vi. “Using vi, the Visual Display Editor,” in Editing Text Files, discusses these options in detail. That chapter also contains information on how to set up the many different display terminals on which vi mns. Type at a prompt man vi for additional information. 5.14. Problems With vi If you run into difficulties running vi, SunOS User’s Guide: Basic Troubleshoot- ing offers some tips on handling minor problems. 5.15. A Note on ex vi is a superset of ex, a line-oriented text editor, ex commands can be com- bined with vi commands. In fact, you’ve already used some: commands pre- ceded by a colon are examples of ex commands ( : w , : q ! ). For more infor- mation, see “Command Reference for the ex Line Editor,” in Editing Text Files. Revision A, of 27 March 1990 62 SunOS User’s Guide: Getting Started Table 5-1 Basic vi Commands Basic vi Commands vi filename Starting vi open or create file vi +18 filename open file to line 18 vi +/"mustard greens" filename open file to first occurrence of “mustard greens” vi -r filename recover crashed file view filename open file read-only h Cursor Commands move left j move down k move up 1 move right w move right one word w move right one word (past punctuation) b move left one word B move left one word (past punctuation) Return move down one line Back Space move left one character Space Bar move right one character H move to top of screen M move to middle of screen L move to bottom of screen Ctrl-F scroll forward one screen Ctrl-D scroll forward one-half screen Ctrl-B scroll backward one screen Ctrl-U scroll backward one-half screen a Inserting Characters and Lines insert characters to right of cursor A insert characters to right of cursor, at end of line i insert characters to left of cursor i insert characters to left of cursor, at beginning of line o insert line below cursor 0 insert line above cursor cw Changing Text change word (or part of word right of cursor) cc change line C change part of line to right of cursor s substitute string for character under cursor r replace character under cursor with one other character r-Return break line J join current line and line below xp transpose character at cursor & character to right change case of letter (upper or lower) u undo previous command U undo all changes to line : u undo previous last-line command £S2 Revision A, of 27 March 1990 Chapter 5 — Editing and Writing With vi 63 Table 5-1 Basic vi Commands— Continued Basic vi Commands X Deleting Text delete character dw delete word (or part of word to right of cursor) dd delete line D delete part of line to right of cursor : 5, 10 d delete lines 5-10 yy Copying and Moving Text yank or copy line Y yank or copy line dd delete line p put yanked or deleted line below current line P put yanked or deleted line above current line : 1 , 2 co 3 copy lines 1-2 and put after line 3 : 4 , 5 m 6 move lines 4-5 and put after line 6 :set nu Setting Line Numbers show line numbers :set nonu hide line numbers G Finding a Line go to last line of file 21G go to line 21 /string/ Searching and Replacing search for string ? string? search backward for string n find next (or previous) occurrence of string : q / search-string / s / / replace-string/ gc search and replace, consult at each occurrence Ctrl-L Clearing the Screen clear scrambled screen : r filename Inserting a File Into a File insert (read) file after cursor : 3 4 r filename insert file after line 34 : w Saving and Quitting save changes (write buffer) : w filename write buffer to file : wq save changes and quit vi ZZ save changes and quit vi : q ! quit without saving changes Revision A, of 27 March 1990 6 Formatting and Printing Documents Text editors like vi produce “raw,” unformatted files. A text formatter lets you specify concisely the way you want your printout to look. You can add special attributes, like different fonts and intensities, that would be impossible without the formatter. In this chapter, you will leam the basics of the SunOS formatters called nrof f andtroff. nroffis used to produce typewriter-like output for conventional dot-matrix and letter-quality printers, though it may be used for laserprinters. While trof f was developed to produce output for phototypesetters, it’s mainly used now to format text for laserprinters. All the commands discussed in this chapter work with both programs. The versions of nrof f and trof f discussed here reside in your /usr/bin directory. 6.1. Sample Memo To help you leam nrof f and trof f , we’ve included two forms of a sample memo. First you’ll see the printed version of the memo, as it would come out of a laserprinter. Then you’ll see the file as you would input it on your screen, with the formatting commands visible. Compare the two versions line for line to see how the nrof f and trof f commands affect the final copy. microsystems 65 Revision A, of 27 March 1990 66 SunOS User’s Guide: Getting Started From: Board of Directors To: Vociferous Employees Cut Paper Waste on Memos It has come to our attention that certain employees of this company have been printing inordinate numbers of inter-office memos. As you know, our distinctive Flying Headstone stationery is quite expensive. We have decided to take three immediate steps to counter this threat to cor- porate profitability: 1) We wifi reduce paper stocked for the printers by 25% within month-end. 2) We will begin terminating employees randomly. 3) We will open fire on anyone caught within 1 00 yards of a printer. If these steps do not stop the proliferation of memos, we will consider sending out an even stronger note on the subject. Acn n microsystems Revision A, of 27 March 1990 Here is the sample memo before formatting. All of the lines that begin with a period are nr of f and tr of f formatting commands. .LP From: Board of Directors .br To: Vociferous Employees • sp . ce .1 "Cut Paper Waste on Memos" .LP It has come to our attention that certain employees of this company have been printing .UL inordinate numbers of inter-office memos. As you know, our distinctive Flying Headstone stationery is quite expensive . .LP We have decided to take three immediate steps to counter this .B threat to corporate profitability: .IP 1) We will reduce paper stocked for the printers by 25% within month-end. .IP 2) We will begin terminating employees randomly. .IP 3) We will open fire on anyone caught within 100 yards of a printer. .LP If these steps do not stop the proliferation of memos, we will consider sending out an even stronger note on the subject. 6.2. Basic Formatting The commands in lowercase letters are called primitives : they are the simplest Commands commands, directing the formatter to break a line, add a space, or center the text. The uppercase commands are called macros: they are preprogrammed combina- tions of primitives that tell tell nrof f and trof f to do more complicated things, like create an itemized paragraph. The macro package used in this chapter is called -ms. . LP to left-justify a paragraph .IP to create an itemized paragraph (like this one) . I to italicize text in trof f (or to underline in nrof f ) .UL to underline text in both tr off and nr off Revision A, of 27 March 1990 68 SunOS User’s Guide: Getting Started Left-Justified Paragraph Itemized Paragraph Italicizing Text Underlining Text Boldface Text Centering Text Line-Spacing Line Breaks 6.3. Formatting and Printing the File . B to make text boldface in trof f (or to strike over in nrof f ) . c e to center text on the page . sp to create a blank line-space . br to force the end of a line, a line-break Use the . LP command to begin a paragraph without indentation. . LP must appear all by itself on the line before the paragraph. The . IP command begins an itemized paragraph. An itemized paragraph starts with an item, say the figure 1, followed by an indented paragraph of text. Put . IP on its own line, followed by the item you want to mark the paragraph. The itemized paragraphs in the sample memo are enumerated paragraphs, but you can also begin itemized paragraphs with other items. To italicize a word, type the . I command at the beginning of a line, followed by the word on the same line. (This command underlines in nrof f .) If the text to be italicized is more than one word long, enclose the text in double-quotation marks (" "). To underline text, type the . UL command at the beginning of a line, followed by the text you want underlined. If the text to be underlined is more than one word long, enclose the text in double-quotation marks (" "). To boldface text, type the . B command at the beginning of a line, followed by the text on the same line. (In nrof f , the the printer will attempt to strike over the text.) If the text to be made boldface is more than one word long, enclose the text in double-quotation marks (" "). When you have a title or headline to center, type the . ce command on a line by itself, then type the text you wish to center on the next line. . sp creates an empty line, or line-space, in the file. Type . sp on a line by itself. When you want a line to end at a specific point, type . br on a line by itself. Once text has been input and coded, it’s time to run the nrof f and trof f for- matters on the file and print it. microsystems Revision A, of 27 March 1990 Chapter 6 — Formatting and Printing Documents 69 Using nroff For more on pipes, see Chapter 7. Using troff 6.4. Where To Find Out More About Formatting To run the nroff formatter, give the following command: venus% nroff -ms sample. memo > sample. ms venus % sample .ms is the nroff -formatted file. (People often name formatted files after the macro package.) You can preview the formatted file on screen by using the more program: To print the formatted memo, type lpr followed by the filename of the format- ted file: ( A venus% lpr sample. ms venus% — Alternatively, you can format and print without creating an intermediary file. You do this by running nroff on the file and then piping the output to the printer command: r A venus % nroff -ms sample. memo | 1 lpr venus % V - - J To preview, pipe the command to more instead of to lpr. Then, when the document is ready to print, repeat the command and pipe it to lpr. Format and print your file by running troff on the file and then piping the out- put to the printer command: r \ venus % troff -ms -t sample .memo lpr -t venus% V / No preview function is supplied for troff -formatted files. See Using nroff and troff, Formatting Documents, and the nroff and troff man pages for more information. ©sun microsystems Revision A, of 27 March 1990 7 Basic Command Syntax 7.1. SunOS Commands: The SunOS operating system may seem complex and arcane; it is, however, very An Overview flexible and powerful. It allows you to create your own commands, devise shortcuts for repetitive tasks, and perform complex tasks quickly and easily. Before you read this chapter, you should have a basic knowledge of the SunOS file system and how to manipulate it; this information is contained in Chapters 3 and 4. Another shell — the Bourne shell — is also available. See SunOS User's Guide: Doing More. Figure 7-1 This chapter introduces the command syntax of the SunOS C shell. The C shell is a command interpreter — it deciphers and executes the commands you put together. You can think of the C shell as a layer of software between you and the internal workings (or kernel) of the system. Where the C Shell Sits This tutorial combines C shell commands with SunOS utilities such as cat, sort, head, tail, ps, at, batch, and grep. These essential concepts of shell use are discussed and illustrated: □ Parts of the command line; microsystems 71 Revision A, of 27 March 1990 72 SunOS User’s Guide: Getting Started 7.2. Starting a C Shell 7.3. Arguments and Options □ Filename matching; □ Redirecting standard input and output; □ Redirecting standard error; □ Filters; □ Command line editing with the history mechanism; □ Processes; a Aliases; □ Running commands in the background; and □ Searching for patterns. You can write simple programs for the C shell, to do many types of tasks. SunOS User’s Guide: Doing More explains how these programs, called “shell scripts,” work. SunOS User’s Guide: Doing More also continues the discussion of the history mechanism and demonstrates the use of variables in the C shell. Addi- tonal information on the C shell can be obtained by typing man csh at a prompt. A C shell is started whenever you log in or give the commands shelltoolor cmdtool (‘Shell Tool’ or ‘Command Tool’ in the SunView menu). A subshell (a shell within a shell) is started with the command csh. Type exit to escape a subshell. A command line is composed of a command and arguments. Consider this example: This command line consists of a command and two arguments. There are several kinds of arguments: they may be be options, objects, patterns, redirection sym- bols, or even other commands. Here’s a breakdown of this command line: Is A command, to list contents of directories. - 1 An option, modifying the behavior of 1 s . * . ps The object of the command — in this case, the files Is is to display. Every argument is associated with a command. In our example command line, everything to the right of Is can be considered an argument of Is. Revision A, of 27 March 1990 Chapter 7 — Basic Command Syntax 73 Options Certain arguments, like -1, are called command options. They modify the behavior of a command. Each command has its own unique options (or it may have none at all). If you look at the page on Is in the SunOS Reference Manual, you’ll see that Is has 20 or so options. (Some of these are described in detail following Section 4.7.) Options typically start with a dash (-). 7.4. Matching Filenames The abbreviations (or “metacharacters”) ? and * are explained in Chapter 4. Briefly, * matches one or more characters in a file’s name, and ? matches any single character. r venus% Is ma* A maine maple marsh manitoba maryland venus% Is ma??? maine maple marsh venus% v Other Syntaxes for Matching In addition to the wild cards * and ?, the SunOS operating system provides more Filenames sophisticated ways of specifying a set of files on the command line. Single-Character Matching with You can use brackets instead of a ?, to match a single character. Within the [ and ] brackets you can specify a list of characters to match against. For instance, [ab]* matches all filenames that begin with a lowercase a or b. You can also specify a range of characters to match against. Thus, [A-Z]* matches all filenames that begin with an uppercase alphabetical character. You can use braces instead of * to match specific character strings of any length. Within the braces, strings are separated by commas. For instance, { uranus , sygnus , x } * matches any filenames beginning with uranus, sygnus or x. Within braces, * and ? are legal. You can nest braces within strings for interest- ing results. For instance, { { ura , syg } nus, x } * is another way to match filenames beginning with uranus, sygnus or x. 7.5. Command Sequences Separating Commands With a Semicolon You can combine several commands on one line by separating them with a semi- colon (;). Xr microsystems Revision A, of 27 March 1990 74 SunOS User’s Guide: Getting Started venus % cd /usr/ spool ; pwd /usr /spool (pwd prints out current directory) venus % ' y Continuing Long Command If a command line is longer than the width of the screen you’re typing it in, you Lines can break it up with a backslash (\). V venus% /bin/ rm xout line; egrep -h "'\FN| “ ,TN| * .H" \ preface 'cat Listfile' > xoutline venus% V 7.6. Redirecting Input and Unless you indicate otherwise, commands normally display their results on the Output terminal screen. In this case, the terminal is known as the command’s standard output. Also, commands normally operate on data as you type it in from the keyboard; normally, then, the terminal is the command’s standard input. Because SunOS commands treat files and devices in a uniform way, you can direct the output of a command to any file or device that you choose. You can also use the output of one command as direct input to another, using a special connection symbol called a pipe (explained later). Or you can obtain the input to a command from a file. Redirecting the Standard A right angle-bracket (>) (pronounced “into”) on the command line indicates Output that the next word is the name of a file or device in which to place, or redirect the output of a command. For instance, the command line: ■N venus% Is > list venus % (. ij places the output of the Is command (a list of files) in a file named list. CAUTION If a file by that name already exists, any previous contents may be deleted before the command is performed. So the command cat filel > file2 removes all existing contents from file 2 before the cat command is executed. To avoid writing over existing files, add a line with the command set noclobber to your . cshrc file, if one isn’t there already. (Refer to SunOS User’s Guide: Customizing Your Environment for more information about this file.) Then, to make changes effective now, type in the command: A microsystems Revision A, of 27 March 1990 Chapter 7 — Basic Command Syntax 75 If using windows, type this source command in each shelltool or cmdtool window, so that the change will take effect in each. ( venus % source "/.cshrc : \ venus % i V When you are certain that you want to overwrite the previous contents of a file, use > ! to override this file protection. r \ venus % cat filel >! file2 venus % (file2 is overwritten) ( .— — / Appending to an Existing File You can append to the end of a file using a double right angle-bracket (») (pro- nounced “onto”). For example, in the example below, we add the output of the pwd command (showing the current directory) to the file list, created above. With noclobber set, a file must already exist before the standard output can be appended to it. Using »! overrides this. \ venus% Is > list ( create list) venus % cat list (look at it) sees esh . 1 files list outline philosophy picturel preface venus % pwd » list (append the output of pwd) venus % cat list (look at list again) secs esh . 1 files list outline philosophy picturel preface / home / venus /medi ci venus % V j Redirecting Input Just as you can redirect the output of a command, you can also specify a file (or device) from which that command obtains its input. You can use a left angle-bracket (<) (pronounced “from”) to redirect the standard input of a command. For instance, in the example above we used the command cat list to show the contents of the file list; another way would have been to say cat < list Most commands, like cat, allow the input file to be specified as an argument. However, other commands, such as crypt, only read from the standard input sun microsystems Revision A, of 27 March 1990 76 SunOS User’s Guide: Getting Started Pipes and Pipelines Filters and thus require the use of <. The output of one command can be fed in directly as input to another. A set of commands strung together in this way is called a pipeline. The symbol for this input/output (I/O) connection is a vertical bar ( | ) (pronounced “through”), called a pipe. Pipes and pipelines have a wide variety of uses. As an example, suppose you wanted to know how many files there are in a direc- tory. You could use Is to display the contents of the directory, and then hand- count the number of files it shows. An easier way is to pipe the output of 1 s through the command wc, a word-counting program. wc displays the number of lines, words, and characters, respectively, of the input given it. Here’s how you’d count the number of files in the directory /etc: venus % Is /etc | wc 86 86 684 venus % k t As you can see, the example displays only the output of wc; the output of Is feeds into wc. wc itself tells us that the output of Is contained 86 lines, 86 words, and 684 characters. Since each file makes up one word of the output of Is, we know that / etc contains 86 files. (Is displays only one file to a line when the output doesn’t go directly to the screen.) You can connect several commands to make longer pipelines. For instance, the command line: / -v venus % Is /etc | grep '~re.*' I wc 4 4 32 v displays the number of files in /etc starting with “re” (four). (The grep com- mand is explained in Section 7.1 1.) Commands like wc are called filters. They accept text as input, transform or analyze it, and produce text as output. Although often used as commands in their own right, filters are especially useful in pipelines. Is is not a filter, because it doesn’t accept data from the standard input. That is, you can’t give Is any data to work on, because it gets its information from the directory structure. The date command isn’t a filter, either, even though you can give it data (i.e, you can set the date). Why not? Because you can only give it information by way of command-line arguments. As you might expect, the command Is | date produces only the date, since dat e ignores its standard input. And Revision A, of 27 March 1990 Chapter 7 — Basic Command Syntax 77 date I Is produces only the output of Is. Here are some other things you can do with filters: display data one screenful at a time (more) As explained in Section 4.9, the more command displays a file in screen-size chunks. This also works for output sent to more from another command. search for specific patterns (grep) grep allows you to look for just the output lines which are of interest to you. grep is covered in detail in Section 7.1 1. display the first n lines of a file (head) The head command shows the first lines of a file; you can specify how many lines you want displayed. (The default is ten.) head is useful for quickly com- paring similarly named files. Here we compare the first four lines of three files: venus % cat speech* | head -4 ==>speechl<== Fourscore and seven years ago — or, say, seven dozen and three years ago — or, for those in the audience who like Base Two, forty-three and one-half pairs of years ago— our forefathers ==>speech2<— I'm reminded of the famous story of the two Hungarian shoe salesmen and the Emperor penguin. It seems that two Hungarian shoe salesmen were in Antarctica — I forget why they were in Antarctica, ==>speech3<== Ladies and gentlemen, I have a dream. It is a dream deeply rooted in the American dream. In it I am flying over my high school, and it's the last day of classes, and I've forgotten to study, venus % V / display the last n lines of data (tail) Similar to head, tail displays the last n lines. With no -n argument, it displays the last ten. tail +n skips to line n and displays that line through the end of the file. display data, finding a search pattern (more +) The command more +/ pattern begins displaying data two lines before the first match for pattern, which can be either a string or a grep search pattern (described in 7.1 1). more is also described in Section 4.9. microsystems Revision A, of 27 March 1990 78 SunOS User’s Guide: Getting Started lpr is the command for printing files. display nonprinting characters (cat -v) cat -v translates nonprinting characters into strings of regular characters of the form 'c (for control characters), or M-c (for 8-bit characters). sort lines in predetermined order (sort) The sort command sorts and collates lines according to an order you specify. Refer to sort in the SunOS Reference Manual for more information. For exam- ple, sort -n sorts in numerical order, format text (fmt) f mt does rudimentary formatting of text. For example, you can make all your lines in a file, or in a text window, 72 characters long. reverse order of characters in a line (rev) rev reverses the order of characters within each line. reformat input (pr) pr, like fmt, reformats input. pr is useful for preparing files for printing. For example, cat filename | pr -t -n | lpr breaks up the output into n columns. The -t option suppresses a heading that would otherwise appear. There are a number of options to pr; see the SunOS Reference Manual for more information. check spelling (spell) spell produces a list of (possibly) misspelled words. perform simple editing on files or output (sed) sed uses regular expressions to represent patterns of text. (Regular expressions and sed are explained in Editing Text Files.) Suppose you’re using the grep utility to find instances of the word “butter” in various files, (grep is explained in Section 7.11.) ? * venus % grep "butter" chap* chapl:the world's butter supply in danger, we chap8: butter and motor oil to make a delicious chap30:life as we know it without butter would be chapll2 : primitive butter-worshiping peoples in Central venus % \ / You can use sed to modify the output to make it easier to read: fsun microsystems Revision A, of 27 March 1990 Chapter 7 — Basic Command Syntax 79 < “ — '> venus% grep "butter" chap* | sed "s /:/: /" chapl : the world's butter supply in danger, we chap8 : butter and motor oil to make a delicious chap30: life as we know it without butter would be chapl 12 : primitive butter-worshiping peoples in Central venus % s Redirecting the Standard Error You can redirect the standard error to the same destination as the standard output by appending an ampersand (&) to the output-redirection symbol. >& sends both standard and diagnostic output to a destination file. »& appends the output to the file. | & includes both types of output as input to the next com- mand in the pipeline. If you want a command to perform silently, that is, to display no output of either kind, you can redirect its output to /dev/null, the system “wastebasket.” command >& /dev/null To separate the standard error from the standard output, use a command line of the form: ( command > out file) >& errorfile When you want to force output to appear on the terminal, you can redirect it to /dev/ tty (a synonym for the name of the terminal). command >& /dev/tty So the command r ) venus % (program > /dev/null ) >& /dev/ tty • — J throws away the standard output and displays only the error messages produced by program (if any). This construction can save you time when testing long- running commands. When a command performs without problems, it produces results on its standard output. But when a command encounters a problem, it uses a different channel to send error messages to the terminal. This second channel, called the standard error, can also be redirected. fsun microsystems Revision A, of 27 March 1990 80 SunOS User’s Guide: Getting Started Using Backquotes Table 7-1 Summary of Redirection Symbols > send output to named file > ! same, overwrite file if it exists > & send standard error to file » append output to file » ! same, overwrite file if it exists » & append standard error to file I pipe output to named command (filter) I & include standard error in pipe Another way to redirect output is with backquotes (‘). Whatever is enclosed in backquotes is interpreted first, and the resulting output becomes an argument of the command. One example is the use of the command Is -a to list all files, even hidden ones, in a directory. Suppose you want to empty a given directory. Simply typing rm * won’t do the trick, because it will miss the hidden files (i.e, those starting with a period). However, this command will work: rm 'Is -a' {note backquotes) This command means “remove all files listed by Is -a.” Since Is -a lists all the files in a directory, this command removes all files there. Backquotes are very useful when you perform operations on the same set of files over and over. To see how this works, create a file that contains the names of each of these files: Now the output of the construction 'cat listfile' is a list of the files to work on, so that cp 'cat listfile' /tmp copies all those files (and only those files) to the directory /tmp, whereas rm 'cat listfile' removes only those files, and so on. Revision A, of 27 March 1990 Chapter 7 — B asic Command Syntax 81 cat vs. more You may have noticed by now that cat and more both display the contents of files (or the standard output). But more breaks the display up by screenful. Therefore, it’s better to use more for displays going straight to the screen, and cat for directing output to files or pipelines: / " > venus % cat file | more (file is displayed here by the screenful) V - ■ - 7.7. Command Line Editing Using the history Command The C shell keeps a list of previous commands that you have typed in. This his- tory mechanism provides you with the means to select and modify any word from any event in the history list. The history variable determines the length of this list. You can add this command to your . cshrc file if it isn’t already there. For more information on this file and how to change it, see SunOS User's Guide: Customizing Your Environment. To set or change this variable, use a command of the form: set history=n where n is the number of commands to remember. (40 is a good number. Setting the history variable to a very high number can degrade performance of the shell.) To see the list of previous command lines, type history after the prompt. Your history list will be similar to the one below: \ venus % history 1 Is 2 cd 3 date 4 history l J Command Substitution and When you want to repeat the previous command line but at the same time change Repetition part of it, you will find command substitution useful. You can easily substitute one string for another, using two carets (") to define the operation. This is the syntax: * old~ new In the following example, the incorrectly typed command mdkir is corrected to read mkdir. Note that in correcting the command, you also cause it to be per- formed. Revision A, of 27 March 1990 82 SunOS User’s Guide: Getting Started f ' venus % mdkir animals mdkir: Command not found venus % ^dk"kd mkdir animals venus% v . Adding * : p to the substitution line makes the system wait for confirmation before reentering the command. This allows you to reedit your correction, if necessary. f \ venus% mdkir animals mdkir: Command not found venus% "dk'kd' : p mkdir animals venus% V / The command has been edited, printed to the screen, and stored in the history list, but it has not yet been performed. Type ! ! to give the command: , — — venus % mdkir animals mdkir: Command not found venus% ~dk~kd - ' :p mkdir animals venus % ! ! mkdir animals venus% t Typing ! ! anywhere on the current command line repeats the entire previous command line. You can repeat just the last word of the previous command line by typing ! $ on the current command line, as in this example: venus % cat mammals chimp dog zebra venus % lpr !$ lpr mammals venus% k , You can also use command substitution to streamline repetitive tasks. The next example shows how to use mkdir and command substitution to make a series of directories without retyping the whole command line: microsystems Revision A, of 27 March 1990 Chapter 7 — Basic Command Syntax 83 r N venus % mkdir plants venus % '‘plants* fungi mkdir fungi venus% * fungi* pro ti stans mkdir protistans venus % *protistans*monerans mkdir monerans venus% Is fungi plants monerans protistans venus % ” J With longer, more complicated commands, substitution can save a lot of typing (and mistyping!). For more on command substitution, see SunOS User’s Guide: Doing More. Changing Prompt To Display If you want your prompt to display the history number as well as the hostname, History Number you can use a text editor to change the line in your . c shrc file that reads set prompt=" 'hostname to read set prompt=" 'hostname '_\ ! %" For more information on changing . cshrc, see SunOS User's Guide: Customizing Your Environment. To make your changes take immediate effect, type ( venus% source “/. cshrc \ venus% J Your prompt now looks like this: ( 1 venus 38% > When you start new windows, they will also display the new prompt. 7.8. Processes, PlDs, and Daemons What Commands are Running Now? (ps) After each command is interpreted by the C shell, an independent process, with a unique process identification number (PID), is created to perform it. The system uses the PID to track the current status of each process. To see what processes you have running, use the ps command. In addition to showing the PID for each process you own (created as a result of a command you typed in), ps also shows you the terminal from which it was started, its current status (or state), the cpu time it has used so far, and the command it is perform- ing. Revision A, of 27 March 1990 84 SunOS User’s Guide: Getting Started ( \ venus % ps PID TT STAT TIME COMMAND 2649 CO IW 0:23 sunview 2650 p0 IW 1:12 shelltool -C 2651 pO IW 0:06 -bin/csh (csh) 6006 Pi R 0:02 ps 2655 P2 S 34:32 shelltool 2659 p2 IW 0 : 50 -bin/csh (csh) 6000 P2 R 0:05 vi proc V The table below should help decipher the display: Table 7-2 Information Displayed by ps Column Symbol Meaning PID process ID number TT terminal: CO /dev/console mn / dev/ttywm STAT state of the process: R runnable (running) T stopped P paging D waiting on disk S sleeping (less than 20 seconds) I idle (more than 20 seconds) Z terminated, control passing to parent W swapped out > exceeded soft memory limit N priority was reduced < priority was raised TIME processing time (so far) COMMAND command being performed Of the various states in the STAT column, I w and ID can indicate that a process is in trouble. If you find a process in one of these states, and if in 5 minutes or so it is still in that state, it is probably a good idea to terminate it and run the com- mand again (checking to be sure that the command line makes sense and is typed in correctly). microsystems Revision A, of 27 March 1990 Chapter 7 — Basic Command Syntax 85 Terminating a Process With kill provides you with a direct way to stop commands that you no longer want, kill even from a shell running on another terminal or from another window. This is particularly useful when you make a mistake typing in a command that takes a long time to run, such as trof f . To terminate a process, type ps to find out the PID. When you see which process or processes to terminate, type in kill followed by the PID s for those processes. A faster way to get the right pid is to pipe ps output through grep: ps | grep command-name grep is explained in Section 7.1 1 . venus% ps PID TT STAX TIME COMMAND 1291 co I 0:12 iconedit -Wp 46 1282 pO S 0:11 -bin/csh (csh) 3250 pO R 0:00 ps : 1286 pi I 0:05 -bin/csh (csh) 3248 pi S 0:05 vi commands 1287 p2 I 0:40 cmdtool -Wp 496 venus % kill 1282 [1] Terminated -bin/csh (csh) venus % 90 -Ws 428 276 -WP 176 24 -Wi -Ws 645 172 -WP 1088 256 Use kill -1 PID # to forcefully terminate a process. If that doesn’t work, use kill -9 PID# See Section 7.10 for how to kill commands in the background. 7.9. Aliases Aliases allow you to substitute a short command for a long one — or a single com- mand for a series of commands. By using aliases, you can save a lot of typing when performing actions you do frequently. To declare an alias, use the following format: alias name-of -alias 'alias-commands' where name-of-alias is the name of the alias; and alias-commands is the action (or collection of actions) that this alias performs. SunOS User’s Guide: Customizing Your Environment contains a number of use- ful aliases you may want to use. One way to use aliases is to invent an alias that is an abbreviation of a longer command. In the example below, the h alias is a quick way to perform the his- tory command: microsystems Revision A, of 27 March 1990 86 SunOS User’s Guide: Getting Started / — — : A venus % alias h 'history' (create h alias) venus % h 1 cd 2 ps 3 alias h history 4 h venus % > Another way to use aliases is to create alternate forms of existing commands. One example is the rm command. Normally, rm removes files without asking for confirmation. With the -i option, however, rm queries you about deleting files. The example below shows you how to create an alias, del, that is equivalent to rm -i: f ■\ venus% alias del ' rm -i' (create del alias) venus % del filel del: remove filel? y venus % V You do not have to create an alias with a new name; aliases can have the name of existing commands. In the next example we create an aliased version of rm that is the same as del: / A venus% alias rm ' rm -i' (create rm alias) venus% rm file2 rm: remove file2? y venus % v Argument Designators You can use argument designators in alias definitions to create aliases for com- plicated commands and pipelines. When you use the alias as a command, the argument designator is replaced by command line arguments. One argument designator is \ ! *. When you use the alias, \ ! * is replaced by all the arguments that follow the alias. An example is an alias for cd that not only changes you to the directory you specify, it uses pwd to print out that new directory. Note that the example below uses a semicolon (; ) to combine two commands into one alias: . . is an abbreviation for the parent directory of the current directory. venus % alias cd 'cd \ ! * ; pwd' ( create cd alias) :venus% cd /etc/uucp (/etc/uucp replaces \!*) /etc/uucp (cd displays new location) venus% cd .. (go to parent directory ; .. replaces \ ! *) /etc (cd displays new location) venus % Revision A, of 27 March 1990 Chapter 7 — Basic Command Syntax 87 Making Aliases Global and Permanent Seeing Current Aliases Escaping an Alias Besides \ ! *, you can specify which arguments to replace: \ ! 1 replaces the first argument to the alias, \ ! 2 the second, and so forth. Aliases are only valid for the window you type them in; if that window goes away, so do its aliases. To avoid having to type in all your aliases in all your windows, put them into the file . cshr c, located in your home directory. Then type source '/.cshrc in each window you want them in. When you start a new window (or log in), the new aliases will be valid automatically. To see what aliases you have, just type alias. To see a particular alias, type alias followed by the command you want to see: venus% rm -i alias rm (check rm) venus % alias (check all aliases) a alias h history j jobs -1 Is Is -F mv mv -i rm venus % rm -i To run the unaliased version of a command, precede the name of that command with a backslash. Here, rm is aliased to confirm file deletions, but in its escaped form it removes the file without checking first. r venus alias rm (check rm alias) rm -i venus % rm test (use alias version of rm) rm: remove test? n venus % \rm test (don’t use alias version of rm) venus% V The same result can be had by using the command’s full pathname: A venus% /bin/rm test venus % V Some commands, such as cd and pushd, are built into the C shell. As such, they cannot be escaped with a backslash. To escape these commands, put the null string before the command. The null string is represented by a set of empty double quotes (" "): microsystems Revision A, of 27 March 1990 88 SunOS User’s Guide: Getting Started The semicolon separates two com- mands. Unaliasing an Alias To remove an alias, simply use the unalias command: 7-10. Running Commands The SunOS operating system is a multi-tasking operating system. This means in the Background that it can keep track of several users and their commands simultaneously. The system also allows you to run several commands at once by placing them in the background. Running a command in the background means that you can type in other com- mands while it’s running. To run a command in the background, end the com- mand line with an ampersand (&): The nrof f text formatter is explained in Chapter 6. 4 0 0 1 is a PID number (described in Section 7.8). [ 1 ] is the job number. To see what jobs are running, use the jobs command: Because each window runs with a different shell, you can’t use jobs to inquire about stopped jobs in other windows. In the example below there are two stopped jobs. Note the plus sign (+). It indi- cates that one job is current; the minus sign (-) shows that the other job is wait- ing. You can also send programs that are interactive, like vi or a game, to the back- ground temporarily. You can stop the job in the middle, go do something else, and then start it up again where you left off. To do so, use I Ctrl-Z 1 . Suppose you’re in the middle of editing a file, and you want to leave temporarily: Revision A, of 27 March 1990 Chapter 7 — B asic Command Syntax 89 Exiting With Stopped Jobs bg and f g when in the course of human events, it becomes necessary for one people, in order to secure the rights of liberty, fraternity, and a decent, well-aged Gouda cheese, to (ggc.J (leave input mode) [ Ctrl-Z ) (stop vi) Stopped venus % (now you can type in a command) To restart a command, or bring it to the foreground, type %n where n is the job number. If there is only one stopped job, or if you are bringing the current job back to the foreground, you can omit the job number. To abort a background job, use a command of the form: kill %n where n is the number of the job to kill: r \ venus % kill %1 [1] Terminated nroff -ms text. file 1 j If you try to exit a shell while a job is stopped, you get the warning message: There are stopped jobs. A second logout will then log you out (but its a good idea to see what jobs are stopped with jobs before you exit). The C shell has two built-in commands, bg and f g, which can be used to put jobs in the background or foreground. Typing bg at a prompt puts the current job in the background. (This has the same effect as if you had ended the original command line with an &.) You can specify a job number by typing bg %n Similarly, typing fg brings the current job into the foreground, while another job can be specified by typing fg %n #sun microsystems Revision A, of 27 March 1990 90 SunOS User’s Guide: Getting Started The at Command You can take advantage of hours when the system is not heavily used to run large jobs that require a large amount of system time or memory (like formatting large documents with trof f or printing out large files; see Chapter 6 for more on this). First, create a file containing the command line(s) you wish to run later on: — venus % cat > atfile: /usr/bin/troff -ms -t big. doc | lpr -t 1 Ctrl-D 1 venus% V Then type in at, followed by the time you wish to run the job, and the name of the file containing the command line(s): venus % at 2a atfile venus % y ~ ■■■■ — — j This command tells the system to start formatting and printing the large docu- ment at 2:00 a.m. at accepts a wide variety of syntaxes for specifying the time to run the job; these, for example, are all legitimate: at 1415am Jan 3 at 2:15 pm Jan 3 at now + 1 day at 5pm Friday at noon Note that at makes its own copy of the file you want it to execute. If you later change or delete the file, at will not be affected — it will still execute its copy of the original file. Note also that the script should expect no arguments, as none will be passed to it. There are two other ways you can use at, without creating an “atfile.” One is to pipe a command to at: ( venus % nroff -ms much.too.large.doc job 937 at Tue Jan 3 01:00:00 1989 at 1 am venus% v The other way is to go into at itself (by typing at), and then typing the com- mand at the prompt. End with [ Ctrl-D 1 : microsystems Revision A, of 27 March 1990 Chapter 7 — B asic Command Syntax 9 1 r venus % at midnight at> nroff -ms much.too.iarge.doc at> (Ctrl-Dj venus % l — — — ___ — __ There are two files, at . allow and at . deny, which regulate who can use the at command. at q and atrm batch atq tells you what jobs at is waiting to perform. venus % atq Rank Execution Date Owner Job # Queue Job Name 1st Jan 3, 1989 0:00 barty 93 6 a make 2nd Jan 3, 1989 1:00 barty 937 a lpr -n atrm removes jobs from the at queue, o To remove a specific job, type atrm job # You get the job number by using atq. venus% atrm 936 936: removed venus% □ To remove all your queued jobs, type either atrm -a or at rm followed by your username. (The superuser can remove all queued jobs with at -a.) o To be cautious, use the -i option; atrm will then ask you to confirm all deletions. batch is similar to at except that it sends the jobs off immediately to be exe- cuted, but waits until the system load level is low before actually running them. For more on at and batch, see the SunOS Reference Manual or type man at. 7.11. Searching for Patterns With grep To search for a particular character string in a specified file, use the grep com- mand. The basic syntax of the grep command is: grep string file A string is one or more characters; a single letter is a string, as is a word or a sentence. Strings may include “white space,” punctuation, and invisible (control) characters. where string is the word or phrase you want to find, and file is the file to be searched. As shown many times in this chapter, you can also use grep with out- put redirection: command I grep string To find Edgar Allan Poe’s telephone extension, type grep, all or part of his name, and the file containing the information: Revision A, of 27 March 1990 92 SunOS User’s Guide: Getting Started venus % grep Poe extensions Edgar Allan Poe X72836 venus % Note that more than one line may match the pattern you give: ( — .■ : . .. venus % grep Allan extensions Ethan Allan X6438 Edgar Allan Poe X72836 venus % grep A1 extensions Louisa May Alcott X4236 Ethan Allan X6438 Edgar Allan Poe X72836 venus % grep is case-sensitive; that is, you must match the pattern with respect to upper- and lowercase letters: venus% grep allan extensions (grep fails) venus % grep llan extensions Ethan Allan X6438 Edgar Allan Poe X72836 venus% grep as a Filter Pipes and filters are explained in Section 7.6. grep is very often used as a filter with other commands. It allows you to win- now out useless information from the output of commands. The example given at the beginning of this chapter illustrates grep as a filter; it displays files ending in “.ps” that were created in the month of May: Is -1 *.ps I grep May The first part of this command line, Is -1 *.ps produces a list of files: venus i -rw-r — r — -rw-r — r — -rw-r — r — -rw-r — r — -rw-r — r-- venus% Is -1 * . ps elvis elvis elvis elvis elvis 7228 Apr 22 15:07 change.ps 2356 May 22 12:56 clock.ps 1567 Jun 22 12:56 cmdtool.ps 10198 Jun 22 15:07 command.ps 5644 May 22 15:07 buttons.ps The second part, grep May microsystems Revision A, of 27 March 1990 Chapter 7 — Basic Command Syntax 93 pipes that list through grep, looking for the pattern May: grep With Multi-Word Strings To find a pattern that is more than one word long, enclose the string with single or double quotation marks. grep can search for a string in groups of files. When it finds a pattern that matches in more than one file, it prints the name of the file, followed by a colon, before the line matching the pattern: Searching for Lines Without a To search for all the lines of a file that don’t contain a certain string, use the -v Certain String option to grep. For example, to find all of the lines in the user medici’s home directory files that don’t contain the letter e: More on grep Some characters with special meaning to grep also have special meaning to the system and need to be quoted or escaped. So, whenever you use a grep regular expression on the command line, surround it with quotes, or escape such charac- ters as & ! . * $ ? and \ with a backslash. A caret (") indicates the beginning of the line. So the command grep ’ ~b' list finds any line in list starting with “b.” A dollar-sign ($) indicates the end of the line. The command Revision A, of 27 March 1990 94 SunOS User’s Guide: Getting Started grep 'b$' list displays any line in which “b” is the last character on the line. Therefore, the command grep '~b$' list displays any line in list where “b” is the only character on the line. Within a regular expression, dot ( . ) finds any single character. So the command grep ' * .b' list finds all lines in which b is the second character. The command grep 'an.' list would match any three characters with “an” as the first two, including “any,” “and,” “management,” and “plan ” (because spaces count, too). When an asterisk follows a character, grep interprets it as “zero or more instances of that character.” When the asterisk follows a regular expression, grep interprets it as “zero or more instances of characters matching the pattern.” Because it includes zero occurrences, usage of the asterisk is a little non- intuitive. Suppose you want to find all words with the letters “qu” in them. Say- ing grep 'qu*' list will work as expected. But if you wanted to find all words containing the letter “n,” you’d have to type grep 'nn*' list and if you wanted to find all words containing the pattern “nn,” you’d have to use grep 'nnn*' list You may want to try this to see what happens otherwise. To match zero or more occurrences of any character, use Searching for Metacharacters Suppose you want to find lines in the text that have a dollar sign ($) in them. Preceding the dollar sign in the regular expression with a backslash (\) tells grep to ignore {escape) its special meaning. This is true for the other metachar- acters as well — & ! . * ? and \ itself. For example, the expression matches lines starting with a period, and is especially useful when searching for nrof f or trof f formatting requests (which begin with a period). See Chapter 6, Formatting and Printing Documents. microsystems Revision A, of 27 March 1990 Chapter 7 — Basic Command Syntax 95 Table 7-3 grep Search Pattern Elements Character Matches: - The beginning of a text line. $ The end of a text line. Any single character [...] Any single character in the bracketed list or range. r...i Any character not in the list or range. * Zero or more occurrences of the preceding char- acter or regular expression. . * Zero or more occurrences of any single character. \ Escapes special meaning of next character. Note that these search characters may also be used in vi text editor searches. See Chapter 5. Single vs. Double Quotes on As shown earlier, use quotation marks to surround text that you want to be inter- Command Lines preted as one word. For example, grep searches all files for the phrase “roger, good buddy”: , > venus% grep "roger, good buddy" * Single quotation marks (' ) also group multi-word phrases into single units. Sin- gle quotation marks also make sure that certain characters, such as $, are inter- preted literally. (The history metacharacter ! is always interpreted as such, even inside quotation marks, unless you escape it with a backslash.) In any case, it is a good idea to escape characters such as &, !,$,?, . , ; , and \ when you want them taken as ordinary typographical characters. For example, if you type grep $ list you’ll see all the lines in list; if you type grep '$' list you’ll see only those lines with the “$” character in them. •sun Nr microsystems Revision A, of 27 March 1990 8 8.1. What Is a Network? Sharing Files Over a Network: NFS and RFS Using the Network Networks provide you with the opportunity to use other machines while logged in on your own machine. You can log in to other machines or you can execute commands without logging in to other machines. In this chapter, you’ll learn □ Network concepts; □ How to log in to other machines from yours; □ How to issue commands to remote machines; and □ How to request status information on other machines. A network is a connection between machines, allowing them to transmit informa- tion to one another. Networks are often referred to as being local area networks (LANs), which range over a small area, generally less than a few thousand feet; wide area networks (WANs), which can span thousands of miles; or campus area networks (CANs), which are intermediate in size. Networks may themselves be groups of networks; such a super-network is called an internetwork. For example, you may be part of a network of machines on your building’s floor and part of an internetwork connecting your local network with similar networks across the country. As the difference between a network and an internetwork is generally invisible to the user, we will use the term “net- work” to refer to both networks and internetworks. Machines participating in a network communicate using a network protocol, or shared network language, to transmit the appropriate information to the right place. An internetwork protocol — sometimes referred to as a gateway or relay — links networks together. If you are using a Sun Workstation, you are not necessarily on a network. You may, for example, bring your machine up single-user or you may simply be on a machine that is not connected to any network. Still, most Sun users are on a network of one sort or another. The Network File System, or NFS®, allows users on different machines to share files across a net- work. NFS is both a communications protocol — a set of rules machines follow for talking with each other — and a collection of software utilizing that protocol. NFS makes use of services provided by a network to allow for transparent transfer ©sun microsystems 97 Revision A, of 27 March 1990 98 SunOS User’s Guide: Getting Started and access of files between machines; that is, NFS allows you to treat some files on other machines as though they were on your own machine. NFS was developed by Sun Microsystems and has been adopted by a number of other companies. NFS is not limited to machines that run the SunOS operating system; many other systems, from personal computers to super-computers, can use it to share files across a network. The Remote File System, or RFS, is similar to NFS but was developed indepen- dently by AT&T. 3 It performs the same function as NFS. Most sites running SunOS will be using NFS; check with your system administrator to see which you are running. SunOS User’s Guide: Customizing Your Environment explains how to use RFS instead of NFS. NFS and RFS don’t exist on the network — a network is just a lifeless collection of wires, cables, phones, and other communications devices. Rather, each machine utilizing NFS and RFS runs its own set of the NFS and RFS daemons. (A daemon — sometimes known as a server — is a program that runs on your machine, doing various specific housekeeping chores. A printer daemon might handle the queueing up and printing of files, while a mail daemon takes care of sending messages back and forth between users. Most daemons are invisible to the user.) Traditionally, a multi-user system had a single processor (or set of processors) and disks serving a number of users: Figure 8-1 A Non-Network Environment The problem with the set-up in Figure 8-1 is that all the users are competing for the same processor. With a network of workstations, however, each user has his 3 RFS and “Remote File System” are trademarks of AT&T. microsystems Revision A, of 27 March 1990 Chapter 8 — Using the Network 99 Types of Networks or her own central processor and can access files located on other machines. NFS allows files to be scattered among the various machines on the network, so to the user the whole network appears somewhat like one big computer: Figure 8-2 A Typical Network Set-Up workstation! printer Using NFS and RFS, you can get access to other machine’s files by mounting file systems on those machines. SunOS User’s Guide: Customizing Your Environ- ment gives an introduction to mounting remote file systems under NFS and RFS; for a fuller discussion, see the System and Network Administration manual. Some common networks you may encounter include: Local Area Networks As mentioned earlier, small networks are sometimes called local area net- works (LANs). In local area networks, machines are connected by cables. Two types of LAN networks common to Sun machines are based on Ethernet and FDDI technologies; you may, for example, hear references to “sending something over the Ethernet.” Such networks allow real-time communica- tion between machines, so you can log in directly to another machine and run programs as though it were in front of you. You can also copy files to and from remote machines on a LAN. ARPANET-Based Networks In 1969 the Advanced Research Projects Agency (ARPA) of the U.S. Depart- ment of Defense sponsored the development of a broadscale communication protocol and network. Today, the descendant of that effort is called the Internet, which is composed of a number of interconnected networks that use the Internet protocol (IP). Revision A, of 27 March 1990 100 SunOS User’s Guide: Getting Started Users on machines that attach directly to the Internet, by cables or microwave connections, can log in “real-time” to other machines on the network. UUCP Network The UUCP (“Unix-to-Unix Copy Program”) network is not a permanent sys- tem of hardware connecting machines but rather a program that allows machines to use telephones to transmit data. Thus UUCP creates a sort of ad hoc network each time the program is invoked. (People disagree on whether it should be considered a network at all.) You can use UUCP to communicate with machines across the United States and throughout the world. An ad hoc UUCP network is not a real-time network like a LAN network; in other words, you can’t log in to another machine using UUCP. However, you can send information, like mail messages, to other machines and receive answers back from them. Because UUCP is not a real-time network, most of the information in this chapter — such as logging in to remote machines, copying from other machines, and issuing commands to other machines — does not apply to it. For information about how to send and receive mail messages on the UUCP network, see the mail chapters in this manual. People using machines on a UUCP network sometimes can send mail mes- sages over ARP ANET-based networks by utilizing a mail gateway, a machine that transfers data from one network to another . 4 The Network Information Because networks can get very large, doing system administration on them can Service ( Nis) get quite complicated: one needs to keep track of who belongs to a network, who has permissions to access which filesystems, and so on. For this reason, Sun pro- vides the Network Information Service, orNis. NIS maintains certain files with information about the machines which belong to the network and their users, and it provides users all over the network with the ability to look up the information contained in those files. By default there are a number of databases in Nis, but a system administrator may delete or add databases as desired. These default data- bases include hosts, which has machine names along with their addresses on the network; passwd, which, like your local /etc/passwd file, contains pass- word and other information associated with usernames; group, which holds the various groups that users have divided themselves into; and aliases, which contains mail aliases that the network recognizes. Not all systems run NIS — ask your system administrator if yours does. NIS is a distributed database; that means that copies of its data files are kept in various places throughout the network, for faster access by users. (There is one central, master copy, and changes to it are propagated down to the other “slave” copies.) Nis revolves around two daemons: ypserv, which is the lookup func- tion on the machine that has a copy of NIS, and ypbind, which runs on your machine and determines where to obtain NIS. In order to use NIS, these two 4 For information about how to send and receive mail messages on ARPANET-based networks, see Chapter 13. Revision A, of 27 March 1990 Chapter 8 — Using the Network 101 daemons must be running. To find out if your machine is using NIS, use the ps and grep commands; you should see something like this: r venus % ps -aux | grep ypbind root 27 0.0 1.1 66 34 ? I 0:15 /usr/etc/ypbind venus % l . J (You can use ps -aux to check for the presence of any daemon, including the NFS daemons.) You may never need to access theNis files; generally only system administrators ever tinker with them. However, you may occasionally want to read these files. Some commands to help you include the following: ypcat This displays the NIS data file you name. You can pipe it to the grep com- mand to find the entries you want. ypmatch ypmatch looks up an entry, or “key,” in the NIS file you specify, ypwhich This command tells you which server supplies NIS services for your machine. yppasswd You use yppasswd to change your network, as opposed to your machine’s, password. (Often they’re the same.) For further information on these commands, type man followed by the com- mand name. For a fuller treatment of NIS, type man ypf lies or consult the System and Network Administration manual. 8.2. Remote Login With rlogin Logging in to Another Machine With rlogin rlogin logs you in to other UNIX machines on a network. Type rlogin and the machine name of the other machine. Should a password prompt appear, type the password for that machine followed by I Return I . If your machine’s name is in the other machine’s /etc/hosts . equiv file, then the other machine trusts your machine name and won’t require you to type the pass- word. Revision A, of 27 March 1990 102 SunOS User’s Guide: Getting Started rlogin to a Machine Where You Don’t Have a Home Directory rlogin to a Machine as Someone Else venus% rlogin jupiter Password: (Type password ) Last login: Mon Oct 20 00:30:52 from venus SunOS Release 4.1 (SON) #9: Sat Nov 16 12:51:59 PST 1989 jupiter% pwd /home/medici jupiter% logout Connection closed. venus % ' In the example above, user medici logged in to jupiter at the directory /home/medici, as indicated by the pwd command. When you log in to a machine where you don’t have a home directory, rlogin displays a notification that you have no home directory on that machine and logs you in to the root directory (/) of that machine: ( .. .. . . ... . A venus % rlogin neptune Password: No directory! Logging in with home=/ Last login: Mon Nov 25 16:58:57 from venus SunOS Release 4.1 (SUN) #9: Sat Nov 16 12:51:59 PST 1989 neptune% pwd / neptune% logout Connection closed, venus % rlogin as we’ve described it above allows you to log in to another machine, but under your own username. At times you may want to log in as someone else. One example of this would be when you’re off working on someone else’s machine (and using their username) and you want to log in to your own machine as yourself. The -1 option to rlogin allows you to do this. The command syntax is: rlogin machine-name -1 username For example, here’s how user medici on machine venus logs in to machine aphrodite as cosimo: f#sun microsystems Revision A, of 27 March 1990 Chapter 8 — Using the Network 1 03 Note that when you log in as someone else, you go to that person’s home direc- tory. r login to a Non-Existent If you attempt to log in to a machine whose name isn’t known to your machine, Machine say the machine andromeda, r login searches unsuccessfully through the hosts database for that machine, then displays the following notification: If you see error messages that you don’t understand, try looking at Table 8-1 , which contains solutions to common networking problems. Aborting an rlogin Connection Usually you abort an rlogin con- nection only when you can’t ter- minate the connection using logout at the end of the work ses- sion. To abort an rlogin connection, type a tilde character followed by a period character (~ . ) at the beginning of a line. The login connection to the other machine aborts, and you find yourself back at your original machine. When you log in to a series of machines, accessing each machine through another machine, and you use ~ . to abort the connection to any of the machines in the series, you return to the machine you started from: To disconnect to an intermediate rlogin, use two tildes For example: osun V microsystems Revision A, of 27 March 1990 104 SunOS User’s Guide: Getting Started Suspending an rlogin When you want to suspend an rlogin connection, so that you can return to it Connection later, type the tilde character (~) followed by I Ctrl-Z 1 . The rlogin connection becomes a stopped process, and you are put back into the machine you logged in from. To reactivate the connection, type fg. Alternatively, type % followed by the job number of the stopped process (default job number for % is the job you most recently stopped or put in the background). venus % rlogin animation last login: Thu Nov 21 07:07:07 from venus SunOS Release 4.1 (SUN) #9: Sat Nov 16 13:21:24 PST 1989 animation% ~ ~Z (Sometimes ~ Z doesn't echo on the screen.) Stopped venus % pwd /home/medici venus% % rlogin animation animat ion % logout Connection closed, venus % As is the case with aborting rlogin with ~ ~ , using two tildes and a I Ctrl-Z 1 will suspend you to an intermediate rlogin. Verifying Your Identity With When logged in to a series of remote machines, perhaps under a variety of login who am i names, you may need to verity just who and where you are (relative to your com- puter, that is). The command who am i displays the machine you’re logged into, along with your current identity. (It also gives you the name of your terminal or workstation and the time.) venus% rlogin tripod -1 billyboy Password: Last login: Tue Nov 26 00:02:00 from portnoy SunOS Release 4.1 (SUN) #9: Tue Nov 17 21:10:51 PST 1989 tripod% who am i tripod! billyboy tty3 Nov 20 20:07 tripod% logout Connection closed, venus % who am i venus Imedici tty3 Nov 20 20:08 venus % For further information about Reference Manual. rlogin, see its man page, online or in the SunOS microsystems Revision A, of 27 March 1990 Chapter 8 — Using the Network 1 05 8.3. Who’s Logged in to This Machine? users, who, and w In the SunOS operating system, processes execute commands. The process that supports a terminal may run without any actual piece of hardware — what we usually think of as a terminal — associated with it; each window on a Sun worksta- tion counts as a separate terminal. Rebooting a machine is, essentially, starting its software up. For exam- ple, you reboot when you turn the power on. You also reboot after your machine “crashes.” The line in the figure starting with - Ws wrapped around, continuing from the end of the previous line. When you want to find out who’s logged on to your machine, you can use one of three commands: users, who, and w. The users command displays, in alphabetical order, the username of each per- son logged in on your machine: r venus% users medici rimbaud venus % \ > The who command provides more information than users does. For each ter- minal running on your machine, who displays the username, the terminal name, and the date and time the user created the terminal process : venus % who medici console Apr 1 8:50 medici ttypO Apr 1 8:51 medici ttypl Apr 1 8:51 rimbaud ttyp2 Apr 1 9:36 venus % (verlaine) When a user has logged in to your machine from another machine, the name of that machine appears enclosed within parentheses after the rest of the information who displays about them. The w command gives yet more information. First, w displays system informa- tion, including the current time, how long since the last reboot of your machine, the number of terminals running on the machine, and system load information. For each terminal running on your machine, w displays the username, the termi- nal name, the time of terminal login, other system information, and what pro- gram that process is running: venus% w 9:43am up 11:11, 4 users, load average: 0.76, 0.45, 0.27 User tty login? idle JCPU PCPU what medici -Ws 122 console 55 8 : 50am 4.02 4:40 3:59 clocktool -Wp 120 120 medici ttypO 8:51am 2 5:34 1:14 vi sculptor . list medici ttypl 8:51am 94:14 till! 15 date rimbaud venus% ttyp2 9 :36am 1 ' 5 5 -csh For more information on users, who, and w, see the appropriate man page, online or in the SunOS Reference Manual. Revision A, of 27 March 1990 106 SunOS User’s Guide: Getting Started 8.4. Status Information: ping, rup, and perf meter provide status information for other machines, ping, rup, and perfmeter Dead or Alive: ping ping checks to see if another machine is up and running, ping is useful because it’s a quick way to determine the status of another machine before you try to access it or if you’re having trouble accessing it. The ping command takes the form ping host timeout where host is the machine you’re testing, timeout is an optional amount of time you want ping to try for. If you don’t include timeout, ping will try for a maximum of 20 seconds. r ' — venus % ping pong pong is alive venus% V y Remote Uptime: rup To find out the length of time a system has been ‘ ‘up and running” and to view its load average, type rup followed by the machine name of the desired machine: rup stands for remote uptime, a version of the uptime command that runs uptime on other machines. / — ■ venus % rup pluto "N pluto op 1 day, venus* 5:47, load average: 3.S4, 3.53, 2.80 y To get the same set of information for all of the machines that are ‘‘up and run- ning’ ’ and on your local network, type rup without any arguments: f venus% rup mercury up 1 day, 23:31, load average : 0.04, 0.00, 0.00 venus up 8 days, 21 : 27, load average: 0.26, 0.13, 0.02 earth up 3 days, 20:44, load average : 1.07, 0.90, 0.54 mars up 36 mins, load average : 0.01, 0.00, 0.00 jupiter up 20:30, load average : 0.52, 0.20, 0.05 saturn up 8 days, 18:29, load i average : : 1.27, 1.12, 1.00: neptune up 2 days, 2:38, load I average : j 2.27, 1.73, 1.18 uranus up 1 day, 3:19, load average : 0.64, 0.90, 1.04 pluto up 1 day, 5:47, load average : j 3.64, 3.53, 2.80 venus% To find out more, see the rup man page, online or in the SunOS Reference Manual. Remote User Information With rusers rusers tells you who’s logged on to other machines on your network. The command rusers by itself shows each machine on the network, followed by the users on that machine: microsystems Revision A, of 27 March 1990 Chapter 8 — Using the Network 107 rusers stands for remote users, a version of the users command that runs users on other machines. The finger Command \ venus% rusers homeplate billyb absalom john babylon manchild garden russell cousy havilcek texas houston venus% l / Note that machine garden has three different users on it. If you wanted information on just one machine, you would type rusers fol- lowed by the machine name: / A venus% rusers garden garden russell cousy havilcek venus % V / For more detailed information, there’s the -1 option, which gives the username, the machine and terminal names, the time the user logged on, how long the users’s been idle (if more than one minute), and the name of a machine that the user rlogged in from, if any: r \ venus % rusers -1 garden russell garden :ttyd8 Nov 18 09:00 7:24 cousy garden : console Nov 18 16:13 havilcek garden : ttypO Nov 18 11:43 21 (quirk) venus% l The -1 option can also be used when no machine name is given. For more infor- mation, see the rusers man page, online or in the SunOS Reference Manual. Unlike commands such as ping or rusers, finger doesn’t give you infor- mation about other machines: it tells you only about other users. In fact, finger is so user-oriented that it accepts people’s real names, as well as their usernames, as arguments. Here’s what finger tells you: □ the user’s login name □ the user’s real name □ the user’s home directory and login shell □ the last time the user logged in □ the last time the user received mail, and the last time it was read □ the name of the user’s terminals and how long they’ve been idle Here is a slightly simplified example of a two typical finger requests: microsystems Revision A, of 27 March 1990 108 SunOS User’s Guide: Getting Started venus % finger mobygsea [sea] Login name: moby In real life: Ishmael Wong Directory: /home/shipwreck/moby Shell: /bin/csh On since Nov 14 06:33:41 on console 4 days 14 hours Idle Time New mail received Wed Nov 18 20:34:02 1987; unread since Wed Nov 18 16:20:24 1987 venus % finger Henry Stamper Login name: hank In real life: Henry Stamper, Jr Directory: /home/oregon/hank Shell: /bin/csh Last login Wed Oct 21 16:16 on ttypO from Cairo No unread mail ^ - finger is useful for making sure that the user you’re looking for is still alive and kicking (computer-wise, anyway), finger has various options and further capacities; to learn about them, see the finger man page online or in the SunOS Reference Manual. 8,5. Remote Command rsh stands for remote shell, or an interpreter capable of executing commands on Execution With rsh another machine. rsh allows you to execute a single command on another machine without hav- ing to log in formally . It can save time when you know you only want to do one thing on the remote machine. To execute a command on another machine, type rsh machinename command For example, suppose you want to see the contents of the directory /home/fresno/crops on the machine fresno: / venus % rsh fresno Is /home/fresno/crops -v corn kiwi oranges grapes olives peaches venus% ... V When you execute a command on another machine using rsh, rsh doesn’t log in: it talks to a daemon that executes the command on the other machine. How- ever, if you have a . cshr c file in your home directory on the other machine, rsh reads it. So rsh uses any pertinent aliases that you have defined on the other machine when executing the command. Like rlogin and rep, rsh uses the other machine’s /etc/hosts . equiv and / etc/pas swd files to determine whether you have unchallenged access privileges. For more information, see the rsh man page online or in the SunOS Reference Manual. Revision A, of 27 March 1990 Chapter 8 — Using the Network 109 Table 8-1 Network Error Notifications: Problems and Solutions Error Notification Problem Address already in use. Another server is “listening” on that address. Connection refused. The other machine is up, but its daemons aren’t ready to complete a connection. Connection timed out. One machine or the other is off, hung (stuck), or down. File not found. File doesn’t exist on other machine. Host name for your address unknown. Other machine needs your machine name in its /etc/hosts file or its NIS map. Login incorrect. You mistyped a password, or your username isn’t in the other machine’s /etc/passwd file or NIS map. Network is unreachable. Routing problem — a gateway machine or other network connection is broken. No such file or directory File or directory on other machine doesn’t exist, or you don’t have read permission. Permission denied. Machine name isn’t in /etc/hosts . equiv file; password required; may need write permission for directory on your machine. RPC PMAP_FAI LURE Daemon not running properly. RPC: Timed out Couldn’t connect to other machine, it may be down or network overloaded. RPC: Unable to send System cannot send data. RPC: Unable to receive System cannot receive data. RPC UNKNOWNHOST Machine name doesn’t exist on network. unknown host Other machine name not in /etc/hosts file on your machine. NFS server not responding still trying Server is under heavy load or has crashed. microsystems Revision A, of 27 March 1990 Messages This chapter describes messages, so that you can communicate with other users more immediately and interactively than by electronic mail. See Chapters 10 and 1 1 for more on electronic mail. There are three kinds of electronic messages: □ Interactive messages with talk or write □ Broadcast messages with wall □ System messages from your machine 9.1. Using talk With the talk program, you can converse on your screen with someone else who is either using a terminal on your machine or using another machine on your local network. To start talk, type talk usernameSmachinename at your command prompt, followed by ( Return J. When using SunView, initiate your talk message session in the window you want to use for the session. Pick a window that is large enough to contain a fair amount of text. In this example, user medici attempts to contact user michaelangelo. venus% talk iaichaelangel6@david talk’s interactive screen appears, and talk attempts to connect with the other user’s machine. Until talk connects to the other machine, it displays the notification: [No connection yet] Once connected, talk notifies you that it is waiting for the other person to respond: [Waiting for your party to respond] 111 Revision A, of 27 March 1990 112 SunOS User’s Guide: Getting Started talk “rings” the other person again and again, printing a message repeatedly on the screen while waiting for a response. If the other person isn’t a user or isn’t logged in at that time, talk responds with: [Your party is not logged on] But when talk finds the other user, the talk interactive screen displays a line to split itself in half like this: To facilitate a connection, talk displays a message that includes your user- name and machine name on the other user’s screen. In this example, talk displays the following message on user michaelangelo’s screen: The other user must respond by typing talk followed by the username and machine name of the person who is attempting to talk. In our example, michaelangelo types: to confirm the talk connection with user me die i on machine venus. If michaelangelo is busy or wants to ignore medici, he refuses to answer medici’s request. Eventually medici gives up, and types I Ctrl-C 1 to exit from the talk interactive screen. However, if michaelangelo successfully responds to medici’s request, talk establishes a link between the two users. Revision A, of 27 March 1990 Chapter 9 — Messages 113 Now, both users can type messages on the screen without interfering with each other. Both users see the messages they’ve typed on the upper half of their own screens or windows; the other user’s messages appear on the lower half of their screens. When they have finished typing messages, either user types l Ctrl-CJ to terminate the talk message session. You can prevent talk messages from appearing on your screen by giving the command: 1 14 SunOS User’s Guide: Getting Started If you’re running the SunView window system, you must be superuser (root) to run mesg. You can also put mesg n on a line by itself in your . login file; this file is consulted whenever you log in, so messages will be turned off until you take the line out and log in again. SunOS User’s Guide: Doing More con- tains information on becoming superuser, and SunOS User’s Guide: Customizing Your Environment explains the .login file. For more information on talk, seethe talk man page, online or in the SunOS Reference Manual. 9.2. Using write Users may want to establish con- ventions — like "over" and “over- and-out” — to indicate when they’ve completed their messages. write differs from talk in that write: a doesn’t use the entire screen or window □ only reaches users on the same machine or workstation you’re sending mes- sages from One user writes a message to the other. Then the other user can in turn write a reply. To write a message to someone using a terminal on your machine, type venus % write username followed by I Return 1 . In this example, user medici decides to write some messages to user sap- pho. He types in the text of an introductory message on lines following the write command line. To send the introductory message text, type (Return ) . / - venus % write sappho Do you want to chat? (Type L Return J to send message text.) v / The message appears on the other user’s screen almost immediately afterwards. sappho decides to exchange messages with medici, so she types write, fol- lowed by his username, [ Return I . and her message in reply. venus% Message from venus! medici on ttyp2 at 1:01 Do you want to chat? write medici Sure, what's up? (Type l Return] on next line to send message text.) As you can see, write automatically identifies the machine, username, and ter- minal where the message originated, and the time the message arrived. microsystems Revision A, of 27 March 1990 Chapter 9 — Messages 115 The two interlocutors can continue to write messages back and forth, without retyping the write command, until they want to stop. Then both users must type f Ctrl-D 1 on a line by itself to terminate the write connection. venus % write sappho Do you want to chat? Message from venus ! sappho on ttyp3 at 1:02 ... Sure, what's up? Oops, I'm late for an appointment — gotta run! ~D ( Terminate connection.) venus% write displays the end-of-file indicator, EOF on the other user’s screen (for this example, user sappho’s screen) to notify that person that her conversa- tional partner (user medici) terminated the connection. Just as with talk, you can prevent write messages from appearing on your screen by using me s g n . For more information on write, see the write man page, online or in the SunOS Reference Manual. 9.3. Broadcast Messages: wall Most users sharing a machine don’t appreciate people sending spurious messages to everyone on the machine. When you want to send a message to everyone on your machine at once, use the wall, write to all, command. Usually, people broadcast messages only to announce that the machine is going down for maintenance, or for other important messages that affect everyone using the machine. Type wall followed by I Return I . Then, type the text of the message, followed by ( Ctrl-D I on a line by itself. The message appears on the screen — in the con- sole window — almost immediately after you send it. venus % wall This machine will go down for maintenance at noon today . ( Type i Ctrl-D 1 on next line to end text, send message .) Broadcast Message from venuslmedici (ttyp4) at 12:00 ... This machine will go down for maintenance at noon today. venus% — ...... J The same message appears on the screen, or console window, of anyone else who is logged in to that machine. For more information on wall, seethe wall man page, online or in the SunOS Reference Manual. microsystems Revision A, of 27 March 1990 116 SunOS User’s Guide: Getting Started 9A System Messages System messages are like broadcast messages, only the system generates them automatically to notify you about something that may be important. One com- mon system message is the message of the day. When you log in, you often see two system messages — one about the operating system, the other about new mail — shown here as examples: venus login: medic! Password: Last login: Fri Oct 31 23:59:59 from console SunOS Release 4.1 (DIONEJOLIENT) #1: Fri Feb 14 00:00:01 PST 1989 You have mail, venusl Revision A, of 27 March 1990 10.1. What Is Mail Tool? 10.2. Who Can Use Mail Tool? 10.3. Starting Mail Tool Starting From a Command Line Starting From the SunView Menu Mail Tool Mail Tool is a SunView-based program that simplifies use of SunOS mail- handling facilities. With Mail Tool you can write, send, and receive electronic mail to and from other system users, even if they are physically distant and even if they’re not using a Sun system. Mail Tool is built on top of a SunOS program called mail, which is is not window-based. (See Chapter 1 1 for more on mail.) Mail Tool options and defaults are located in an associated file called . mailrc, found in your home directory. You can use the Defaults Editor or a text editor to access and change these. See Appendix B. More information on Mail Tool can be found by typing man mailtool at a system prompt. To run Mail Tool, you must have a bit-mapped screen, like the Sun Workstation. And you must be using the SunView windows system. If your machine is not so equipped, you must use mail, instead. If you’re not sure whether you have a bit-mapped screen, ask your system administrator. See the SunView User’s Guide for information on how to run SunView. There are two ways to start Mail Tool: from a command line and from a Sun- View menu. To start Mail Tool from a command line, type mailtool & at the prompt: r venus % mailtool & [1] 68022 venus% — / The & is optional. It tells Mail Tool to run in the background, so you can still do other work in the same window while using Mail Tool. It’s more common to start Mail Tool from the SunView menu. With the pointer anywhere in the gray area of the screen, hold down the right mouse button to bring up the SunView menu. Choose ‘Tools=>Mail Tool’ to select Mail Tool. This selection looks something like this: microsystems 117 Revision A, of 27 March 1990 118 SunOS User’s Guide: Getting Started Shells Editors * 1 || Tools ! Mail Tool |*s| ii Dbx (debug) Tool i;ij Performance Meter =* Clock =* The Mail Tool Icon When Mail Tool comes up, it appears as an icon. When Mail Tool is displayed in iconic form, it is said to be running closed. 10.4. Opening Mail Tool The icon lets you run Mail Tool without taking up much room on the screen. But to use Mail Tool, you have to open it. Use the mouse to move the pointer on the screen into the Mail Tool icon, and then click the left mouse button. Like most icons, the Mail Tool icon has a menu that allows you to manipulate the application. You can also open Mail Tool with this menu. The ‘Open’ menu offers the following ways of opening Mail Tool: microsystems Revision A, of 27 March 1990 Chapter 10 — Mail Tool 1 19 The Iconic Open Menu Read Neu Mai 1 Read Folder Compose Message Just Open □ ‘Read New Mail’: When you open Mail Tool this way, it automatically checks for new mail. □ ‘Read Folder’: A folder is a kind of a file that contains letters (it’s explained later). Use this item to display your folders and to select the folder you want to look at. □ ‘ Compose Message ’ : Choosing this item brings Mail T ool up ready for you to write a letter. □ ‘Just Open’: This choice opens the icon without looking for new mail, read- ing in a folder, or setting you up for letter writing. This is what Mail Tool looks like when it’s running open: microsystems Revision A, of 27 March 1990 120 SunOS User’s Guide: Getting Started Figure 10-2 Mail Tool Running Open .IX "folder directory” .BP If you choose 'Compose Message', Mai lyou're ready to urlte a letter. .BP [Last but not least, you can choose 'Just Ope opens the Icon without looking for new mall, or setting you up for letter writing. '.LP |And here, finally, Is what Mall Tool looks 1 [running In open mode: A" A" ILLUSTRATION of open mall tool A" .KS .FN .B1 [all Tool Running Open" open_mt CP malltool pic 3.9071 2.2501 "" 0.313 0| sp -.18751 “ B2 .KE .H 2 "Definitions and Descriptions" deflnltll .LP [Before we get Into reading and writing electl let's take a look at some of the parts whlchl jfiall Tool. The Mall Tool window Includes se| each of which serves a different function; there Is a file called XfL.mal lrc\fR which ll of Mall Tool but on which Mall Tool depends. FS For convenience's sake we'll refer to these as \fIw1ndows\fR. .FE From businessSbusynass Fri Sep From: businessObusynsss To: venusGmsdici Subject: Coffee Can Demo 1 ^ June: I want to remind you to let the sales force know about our upcoming release of the "Rotating Coffee Can Demo Program" and its accompanying manual, the "Rotating Coffee Can Demo Program Beginner's Guide." The RCCDP is a non-interacti ve graphics program which displays a coffee can from several angles, showing off not only powerful graphics interfacing but marginally interesting facts about coffee cans from around the world. The manul was ghost-written by e Galtieri . All of us here at Food Graphics, Inc. are sure that the "Rotating Coffee Can" will become a big winner for us. I hope your people are ready to jimp on the bandwagon. Milt Aronson Marketing venus9: from From buslnessfibusyness Fri Sep 4 14:09:14 1987 venus 10: 10.5. A Glimpse at Mail Tool Windows The Mail Tool window includes several subwindows, each of which serves a dif- ferent function. The Header List Window The letters in your mailbox are summarized in the header list . Each letter has a one-line entry in the header list called a header. Figure 10-3 The Header List Window r — 1 f lann@swim2bi rds Wed Aug 5 16:27 25/1098 The Mother Tongue > 2 tecunHuman Wed Aug 5 16:30 27/951 The Quetzal U 3 odysseusSi thaka Wed Aug 5 16:32 42/928 Homecoming Reunion Figure 10-3 shows a header list with three headers. The first letter is from user flann on machine swim2birds\ the second letter is from user tecun on machine microsystems Revision A, of 27 March 1990 Chapter 10 — Mail Tool 121 uman, while the third letter is from odysseus on machine ithaka. Reading across from left to right, each header displays the following information: status msg. no. sender date time msg. length subject □ There are three status indicators for a letter. N means the letter is new. U indicates that the letter is unread ; you’ve retrieved it from your mailbox — and possibly stored it away — without reading it. A blank status indicator means that you’ve retrieved and read the letter but you haven’t done any- thing with it. > indicates the letter you’re currently viewing. □ A message number assigned to each letter in the order received. □ The sender is the person who sent the letter. □ The date is the date the letter was sent. □ The time indicates the time it was sent. □ The message length is given in two parts: the first number is the number of lines in the letter, and the second number is the number of characters. □ The subject is assigned by the sender. The Command Panel Window The command panel window has buttons that control most Mail Tool functions. (These will be described in detail later.) Figure 10-4 Command Panel Window r [ Show ][ Next ][ Delete ][ Reply ][ Compose] ( Print ]|New Mail] [ Save |[ Folder ] Fi le : ^ f ffi sc Done J J Pushing a Button You push a button by using the mouse to position the pointer over a button in window — Show or Compose, for example — and then clicking with the left mouse button. The Message Window The window under the command panel window is called the message window, this is where Mail Tool displays the letters you receive. Revision A, of 27 March 1990 122 SunOS User’s Guide: Getting Started Figure 10-5 The Message Window f Show ][ Next ][ Delete ][ Reply ][ Compose] [ Save ][ Folder ] File: ^ [ Print ] [ Neui Mai 1 ] [ Mi sc ][ Done ] From business@busyness Ved Aug 5 16:27:46 1987 From: businessSbusyness (The Profit) To: karlgmarx Subject: Vour chance to uin! ! Karl Marx/ British Museum / London, U.K. Dear MR. MARX: Hou mould you like to have your OWN HOME, with butlers and maids, and a swimming pool or a two-car garage? Or how about a luxurious, FIRST-CLASS VACATION for two in beautiful Honolulu, Hawaii? Or your own VIDEO CASSETTE RECORDER — perfect for preserving those precious memories of your family's special moments. Impossible you say? Veil, MR. MARX, you may already be a $100,000 GRAND PRIZE VINNER of Philosophy Clearinghouse's Grand Sweepstakes Giveaway. These are only three of the thousands of runnei — up prizes we're giving away. And even if you aren't a Grand Prize Vinner, you're still eligible to win one of thousands of runnei — up prizes, like this practical slicer/dicer, or this complete, five-volume set of the works of Frederlch Hegel. But you have to enter to win. And that's easy! Just send the return postage envelope right away — that's all you have to do. But while you're at It, why not take the time to send in an order for some new philosophy? Ve at Philosophy Clearinghouse are the world's largest distributor of name-brand philosophies, including Platonism, The Composition Window The composition window is where you write letters. Normally, you get a compo- sition window by pushing either the Compose or the Reply button. Revision A, of 27 March 1990 Chapter 10 — Mail Tool 123 Figure 10-6 The Composition Window [ Shoui ][ Next~")[ Delete ][ Reply |[Compose] [ Save ][ Folder ] Fi le : ^ [ Print ][Neuj Mai 1 ] [ Wisc I f Done t]Fromtim@th inking Wed Aug 26 13:53:14 1987 From: timGthinking (Tim Thinking, Esq.) To: weasel Qtoadhall Subject: Overworking | Bill, I You sure seem to be working too hard these days. Last week you (attempted to photocopy your lunch, an entire potato goulash. I (hope you'll take it easy from now on. Tim [Inc1ude][De1iver][ Cancel ] [Re-address j ' Disappear I To: timethinking Subject: spare time Cc: |>other recipients<| | Tim- I hope nobody finds out that I'm stealing a few minutes from work to tell you about my book. Over the past six years I've worked in the Paper Clip Division of Associated Amalgamated, I've been stealing away precious few moments every chance I can to work on my novel . I know that our paper clip sales have plummeted of late, but I am hoping the American public can get by with staples until I have finished the book. 10.6. Receiving Mail There are three ways that you can be notified of incoming mail. (1) Outside of Mail Tool, the SunOS operating system will give you the notification You have new mail in the window you’re typing in. (2) When Mail Tool is closed, the icon changes: the flag on the mailbox goes up, and a letter appears in the slot. (3) When Mail Tool is open, the frame header at the top of Mail Tool will display [New Mail] when you receive a letter. By using the Defaults Editor, you can make Mail Tool beep and flash the screen when it receives a letter. See Appendix B. 10.7. Retrieving New Mail The New Mail button retrieves letters that you’ve received. Hold down the right and Committing mouse button to get the menu associated with the button and to choose from it. Changes NOTE Clicking the left mouse button on a Mail Tool button always selects the topmost menu item for that button. The New Mail button has two different menus, depending on whether you are currently looking at your mailbox or at a mail file or folder. When you are look- ing at your mailbox, the New Mail button displays the menu at left. Retrieve New Mail uithout Coanitting Changes Corwit Changes and Retrieve Heu Hail microsystems Revision A, of 27 March 1990 124 SunOS User’s Guide: Getting Started If you push the New Mail button while looking at your mailbox, Mail Tool retrieves new letters without committing changes , which means you can still undelete letters you’ve deleted. On the other hand, if you choose ‘Commit Changes and Retrieve New Mail,’ all your deletions become permanent. Note that if you are looking at a mail file or folder, then the New Mail menu changes. Pushing New Mail always commits changes when you are looking at mail. See Section 10.9 for more on folders. Choosing Letters When you retrieve new mail. Mail Tool displays an updated header list and the current letter. Mail Tool puts that letter in the message window and puts a > in front of its header. (If you have unread letters when you push the New Mail but- ton, Mail Tool will mark them with a U (unread).) You can do an operation on a letter just by clicking on its header and pushing the appropriate button. You do not have to display the letter first. (The Next button is an exception.) To read other new mail, you can move through the header list with two buttons, Next and Show. Commit Changes and Retrieve Neu Mail Comnlt Changes Looking at the Next (or Previous) Letter t ” Next Previous [Shift] The Next button moves you to the next letter in the header list. (If you’re looking at the last letter in the letter list, pushing the Next button displays the previous letter.) To look at the letter that comes before the current letter, either hold down the I Shift 1 key when you push the Next button or choose ‘Previous’ from the Next menu. Looking at Other Letters To display a letter, move the pointer to its header. Click the left mouse button to With the Show Button choose that header; then push the Show button. The letter will appear in the message window. Displaying the Full Header The header of a letter can contain a lot of unwanted information. Use the Defaults Editor to suppress the display of unwanted information. (This is explained in Appendix B.) Show p ShoiJ jF u 1 1 Header If you do suppress header information, you can still display it when you want to. The Show button has a ‘Show Full Header’ menu item (which you can get by using the [Shift] key on the Show button). Here is a letter, first displayed nor- mally, and then with the ‘Show Full Header’ option: Asun microsystems Revision A, of 27 March 1990 Chapter 10 — Mail Tool 125 Figure 10-7 A Typical Mail Header r 5 17:58:49 1987 j]From businessGbusyness Wed Aug From: businessSbusyness To: marketsSsoma Subject: Ratcliff e needs Dear Susan — I am sending the specifications on the Ratliffe contract to you by express mail. They should reach you shortly. In addition to the VXB283 Control Sequence Processor, the Hi-Brite 2800 Graphics Interface Modulator, and the RomSwap 9091 Memory Allocation Enhancer, Ratliffe Corporation is also requesting that we deliver 150 pounds of smoked ham with the release. Frankly, no one knows why. It's in the contract. Please let me know if you see any delays in filling the order. Ron microsystems Revision A, of 27 March 1990 126 SunOS User’s Guide: Getting Started Figure 10-8 Full Letter Header From businessSbusyness Wed Aug 5 18:06:59 1987 Return-Path: Received: from busyness .sun .uucp (soma) by soma .sun .uucp (3 .2/SMI-3 . 0DEV3) id AA27050; Wed, 5 Aug 87 18:06:53 PDT Received: by busyness .sun .uucp (3 .2/SMI-3 .0DEV3) id AA27047 ; Wed, 5 Aug 87 18:06:48 PDT Date: Wed, 5 Aug 87 18:06:48 PDT From: businessSbusyness Message-Id : <8708060106 . AA27047@busyness . sun ,uucp> To: marketsSsoma Subject: Ratiiffe needs Status: R I Dear Susan — I am sending the specifications on the Ratiiffe contract to you by express mail. They should reach you shortly. In addition to the VXB283 Control Sequence Processor, the Hi-Brite 2000 Graphics Interface Modulator, and the RomSuap 9091 Memory Allocation Enhancer, Ratiiffe Corporation is also requesting that we deliver 150 pounds of smoked ham with the release. Frankly, no one knows why. It's in the contract. Please let me know if you see any delays in filling the order. Ron 10.8. Printing Mail Push the Print button to send a copy of a letter to a printer. (You can change the way you print mail out by using the Defaults Editor to change the printmail variable. See Appendix B.) 10.9. Saving Mail In addition to composing and reading mail, you will also want to save and retrieve it. Here’s one way of saving a letter (other ways — employing folders — are dis- cussed below): □ In the command panel window note the word File : □ After the colon, type the name of the file in which you want the letter held. □ Push the left mouse button on the Save button. Or hold down the right mouse button over the Save button to view the menu options and to select ‘Copy.’ Saving deletes the letter from the mailbox and puts it into the file you specified. Copying leaves the letter visible in the mailbox, while putting a copy into the specified file. Suppose you’re saving a letter about Raymond Chandler’s novel The Big Sleep into the file classic_mysteries. If you just type classic_mysteri.es after File : Mail Tool will assume that classic_mysteries is located in Revision A, of 27 March 1990 Chapter 10 — MailTool 127 Setting Up Folders and the Folder Directory NOTE Naming Folders Selecting and Retrieving Files and Folders NOTE its current directory. If you want classic_myst eries to be in a different directory, say /home/medici/mail, you can type in the file’s whole name, /home/medici/mail/ classic_myst eries, after File : But you can dispense with typing full pathnames if you save to Mail Tool fold- ers: folders are files stored in a folder directory. All folders are files, but not all files are folders. A folder directory is a directory that contains folders. . . . Setting up a folder directory in which to store your letters is a three-step process: □ First, type mkdir directoryname on a command line (name the directory anything you like). □ Then use the Defaults Editor to alter the the Mail Tool settings. At the Set /folder variable type after the colon the pathname of the directory you created in the first step. Don’t forget to save your change before quitting the Defaults Editor. □ Choose ‘Source .mailrc’ from the Misc button menu. See Section 10.19. For example, if you’ve assigned /home/medici/mail as your folder direc- tory, that’s where your folders will be stored. You name a folder by typing a + and a name after File: The + attaches the folder to the folder directory. Thus, still using the example above, the foldemame +classic_mysteries is inteipreted by Mail Tool as /home/medici/mail/classic_my st eries. The + is invisible outside mail and Mail Tool. To select a folder and to retrieve a folder or file, you use the Folder button: □ To select a folder. Hold down the right mouse button over the Folder button — this will give you a menu of all the folders in your folder directory. Choose a folder: its name will appear after File : (You can also select a folder by typing its name after File : ) □ To select a file : Type the full pathname after File : □ To retrieve a folder or file: Once the folder or file has been selected, use the left mouse button to push the Folder button. The letters in that folder will appear in Mail Tool with the usual header information. To exit a mail file or folder, use the left mouse button to push the New Mail or Done button. Or select another folder or mail file. microsystems Revision A, of 27 March 1990 128 SunOS User’s Guide: Getting Started A final word about folders: you can get a menu of just the folders you’ve used during this Mail Tool session by holding down the right mouse button over File : If you work with a few folders over and over, this can save you time. Changing Directories With the Misc Button The ‘Change Directory’ menu option of the Misc button lets you change the directory that Mail Tool is active in. When you choose ‘Change Directory,’ a pop-up window appears giving you the current directory and asking you for the name of the new directory. Type in the name of the directory where you want to save and retrieve letters. Figure 10-10 The Change Directory Pop-up Window NOTE ‘Change Directory’ does not affect where Mail Tool looks for folders : the folder directory remains unchanged. 10.10. Deleting (and Undeleting) Mail When using Mail Tool you’ll want to delete letters from time to time. To delete a letter from the mailbox or from a folder, find it in the header list and click the left mouse button to select it, and then push the Delete button. A deleted letter can be recovered by using the ‘Undelete’ option of the Delete menu. A letter can be undeleted at any time — until you commit changes (usu- ally when retrieving new mail or or finishing a Mail Tool session). If you com- mit changes, you remove deleted letters from your mailbox and make your changes permanent. Revision A, of 27 March 1990 Chapter 10 — MailTool 129 10.11. Composing Mail To compose a letter, push the Compose button with the left mouse button. A composition window will appear. You can type and manipulate text in this win- dow in the same ways as in other SunView text windows. You can open additional composition windows. These will appear as independent windows that you can open, close, and resize without affecting the rest of Mail Tool. They disappear when you quit Mail Tool. You can make even the initial composition window a pop-up window by using the Defaults Editor to set the alwaysusepopup variable to ‘Yes.’ See Appendix B for more on this. Figure 10-11 Composition Window Buttons f IncludejfDeliverjf Cancel jf Re-address] C Disappear Inserting Names and Every composition window has pre-set fields for recipients ( To. ), subject ( Sub Addresses ject: ’), and other recipients (‘ Cc: ’) of your letter. Type in the appropriate information in each field. Type [ Ctrl-Tab I to move from one field to the next. NOTE An empty field is not sent as part of your letter. You can send the letter to as many recipients as you wish: just leave a space or a comma between names after ‘To:’ and ‘Cc:’. (Note that the Compose button menu gives you the option of not having a ‘Cc:’ field.) And you can use the Defaults Editor to have a ‘Bcc:’ (blind carbon) field pre-set: change the Set/askbcc option to ‘Yes.’ Recipients of your letters will not see the addressees of the blind carbon copies, but the addressees of carbon copies will be visible to all. Sending a Letter Directly to a File or Folder You can also send a copy of a letter directly to a file or mail folder. Simply type the file pathname or folder name in either the Cc : or the Bcc : field. Figure 10-12 Subject and Address Fields in a Composition Window n To: | >recipients< Subject : Cc: |>other recipients*: | | >body of message< | Revision A, of 27 March 1990 130 SunOS User’s Guide: Getting Started Figure 10-13 Multiple Addresses Using Word-Wrap While you can set an automatic word-wrap for Mail Tool composition windows (as in other text windows), it’s probably not a good idea. If the person receiving your letter isn’t using word-wrap, the lines of the letter could run out the win- dow. On the other hand, if you receive a ragged letter from someone, you can clean it up by selecting the text while holding down the fCnTI key and then choosing ‘Extras=>Format’ from the text menu in Mail Tool’s message window. 10.12. Replying to Mail To reply to a letter you’ve received, select the letter in the header list and then use the left mouse button to push the Reply button. A composition window will appear — preaddressed to the sender of the letter you’re answering. By selecting ‘Reply (all)’ or ‘Reply (all), Include’ Reply button items, you can send your reply to everyone else who received the letter as well as to its author. Mail Tool lets you forward letters by putting a copy of a letter you received into a letter you send. Suppose you received this letter, and you wanted to send a copy of it to joe@donkey: Reply Reply (all) [Shift] Reply, Include [Ctrl] Reply (all). Include [Ctrl] [Shi ft] 10.13. Including a Letter or File Revision A, of 27 March 1990 Chapter 10 — Mail Tool 131 Figure 10-14 A Received Letter From business@busyness Thu Aug 6 13:52:10 1907 From: businessSbusyness To: outlaws@large Subject: The Big Meeting To all members of the Engineering Department: The regular 2:40 meeting on Deadlines and Shortcuts mill be moved to 4:00 today. The subject, "Using Pliers on Hardware, " will remain the same, as will the speaker. Dr . Henry Thistle of the Institute for Advanced Tinkering. In place of the 2:40 meeting we will have a brief lecture by our own Martin Fierro on his recent trip to Yellowstone Park and the really neat shells he found near a dumpster. ^--Lorraine Pluto Department Chair Using the Include Button First, bring up the composition window with Compose or Reply. Then make sure that the cursor in the composition window is where you want the inserted letter to go. Push the Include button. microsystems Revision A, of 27 March 1990 ■ Ini 132 SunOS User’s Guide: Getting Started Figure 10-15 Including a Letter r IjjTo: joeSdonkey Subject: The meeting Joe, didn't you lose some shells in Yellowstone? Maybe you should go to this lecture: ♦ — Begin Included Message From businessSbusyness Thu Aug 5 13:53:10 1987 From: businessSbusyness To: outlawsSlarge Subject: The Big Meeting | To all members of the Engineering Department: The regular 2:40 meeting on Deadlines and Shortcuts will be moved to 4:00 today. The subject, "Using Pliers on Hardware," will remain the same, as will the speaker, Dr. Henry Thistle of the Institute for Advanced Tinkering. M in place of the 2:40 meeting we will have a brief lecture by our own Martin Fierro on his recent trip to Yellowstone Park and the really neat shells he found near a dumpster. Attendance is recommended. — Lorraine Pluto Department Chair End Included Message Include, —forwarded nessage Include, Indented [Ctrl] \ Choosing the ‘Include, Indented’ option of the Include menu indents the included letter, as in the example below. The included letter is inserted at the cursor. Revision A, of 27 March 1990 Chapter 10 — Mail Tool 133 Figure 10-16 Including a Letter, Indented To: joeSdonkey Subject: The meeting Cc: Pother recipients<| Joe, didn't you lose some shells in Yellowstone? Maybe you should go to this meeting: From busi ness6busyness Thu Aug 6 13:52:10 1987 From: businessSbusyness To; outlaws@large Subject: The Big Meeting To all members of the Engineering Department: The regular 2:40 meeting on Deadlines and Shortcuts will be moved to 4:00 today. The subject, "Using Pliers on Hardware," will remain the same, as will the speaker, Dr. Henry Thistle of the Institute for Advanced Tinkering. In place of the 2:40 meeting we will have a brief lecture by our own Martin Fierro on his recent trip to Yellowstone Park and the really neat shells he found near a dumpster. — Lorraine Pluto Department Chair Using the Compose and Reply Buttons The Compose and Reply buttons have ‘Include’ as a menu option. This option lets you include a letter directly when you bring up a composition window, instead of using the Include button. Using ‘Include File’ You can also include any other file in a letter by using the Text Edi t menu item ‘Include File.’ Type the filename, select it while holding down the LCtrlJ key, and then choose ‘Include File’ from the menu. (The filename itself is not included.) Revision A, of 27 March 1990 134 SunOS User’s Guide: Getting Started Figure 10-17 The Text Edit Menu in Mail Tool To: mamaGwi tsend Subject: telephone numbers Cc: |>other recipientsC | Doreen — Here is my file of useful telephone numbers: Save Current File Edit Store as Neu File Display Load File FI rid Extras Set Directory Empty Document Finishing Up => 10.14. Delivering a Letter „ Once you ve wntten your letter, you send it with the Deliver button. Be sure that 1 Denver, Take Down window u your letter s ready to send before you push Deliver — once a letter is sent, you can ’t take it back ! The Deliver menu allows you to send a letter but leave the composition window intact; that is, with the letter still in it. This is useful if you want to send the letter off to someone else (possibly editing it first) or to keep a copy for yourself. 10.15. Canceling a Letter You can cancel a letter only before you send it. When you press the Cancel but- ton, Mail Tool will ask you to confirm the cancellation. Revision A, of 27 March 1990 Chapter 10 — Mail Tool 135 Figure 10-18 Confirming a Cancellation Reply to or Compose Mall I flnclude] (Deliver] [Re-address] G Disappear To: joe@donkey Subject: Mysterious prowlers Cc: |>other recipients<| Bcc : |>blind carbon copies<] I Joe- Just wanted to drop you a note to say that there's a mysterious prowler outside of my office. He appears to be carrying either a rifle or a copy of "Polka Hits of 195S," I can't tell which. I hope it's the rifle. I'm goin^ in| Never min for elk seas Tim Are you sure you want to Cancel window? ^Confir^ [Do NOT cancel hiindouT) Cancel d Cancel, Ho Confirm [Ctrl] You can avoid this confirmation query by choosing ‘Cancel, No Confirm’ from the Cancel menu or by holding down the fCuTl key when you push the Cancel button. You can modify Mail Tool so that it will not ask you to confirm certain irreversi- ble operations such as quitting windows or canceling a composition. You do this by using the Defaults Editor to turn on the expert variable. See Appendix B. 10.16. Reusing a Composition Window Normally, when you deliver or cancel a letter, the composition window folds up and goes away. If you know you’re going to want to write another letter, though, you can set the composition window to stay up after you deliver or cancel a letter. You use the Disappear button to do this. When the composition window is a pop-up window, you can set it to close itself to iconic form after canceling or delivering. (But the window will stay up if you choose ‘Leave Window Intact’ from the Deliver menu, regardless of how the Disappear cycle is set.) When the Disappear button is set to ‘Stay Up’ and you cancel or deliver a letter, the composition window goes blank. To put the address template back into the window, push the Re-address button. ©siin microsystems Revision A, of 27 March 1990 136 SunOS User’s Guide: Getting Started Note that the Cancel button changes to Clear when the Disappear cycle is set to ‘Stay Up.’ ri Compose with CT: Ip " Compose [shift] |: Compose with Cc:, Include [Ctrl] H H Compose, Include [Ctrl] [Shi ft] |i! 1017 ‘ CSosm § Mais Tool When Mail Tool is closed, it reverts to its iconic form, though it continues to run. Closing using SunView: You can close Mail Tool the way you close any other SunView window. The fastest way to close Mail Tool is to press the I Open 1 key on the key- board. Closing this way does not commit your changes. That means that any letters you have deleted will not be permanently removed, and when you open Mail Tool again you’ll still be able to undelete them. However, they’ll still be in your mailbox, taking up room — if you always open and close Mail Tool this way, you may soon have a mailbox full of temporarily deleted letters filling up your file system. It’s a good idea to commit your changes now and then, just to keep your mailbox a manageable size. Closing Mail Tool from the SunView menu also means that Mail Tool will not automatically look for new mail when you open it again. This saves time, but you will have to push the New Mail button when you want to search for new mail. Commit Changes and C Commit Changes and Qui Quit Without Committing lose Ej |uit Changes j Closing using Done: The other way to close Mail Tool is by using the Done button. When you push Done, Mail Tool commits all changes before closing itself. The next time you open Mail Tool, it will automatically look for new mail. 10.18. Quitting Mail Tool Quitting Mail Tool renders it inactive — the window closes and the icon disap- pears. Quitting using SunView: You can quit Mail Tool as you would quit any SunView window (see the SunView User’s Guide). For example, you can hold down the right mouse button over the top border of the Mail Tool window and then choose ‘Quit’ from the menu. If you do so, Mail Tool will commit changes before it disap- pears (changes will be reflected the next time you start Mail Tool). Quitting using Done: You can also use the Done button to quit. There are two ways to do this: □ Choosing ‘Commit Changes and Quit’ from the Done menu commits all your changes before quitting Mail Tool. cun microsystems Revision A, of 27 March 1990 Chapter 10 — Mail Tool 137 □ Choosing ‘Quit Without Committing Changes’ also quits Mail Tool. When you restart Mail Tool, you’ll find that any letters you’ve deleted without committing will still be there, as though you’d never deleted them. 10.19. Changing Mail Tool: Mysteries of the Misc Button Change Directory Source .mailrc Preserve The ‘Source .mailrc’ option modifies Mail Tool’s behavior. Recall that the .mailrc file contains settings affecting Mail Tool. Normally, when you modify .mailrc you have to quit and restart Mail Tool to see your changes take effect. Choosing ‘ Source .mailrc ’ allows you to incorporate changes to .mailrc while Mail Tool is running. There is a limitation on ‘Source .mailrc,’ however: If you change the setting of a variable from “not set” to “set” (from off to on), then ‘Source .mailrc’ puts the change into effect. But if you change the variable from “set” to “not set” (from on to off), then it won’t. So, when changing variable from “set” to “not set,” quit and restart Mail Tool after changing .mailrc. For a complete discussion of Mail Tool variables and how to change them, see Appendix B. xr microsystems Revision A, of 27 March 1990 □ □ 11.1. What Is mail? 11.2. mail Basics Starting mail Sending Yourself a Letter Mail mail is a SunOS program for sending and receiving electronic mail. It provides facilities for reading, writing, sending, receiving, saving, and deleting letters, mail is not window-based; thus it can be run on any terminal. Electronic mail (or e-mail) is modeled on the traditional post: letters addressed to others on the system or network are received by users in electronic mailboxes. As may be expected, e-mail is considerably quicker and less subject to the vagaries of weather; still, some correspondents will miss the colorful stamps. “mail Basics” gives you the absolute minimum necessary to start mail, send a letter, read letters, and quit the program. The remainder of the chapter explores many useful features of mail and includes discussion on using the vi text editor for writing and editing letters. In this section you’ll leam just enough about mail to get by. In later sections you’ll leam about features and functions that will greatly enhance your ability to use e-mail. Start mail by typing the following command at a prompt and then pressing I Return I : venus% mail If you don’t have any mail waiting for you, your terminal will display the mes- sage: r \ No mail for user venus % y To see at a glance how mail works, you can begin by sending yourself a letter. At the prompt, give the mail command again, but this time include your address (your log-in plus machinename) . For example, if your log-in were ‘ ‘ aphrodite and your machinename were “venus,” your address would be “aphrodite@venus.” (The @ symbol is read as “at.”) You may be able to use just your log-in on a local network — consult your system administrator when in #sun microsystems 139 Revision A, of 27 March 1990 140 SunOS User’s Guide: Getting Started Reading a Letter doubt. f venus % mail aphrodite@venus V > The program will reply with a Sub ject : line: venus% mail aphrodite@venus f:'. Subject : ^ If you like, type in a word or two here about the content of the letter you’re send- ing yours elf and p ress 1 Return 1 . Now type the body of the letter; use short lines and press l Return ) at the end of each line. (Note that you can only make correc- tions as you go by back-spacing and retyping lines before you press (Return].) Your sample letter might look something like this (the spaces between lines are made by pressing 1 Return ) twice): venus% mail aphrodite@venus Subject: banishment of solitude Dear Aphrodite, Though I'm not enamored of the thought of writing to myself — I'd love to hear from Eros — it is a way of passing the time. Maybe I'll read a thriller tonight. See you soon, Aphrodite Send yo ur letter by pressing [Return! to start a new line and then pressing LCtrl-D ). After your letter has been sent, the system will return you to a com- mand prompt. To read your letter, give the mail command again. Your screen will probably look something like this: venus% mail Mail version SMI 4.0 Mon Apr 24 17:36:41 PDT 1989 Type ? for help "/usr/ spool/mail/aphrodite" : 1 message >N 1 aphrodite@venus Fri Jul 14 12:01 21/453 banishment of & Revision A, of 27 March 1990 Chapter 11 — Mail 141 Following the information that identifies the version of mail you’re running and the mailbox where your incoming mail is deposited, there is the header of the letter you sent yourself. Every letter is assigned a number as it’s received: Aphrodite’s letter to herself is shown as letter number 1. (Header information will be analyzed in Section 11.3.) To read a letter, type its number at the mail prompt: venus% mail Mail version SMI 4.0 Mon Apr 24 17:36:41 PDT 1989 Type ? for help "/usr/spool/mail/aphrodite" : 1 message >N 1 aphroditeS venus Fri Jul 14 12:01 21/453 banishment of & 1 To: aphroditegvenus From: aphrodite@venus Subject: banishment of solitude Dear Aphrodite, Though I'm not enamored of the thought of writing to myself — I'd love to hear from Eros — it is a way of passing the time. Maybe I'll read a thriller tonight. See you soon. Aphrodite & , Sending Someone Else a Letter Now that you know how to send and read a letter, you can send to other users by giving the mail command followed by a username. venus % mail user@machine If you’ve already started mail, you can use the same command at the mail prompt: A & mail userSmachine V. i i. -S microsystems Revision A, of 27 March 1990 142 SunOS User’s Guide: Getting Started Quitting mail When you’re finished using mail, you can quit the program by typing q at the mail prompt and then pressing I Return 1 : 11.3. Reading and Deleting Letters & q V You will then see the message. Saved one message in home_directory/mbox. Whenever you quit mail after reading a message, it saves the letter in the mbox file in your home directory, unless you delete it first. If you have mail, mail notifies you each time you log in with the message You have mail or You have new mail To read your letters, type mail at a command prompt and press [ Return 1 . If there’s no mail waiting for you, you’ll see the message, No mail for aphrodite Otherwise, you’ll see something like this: venus% mail Mail version SMI 4.0 Mon Apr 24 17:36:41 PDT 1989 Type ? for help ”/usr/ spool /mail/ aphrodite" : 3 messages 1 new 1 unread 1 aphrodite@ venus Fri Jul 14 12:01 21/453 banishment of U 2 maigretSparis Fri Jul 14 18:31 19/353 pipe perdue >N 3 marloweSbaycity Sun Jul 16 23:59 14/280 getting sleep & The mail program displays information about itself (version number and date) and instructions for getting help ( Type ? for help ) . For more on help, see Section 11.8. On the next line, mail specifies the location of your mailbox (/ usr/ spool/mail/aphrodite), how many letters you’ve received ( 3 messages), and their status ( 1 new 1 unread). Next, mail shows a numbered list of the letters in your mailbox. Reading across, the columns in each line specify: □ Status: indicates whether a letter is new ( N), unread ( U), or read (no sym- bol). > at the beginning of a line indicates the current letter. Deleted letters are marked with an *. □ Number: indicates order in which letter was received. microsystems Revision A, of 27 March 1990 Chapter 11 — Mail 143 Selecting a Letter Deleting (and Undeleting) Letters From the Mailbox □ Sender: indicates name of user (and usually machine) letter came from. □ Time: indicates date and time letter was sent. □ Size: indicates number of lines/number of characters in letter. □ Subject: indicates sender-designated subject of letter. To see the current letter (marked with >), press [ Return ] . Pressing [ Return ) again will display the next letter. To read any letter in the list, type its number and press I Return 1 . In any case, the letter will look something like this: ^ Message 3: From marlowe@baycity Sun Jul 16 23:59 1989 Return-Path: Received: by venus.sun.com (4 . O/SMI-4 . 0) id AA12623; Sun, 16 Jul 89 23:59 PDT Date: Sun, 16 Jul 89 23:59 PDT From: marlowe@baycity (Philip Marlowe) Message-Id: <8910232253 . AA12 62 30 venus . sun. com> To: aphrodite@venus Subject: getting sleep Status : R Like I always say, when in doubt, have a man come through the door with a gun in his hand. Sweet dreams, Marlowe & The header of the letter contains more information than you’ll probably find desirable. Appendix B shows you how to set up mail to suppress unwanted header information. The Date : , From: , To : , and Subject : lines have been seen before. The Return-Path : line indicates the address used to return undeliverable mail; Received : indicates the machine, letter identification, and arrival time for each machine in the letter’s network path; and Message-Id : provides identification information. To delete a letter, use the command form d number at a mail prompt. For example, to delete the second letter, you would give this command (from inside mail): n microsystems Revision A, of 27 March 1990 144 SunOS User’s Guide: Getting Started & d 2 You can also delete several letters a time. To delete letters 1 and 3, you would give the command: & d 1 3 To delete letters 1 through 3, give the command: Before quitting mail you can undelete letters you’ve removed from your mail- box. Use the command form u number followed by [ Return ) . To undelete the second letter, you would give this com- mand: & u 2 Note that all deletions are made permanent when you quit mail with the q com- mand; that is, deleted letters can no longer be undeleted. You can, however, quit mail with another command that leaves your mailbox intact — quitting with x will leave read letters left marked with a U, deleted letters undeleted, etc. & X 11.4. Printing a Hard Copy You can print out a hard copy of a letter by by piping a letter to a printer com- mand. To do this, use the command form I number lpr at a mail prompt. (The I symbol is called “pipe.” See Sections 4.14 for more on printing and 7.6 for more on pipes.) For example, to print a copy of letter 2, you would type: f “ — v , — 5 12 lpr Press I Return 1 . If a letter number is not specified, mail will print the current letter. microsystems Revision A, of 27 March 1990 Chapter 11 — Mail 145 11.5. Sending Letters Canceling an Unsent Letter Adding Carbon and Blind Carbon Copies You can send mail from either the system prompt or the mail prompt. In either case, send a letter by giving the mail command followed by the address of the user; press I Return ) . You can send the same letter to multiple addressees by typing in all their addresses — separated by a space or a comma — after the mail command. For example, if you wanted to send the same letter to “hammett@glasskey” and “nisbet@frisco,” you would give this command at a system prompt: Or you could give the same command at a mail prompt: & mail hammettSglasskey nisbet@fri.sco Type your letter, pressing I Return ) at the end of each line. When you’ve finished, send the letter by typing ( Ctrl-D 1 on a new line. (You can also send a letter by typing a period on a new line.) You can cancel a letter before it’s sent by pressing I Ctrl-C 1 twice. Before sending a letter, you can specify that ‘ ‘carbon copies” be sent to other than the main addressees. You can also have ‘‘blind carbons” sent. (The differ- ence is that recipients of your letter can read the addresses of the carbons but not of the blind carbons.) Many people send themselves carbons or blind carbons in order to retain a copy for their own record. See below for ways to save mail in files and folders (spe- cial files for mail). There are three ways to send a carbon copy. First, after you’ve finished typing the body of your letter, use the command form ~c address (es) Type this command on a new line and separate addresses with a space. Press [ Ctrl-D 1 to send the letter: Or you can modify mail to make it prompt you with a Cc : after you’ve pressed I Ctrl-D 1 . See Appendix B on how to modify mail. A Cc : line is also created by the ~h command, which displays the entire header of the letter. ~h prompts you with To : , Subject:, Cc and Bcc : lines, one line at a time. Blank lines can be filled in; filled lines can be retyped. As with other tilde commands, always give the ~h command on a new line. #sun ^!r microsystems Revision A, of 27 March 1990 146 SunOS User’s Guide: Getting Started Inserting a Copy of a Letter or You can insert a copy of any letter in your mailbox into the letter you’re writing. File Likewise, you can insert a copy of any text file. Inserting a Letter The command form to insert a letter is ~m number where number is the number of the letter to be inserted. For example, to send a letter to “maigret@paris” that included a copy of the letter received from “marlowe@baycity,” you would: □ On a new line give the command ~m 3 and then press I Return 1 . mail will display the message, Interpolating: 3 (continue) You won’t see the text of message 3, but the recipient will. You can go on with your letter after continue or you can send it as is. □ To see the complete letter, interpolation included, give the commmand ~p. On your screen, the process would look like this: Revision A, of 27 March 1990 Chapter 11 — Mail 147 ' venus % mail Mail version SMI 4.0 Mon Apr 24 17:36:41 PDT 1989 Type ? for help "/usr/spool/mail/aphrodite" : 3 messages 1 new 1 unread > 1 aphroditeSvenus Fri Jul 14 12:01 21/453 banishment of 2 maigret @paris Fri Jul 14 18:31 19/353 pipe perdue 3 mar lowe@bay city Sun Jul 16 23:59 14/280 getting sleep & mail mai.gret@paris Subject: unsolicited advice Mon char Maigret, voici lea conseils da Marlowe sur des problemes structuraux du roman policier. Tres amicalement, Aphrodite ~m 3 Interpolating: 3 (continue) P Message contains: To: maigret@paris Subject: unsolicited advice Mon cher Maigret, voici les conseils de Marlowe sur des problemes structuraux du roman policier. Tres amicalement. Aphrodite >From marlowe@baycity Sun Jul 16 23:59 1989 >From: marlowe@baycity (Philip Marlowe) >To: aphrodite@ venus >Subject: getting sleep > >Like I always say, when in doubt, have a man >come through the door with a gun in his hand. > >Sweet dreams , > >Marlowe > (continue) s, Inserting a File You can also insert a copy of any text file into a letter. Use the command form ~r filename as you’re writing a letter. #sun ^ir microsystems Revision A, of 27 March 1990 148 SunOS User’s Guide: Getting Started Replying to a Letter CAUTION 11.6. Saving and Retrieving Letters Saving and Copying Letters in Files In a pathname, the ' represents the home directory. Reply to mail by giving the command r number at a mail prompt. (If you leave off the letter number, mail assumes that you’re replying to the current letter.) For example, to reply to the sender of letter 2, you would give the command: The commands rand ~r produce very different results! mail will automatically address your letter as well as supply a Re : Sub- ject : line that echoes the original Subject : line. Send your reply like any other letter. R is a variant of the reply command that sends your reply to all recipients of the original letter as well as to its sender. Note that you can insert a letter into your reply as shown in the previous section. To insert a copy of the letter you’re replying to, just give the command ~m without a letter number. In addition to sending and receiving letters, you’ll also want to save and retrieve them for later use. In mail you can save letters by appending them to regular text files; you can also append letters to special files called folders. Both methods are discussed below. mail makes a distinction between saving letters and copying them: saving removes a letter from the mailbox and appends it to a file or folder; copying leaves a letter in the mailbox and appends a copy to a file or folder. To save a letter into a file, the command form is s number filename where number is the number of the letter to be saved and filename is the file where it’s to be saved. For example, to save letter 3 into a file called ~ / f ictional_prof essions/detectives, you would give the com- mand: r — & s 3 "/fictional_professions/detectives If the file you specify does not exist, mail will create it. If the file does exist, mail will append the letter you’re saving to the end of the file. Saving a file removes it from your mailbox; mail displays an asterisk ( *) next to the header of any letter that has been saved. #sun ^sr microsystems Revision A, of 27 March 1990 Chapter 11 — Mail 149 To leave the letter in your mailbox while appending it to a file, use the copy command: C , : /.. — — — — 1 & c 3 '/fictional^rofessions/detectives Saving and Copying Letters in You can dispense with typing full pathnames to files if you save or copy letters in Folders mail folders. Folders are special files that are stored in a folder directory. The advantages to saving or copying letters in folders is that your letters are automatically kept together in the same directory, where they are easily accessi- ble without typing long pathnames. Setting the Folder Directory To use folders, you must first set up a folder directory. This is a two-step process: □ First, make the directory using mkdir. For example, if you wanted your folder directory to be called Letters, you would first make the directory: r A venus% mkdir Letters J □ Second, use a text editor or the SunView Defaults Editor to edit your . mailrc file (which contains mail options) to set the folder directory path. (Appendix B contains a detailed discussion of mail options and how to set them.) Here, you need to edit the ‘ ‘set folder’ ’ variable to include the pathname of your newly created folder directory: _ set f older=/home/trouble/aphrodite/Letters — Or A set f older=“/Letters V _ J Now your folder directory is set to receive letters saved in folders. (The change to the . mailrc file will take effect the next time you start mail.) Designating Folders You use the same commands to save or copy letters in folders as into files, except that the folder name is preceded by a + (plus sign) instead of a pathname. The + tells mail that the folder is to be kept in the folder directory ( Letters). For example, to save letter 3 in a folder called noir_writ ing, you would give the command: A & s 3 +noir_writing V iii — Liii — -Ji — — J Revision A, of 27 March 1990 150 SunOS User’s Guide: Getting Started mail interprets this command as meaning “save letter 3 into /home/ trouble/ aphrodite/Letters/noir_writ ing.’’ (If the folder doesn’t already exist, mail will create it.) Copy the letter into a folder by giving the command: & c 3 +noir_writing Sending a Letter Directly to a You can send copies of your letters directly to one of your files or folders. To File or Folder send a copy to a folder, simply type the folder name in either the Cc : or the Bcc : field. Sending a copy to file is similar, but you must include the full path- name. Reading Letters in Files and To read letters saved in a file, use the command form Folders mail -f filename Using the example above, you would read the file ~ / f ictional_prof essions/detectives by giving the command: f venus % mail -f ~/fictional_prof essions/detectives You can read letters saved in a folder with a similar command — just use the + instead of a pathname. For example, to read the letters in the folder noir_writing, you would give the command: venus % mail -f +noi r_wri t ing V folder dire ' ' ^ + des ' 9nates the The command starts mail in the file or folder designated. Only headers for the o er ire ory. letters in the file or folder are displayed. Select a letter to read by typing its number at the mail prompt and pressing I Return 1 . You can also work on mail folders within the mail program. To see a list of your folders, type at a mail prompt folders To switch from your mailbox to a folder, use the command form folder +foldername To return to the mailbox, type at a mail prompt o o To return to the previous folder, type # microsystems Revision A, of 27 March 1990 Chapter 11 — Mail 151 11 . 7 . Using vi With You can use the vi text editor to compose letters while running mail. This ma il gives you the capability of correcting mistakes and adding and deleting text before you send your letters. Under mail you can use the standard vi commands for inserting, deleting, and changing text. See Chapter 5 for a tutorial. To write a letter with vi: □ Give the mail command with an address at either the mail prompt ( &) or the command prompt ( venus%). □ Type in the subject at the Sub ject : line. Press 1 Return ) . □ Start vi by giving the command ~ v on a new line. The vi screen will appear, representing an empty file in your / tmp directory. □ Use vi commands to input and edit the body of your letter. □ When done, quit vi with the command : wq. After you quit vi, mail displays (continue) : here you can either add to the letter (outside vi) or send the letter by pressing [ Ctrl-D ) . 11.8. Getting Help: Other mail has two help commands that display lists of commands and functions. mail Commands When in command mode, you can type ? at the mail prompt ( &) to see a list of commands used in that mode. Likewise, when in input mode (i.e., when writing a letter), you can give the equivalent command, ~ ? to view a list of tilde com- mands (also called “tilde escapes”). As you become more familiar with the SunOS operating system and mail, you may want to try out some of these commands. Give the commands below at the mail prompt (&): microsystems Revision A, of 27 March 1990 152 SunOS User’s Guide: Getting Started Figure 11-1 mail Prompt Commands £ ? cd [directory] d [message list] [message list] |f [message list] [user list] Ip [message list] chdir to directory or home if none given delete messages edit messages show from lines of messages print out active message headers mail to specific users goto and type next message print messages make messages go back to system mailbox quit, saving unresolved messages in mbox reply to sender (only) of messages reply to sender and all recipients of mess append messages to file type messages (same as print) show top lines of messages undelete messages edit messages with display editor append messages to file, without from line quit, do not change system mailbox display next [previous] page of headers shell escape A [message list] consists of integers, ranges of same, or user names separ ated by spaces. If omitted, Mail uses the current message. LQ ___ pre [message list] q r [message list] R [message list] ages s [message list] file t [message list] top [message list] [message list] [message list] [message list] file V [-] The following commands are given only on new lines when composing or edit- ing a letter: Revision A, of 27 March 1990 Chapter 11 — Mail 153 Figure 11-2 mail Tilde Commands & m mar lowe@bay city Subject: wanna help ~a,~A ~b users ~c users ~d ~e ~m messages ~f messages ~h ~p ~q,~Q ~x ~r file ~s subject ~t users ~v ~w file “7 ~ ! command ~] command command ~ ESCAPES Quote a single tilde Autograph (Insert ■'sign'' variable) Add users to Bcc list Add users to Cc list Read in dead. letter file Edit the message buffer Read in messages, right-shifted by a tab Read in messages, do not right-shift Prompt for To list, Subject and Cc list Print the message buffer Quit, save letter in $H0ME/dead. letter Quit, do not save letter Read a file into the message buffer Set subject Add users to To list Invoke display editor on message Vrite message onto file End of input Print this message Run a shell command Pipe the message through the command Execute regular Mail command ] The man pages contain extensive information on mail in more technical form. To see this entry, give the command: venus % man mail microsystems Revision A, of 27 March 1990 12 Other Mail Features There are several commands that can help you read and send mail and messages. This chapter introduces you to the use of □ The from command, which lets you find out who sent you mail; □ The vacat ion program, for responding to and forwarding mail when you’re out of the office; and □ the chf n command, which allows you to change your name in the headers of mail you send. 12.1. Mail From Whom? When you want to know whom your mail is from, without reading it using mail The from Command or Mail Tool, type from to your command prompt. For each letter waiting in your mailbox, from displays From followed by the sender’s username, and the date and time it arrived in your mailbox; venus % from From sappho@aphrodite Sun Apr 1 8:45:12 1989 From rimbaud@verlaine Sun Apr 1 8:45:22 1989 From michaelangelo@david Sun Apr 1 8:45:45 1989 venus % For more information on from, see the from man page, online or in the SunOS Reference Manual. 12.2. The vacation You still receive mail when you’re gone — even if your machine is turned off. Program The vacation utility automatically sends a pre-written response to anyone who sends you mail. Incoming mail is not affected; vacation acts like an electronic mail equivalent of a telephone answering machine. Simply type vacation to start the program. It will help you create the file which contains the automatic reply. This file is called . vacat ion. msg and lives in your home directory, vacation automatically sets you up in your nor- mal editor to edit a standard version of the reply letter. You can modify . vacation .msg to say whatever you like. It should, how- ever, start out with a Subject : line. If you include the word “SSUBJECT” in your reply, the subject of whatever letter you’re replying to will be inserted at • sun W’ microsystems 155 Revision A, of 27 March 1990 156 SunOS User’s Guide: Getting Started that point. Here’s a sample . vacation .msg file: Figure 12-1 A Sample . vacation .msg File This is how vacation works (in this case, using vi): venus % vacation This program can be used to answer your mail automatically when you go away on vacation. You need to create a message file in /home/venus /medici/. vacation. msg first. Please use your editor (/usr/local/vi) to edit this file. (Here you edit the sample vacation .msg) You have a message file in /home/venus/medici/ . vacation .msg . Would you like to see it? n Would you like to edit it? n To enable the vacation feature a ".forward" file is created. Would you like to enable the vacation feature? y Vacation feature ENABLED. Please remember to turn it off when you get back from vacation. Bon voyage, venus % To turn vacation off, or to modify your automatic reply letter, type vaca- tion as you did to start it up. vacation waits a specified interval before sending out your reply to someone it’s already replied to; that way, someone who writes you several times while you’re gone doesn’t get your letter over and over again. (This specified interval is usually one week, but you can change it.) Saving Mai! With the As shown above, vacation creates a file called . forward. This file is one . forward File line long and looks like this: \user, " I /usr/ucb/vacation user" Mail programs look in . forward to see where they should send mail addressed to you. In the case of the . forward file shown above, mail is sent to the user user and to the vacation program. You can modify . forward (which lives in your home directory) with an editor; you could, for example, forward copies of all your letters to another user or another machine. One of the most common ways people use . forward is to send copies of every letter they receive into a storage file. In the example below, the file inbox in the directory f#sun microsystems Revision A, of 27 March 1990 Chapter 12 — Other Mail Features 157 /home/venus/medici gets a copy of all incoming mail. (Note that it doesn’t send mail to vacation, although it could.): venus% cat .forward \medici, /home/venus/medici/ inbox venus % NOTE If you do forward mail to a file like inbox, be sure to prune it from time to time — it can get quite large! Complete information on vacation can be found either by reading the vaca- tion section in the SunOS Reference Manual or by typing man vacation; information on the . forward file can be found by typing man aliases. 12.3. Changing Your Name Another useful command to know is the chf n command. Below is an example With chf n of a typical letter header: From finches@galapagos Sun Feb 12 17:02:36 1859 From finches@galapagos (Charles Darwin) To: mediciQvenus Subject: Huxley's 'The Descent of Bulldog' Note that the mail header not only has the username {finches) and machinename ( galapagos ) of the sender, it also give his real name ( Charles Darwin). You can put your real name — or office extension, or job title, or whatever — in the header of messages you send by using the chf n command, (chf n stands for “change full name.”) Or you can use the passwd command, which is intro- duced in SunOS User’s Guide: Getting Started , with the -f option. The two commands are equivalent. Here’s how Charles Darwin would change the phrase “Charles Darwin” to “Charles Darwin, famous biologist ”: galapagos: chfn Changing finger information for finches on galapagos. Default values are printed inside of '[]'. To accept the default, type . To have a blank entry, type the word 'none'. Name [Charles Darwin] : Charles Darwin, famous biologist galapagos : Now, messages from f inches@galapagos will look like this: Revision A, of 27 March 1990 SunOS User’s Guide: Getting Started From f inches Qgalapagos Sun Feb 12 17:02:36 1859 From f inches @galapagos (Charles Darwin, famous biologist) To: medici@venus Subject: Huxley's 'The Descent of Bulldog' CAUTION Be careful not to use parentheses in your name field. Parentheses are automatically added by the mail system. Asun microsystems Revision A, of 27 March 1990 13.1. What Networks Are Out There? The UUCP Network Sending Mail to People on the UUCP Network Mail Over Networks This chapter describes remote networks for the purpose of understanding how to send mail across them. For more information about networks in general, see Chapter 8. There are many different kinds of networks, and each uses a different syntax for addressing letters. Some networks aren’t connected to your network, making it impossible to exhange mail with their users. Before attempting to send mail to someone on a remote network, you must find out which network they’re on. UUCP and the Internet are the major networks. UUCP is a program that allows machines to use telephones to transmit data. You send mail to other users by sending it through intermediate machines; each machine-to-machine pathway is unique. UUCP can be used to communicate with machines across the United States and throughout the world. To send mail to someone on the UUCP network, you must know the network path, or sequence of machines the letter must travel through to get from your machine to the recipient’s machine. To find out machine name sequences necessary for mail addresses, ask prospec- tive letter recipients if they know the appropriate network path. At the least, find out the prospective mail recipient’s username and machine name.-’ You can figure out the prospective recipient’s mail address from this sequence of machine names. Pretend to walk along the path between the two machines start- ing with the first machine in the sequence and separating each machine name with an exclamation point ( ! ), also called “bang.” Add the recipient’s user- name to the end of the address after one last exclamation point. For example, to figure out the mail address that user bilbo on machine shire would use to send mail to user galadriel on machine loth- lorien, walk from shire to lothlorien. 5 When the letter recipient doesn’t know the appropriate mail address, ask your system administrator, if you have one. microsystems 159 Revision A, of 27 March 1990 160 SunOS User’s Guide: Getting Started Figure 13-1 Sequence of Machines in Network The sequence of machine names is: oldforest, bree.and lothlorien. The recipient s username is galadriel.® So the complete mail address is: oldforest !bree ! lothlorien ! galadriel When you specify the mail address on the command line after mail, make sure to put a backslash character (\) before each occurrence of an exclamation point (oldforest \ ! bree\ !lothlorien\ ! galadriel in the above example), so that the shell interprets the address properly. 7 However, it is not necessary to use a backslash when you’re already in mail or Mail Tool. Backslashes are only needed when you’re typing in an address as part of a command line. You can learn about aliasing a mail address to another character string in the mail man page, online or in the SunOS Reference Manual. How Does Someone Send Mail When people with accounts on a UUCP machine ask you how they can send mail to Me on the UUCP Network? to you, try to come up with the appropriate network path. Determine your user- name, your machine name, and other machines you know your machine talks to using UUCP. Determine the other person’s username, machine name, and associ- ated machines. Hopefully, you will discover an associated machine in common, so that you can identify a network path between you. 8 6 These names and places come from J.R.R. Tolkien’s Lord of the Rings. 1 The shell usually interprets exclamation points as part of the history mechanism. Putting a backslash before each exclamation point requires the shell to interpret the exclamation points as regular characters rather than as special history mechanism characters. See Chapter 7 for more information about the history mechanism. 8 Some sues support uuname, a program which lists the names of systems accessible by UUCP, and uupath, which gives UUCP paths between known machines. #sun microsystems Revision A, of 27 March 1990 Chapter 13 — Mail Over Networks 161 The Internet For more information on the UUCP network, see your system administrator or look in System and Network Administration. To send mail to someone on the Internet, you must find out the username and machine name of the mail recipient, usually by asking the recipient. Unlike the UUCP network, however, you don’t need to know the names of all the machines between your machine and the recipient’s. The Internet takes care of that part automatically. Construct the mail address by typing the recipient’s username, followed by an at-sign character (@), the recipient’s machine name, and his or her institution’s full domain name, which should end in one of the following suffixes: .COM Asigned to commercial organizations. .EDU Assigned to educational institutions, chiefly universities. .ORG Assigned to nonprofit agencies. .GOV Assigned to government agencies. .MIL Assigned to military organizations. Note that you do not have to capitalize the suffixes — you can say, for example, . com instead of . COM. So, for user lumpy on machine geewhiz at Extreme South-Eastern Rhode Island University (domain name: exsoeari . edu), the appropriate mail address would be: lumpySgeewhiz . exsoeari . edu Providing your username and domain name should be sufficient for someone on an Internet-linked machine to send you mail. 9 For more information on the Internet, see Chapter 8 and System and Network Administration. 9 Sometimes, the situation gets more complex. Contact your system administrator or look in System and Network Administration. microsystems Revision A, of 27 March 1990 Mail Aliases A mail alias is a selection of user names grouped under a single name. Use aliases when you want to send mail to the same group of people over and over. For example, if you want to send mail from time to time to joe@ donkey, bill@whitehouse, and laura@ smiley, you can create an alias called buddies; each time you send mail to buddies, you send it to all three people. There are two different ways to set up aliases. One is to set up an alias in your .mailrc file. The other way is to use the file /etc/aliases. These two kinds of aliases work differently, and you set them up differently. The table at the end of this chapter summarizes these differences. A.l. Aliases in .mailrc .mailrc is located in your home directory. It contains a number of settings that control the behavior of mail and Mail Tool, .mailrc is explained in detail in Appendix B. To add an alias to . mailrc, type: venus % vi + "/.mailrc ( + puts you at the file' s end) ( edit .mailrc) s — — You don’t have to use vi: any other text editor will do. But you cannot set up aliases with the SunView Defaults Editor. Each alias takes up one line, with no carriage returns. (The line can visually “wrap around” onto another line.) Each alias should contain the following, separated by spaces: □ The word “alias,” □ The name of the alias (one word), and □ The people (username and machinename) in the alias, separated by spaces. The example below shows two aliases. The first (buddies) has three people on it. The second (chums) has eight. (The names are wrapped around on the screen, splitting ray@eastbay in the middle). ®sun ^ir microsystems 163 Revision A, of 27 March 1990 164 SunOS User’s Guide: Getting Started Figure A-l A .mailrc Alias alias buddies joe@donkey bill@whitehouse laura@smiley alias chums dickiegtucan janep@rydall tolouse@lautrec ray@e astbay bartongbridge luigigpasta momghome sallygdance To send mail to people on a .mailrc alias, just address it to the name of the alias. Do not include the name of your machine. For example, if you set up buddies, don’t send to buddies Qyour-machinename. Just mail to bud- dies. Some things to note about aliases in .mailrc: □ Aliases in . mailrc are private. That means that only you can use them. If another user tries to send to buddies, he will receive a “user unknown” error message. □ . mailrc aliases are automatically expanded, when the mail goes out, to show everyone on the alias. When you send to buddies, your mail arrives as though you had typed everyone’s name as recipients. So everyone receiv- ing the mail knows who else received it, although they cannot tell that you used an alias to send it. For example, if you sent this letter: % — venus% mail buddies Subject: Removal of Deceased Personnel Employees are instructed to please not remove personnel who may expire in front of their computers. Instead, please contact the Office of Human Disposal and fill out form 1-38 6/B. Someone receiving the message would see this (note the To : line): To: billgwhitehouse joegdonkey lauragsmiley Subject: Removal of Deceased Personnel Employees are instructed to please not remove ( rest of message) Aliases in /etc/ aliases Aliases in the file aliases in the directory /etc work similarly to those in .mailrc, but there are important differences: □ Aliases in / etc/aliases are public. This means that if you set up an alias there called lunchers, anyone can send to lunchersgyoMr- machinename and thus make use of the alias. Revision A, of 27 March 1990 Appendix A — Mail Aliases 1 65 □ /etc/aliases aliases are not expanded when mail goes out. If you send to lunchers Qmachinename, that’s how the mail will read when received. This means that recipients will know what the alias is, but not necesarily know who else is on it. For example, suppose you send out this message: venus % mail chewers @ venus Subject: New Restaurant There's a new Indo- Japanese Thai place that's opened on Garcia Ave. It specializes in meat by-products from around the globe, and the Almost Chicken Kiev is exquisite. So, in it's own way, was the Inquisition, of course. Anyone wanna go? This is what would appear to a recipient (note that the To : line remains unchanged): — - To: chewers@venus Subject: New Restaurant There's a new Indo-Japanese Thai place that's (rest of message) The format of /etc/aliases aliases is somewhat different from those found in .mailrc. The format is as follows: o the name of the alias, followed by a colon □ recipients (usernames and machinenames), separated by commas. The alias does not have to be on a single line Here’s how you’d set up two aliases, lunchers and chewers: Figure A-2 /etc/aliases Aliases ^ lunchers: joe@donkey, billSwhitehouse, laura@smiley, tecun@uman, flann@swim2birds, odysseus@ithaka, weasel@toadhall chewers: bradk® zoohouse, jody@taxi, marmot@tomram, lunk@head You must become root to modify your /etc/ aliases file. 10 Here’s how you would set up or modify an /etc/aliases alias (you can use another 10 For more on becoming root or “superuser,” see SunOS User’s Guide: Doing More. microsystems Revision A, of 27 March 1990 166 SunOS User’s Guide: Getting Started editor besides vi): — venus % su ( become root) # vi + /etc/aliases ( + puts you at the file' s end) ( edit /etc/aliases) # lCtrl-D) ( leave root) venus % NOTE Aliases should always go at the end of /etc/aliases. When you send mail to an alias, be sure to add the name of the machine on which it’s located. If someone has set up an alias called air_user s on the machine Canute, then you should send your mail to air_users@canute. For more information, see “addresses” in the SunOS Reference Manual, or type man aliases or man addresses at a system prompt. Table A-l Comparing Aliases: . mailrc and /etc/aliases .mailrc / etc/aliases Must be root to modify? no yes Send message to: alias alias@machinename Recipients list seen by recipients? yes no Names separated by commas? no yes Names all on one line? yes no Others can use? no yes &sun microsystems Revision A, of 27 March 1990 B Modifying mail and Mail Tool The . ma i 1 r c file contains a number of parameters that affect the way ma i 1 and Mail Tool work. By changing this file you can customize these programs to behave the way you want them to. . mailrc is usually located in your home directory. It can be viewed with more and edited with vi or the SunView Text Editor. But if you’re running SunView, you should use the Defaults Editor to modify .mailrc (except for the creation or deletion of aliases). There is a sample .mailrc file, called Mailrc, in /usr/lib. It contains many convenient option settings; to get a copy for your use, copy it to your home directory as follows. (Before you do, type Is “ / . mailrc to see if you already have your own .mailrc file. If you get nothing back but your prompt, then you don’t.) venus% cp /usr/lib/Mailrc “/.mailrc venus% This is what the default Mailrc file looks like: &sun microsystems 167 Revision A, of 27 March 1990 168 SunOS User’s Guide: Getting Started Figure B-l The Default Mailrc File B.l. Using the Defaults Editor A default is the automatic, assumed value of a setting; i.e., the value it has if you do nothing. If, for instance, you normally leave your office door open, you can say that the default for the door is ''open.” The SunView User’s Guide contains an explanation of how to use the Defaults Editor. The Defaults Editor is a simple, interactive program that lets you change a number of SunView defaults in addition to those in .mailrc. The Defaults Editor presents you with a number of settings you can change, with short expla- nations of each item. To bring it up, choose ‘Defaults Editor’ from the ‘Editors’ menu in SunView. Or you can give this command; #sun microsystems Revision A, of 27 March 1990 Appendix B — Modifying mail and Mail Tool 169 Figure B-2 .mailrc in the Defaults Editor Window Category OMail I^SaveJ [Quit] [Reset] [Edit Item| /Mai 1 /Set/aluaysusepopup Controls creation of message composition window Mailtool related options Set /a 11 ou reve rsescan (No) C No Set /a 1 way susepopup (No) C Yes Set/askbcc (No) O No Set /bell (0) 3 Set/disablef ields (No) ONo Set /expert (No) C No Set/f i lemenu Set /f i 1 emenus i ze (10) Set/f lash (0) 3 Set/interval (300) Set /move i nputf ocus (No) C No Set /msgpe rcent (50) Set/printmai 1 Set /trash options relating to appearance of ma Set /and 1 ines (4) /h/aarinrlinnc t icn With the Defaults Editor, many mail and Mail Tool options are turned on by setting them to ‘Yes’ and switched off by setting them to ‘No.’ However, if you can’t use the Defaults Editor, you can still modify .mailrc with a conventional editor such as vi or Text Editor. To set a .mailrc option, include a line like this: set option To turn an option off, either remove the above line or put the prefix no in front of the option’s name: set no option in .mailrc. Some options in . mailrc are not simple “on/off” settings, but require you to put in a value. For example, to set your folder directory, you type its name in at the appropriate place in the Defaults Editor. If you’re not using the Defaults Edi- tor, you’d put in a line like set folder=/home/medici/mail (or whatever your folder directory will be). microsystems Revision A, of 27 March 1990 170 SunOS User’s Guide: Getting Started NOTE “Turning an option on," “setting an option," and using the Defaults Editor to set it to 'Yes’ are all synonymous; “turning it off,” “unsetting” it, and setting it to ‘No’ also all mean the same thing. But you can set a variable to ‘No’ only when you are using the Defaults Editor. Do not put a line in your .mail rcfile that says set option=No. If you do not change a setting in . mailrc, then the default value is assumed. For more information on mail and Mail Tool, and their associated options, see the SunOS Reference Manual. (Mail Tool is spelled mailtool.) B.2. Mail Tool-Related Options Scan mail in reverse with allowreversescan When turned on, allows you to go through the letters in your mailbox in reverse order; i.e., last to first. This affects which letter is next — if the sense of direction is reversed, then the letter displayed by the Next button is actually the previous one. Default setting: turned off. Get separate composition window with alwaysusepopup Turning this on makes the composition window come up as a separate win- dow frame; otherwise the composition window is simply split off from the message subwindow. Default: turned off. Set automatic blind carbon copy prompt with askbcc This gives a “Bcc:” prompt when set. “Bcc” stands for blind carbon copy. Like “Cc:”, except that the list of people you copy the letter to doesn’t appear in the letter header, so you can copy a letter to someone without alert- ing the addressee. Default: turned off. Mail Tool beeps when mail arrives with bell Number of times you want the terminal to beep when you get a letter. Default: no beep. See also flash. Remove address fields with disablef ields Including this option removes the fields in the composition window’s address template. Default: turned off. Confirm edits in message window with editmessagewindow With editmessagewindow turned on, if you try to edit a letter in the message window, Mail Tool will first ask you to confirm that you want to edit it. Default: turned off. Disable confirmations with expert When you have expert set, Mail Tool does not ask you to confirm dele- tions, cancellations, etc. Default: turned off. Set File: menu with f ilemenu The File : prompt in the command panel window has a menu of folders you’ve been working with. You can set f ilemenu so that certain files are automatically included on this menu when Mail Tool starts. Examples Revision A, of 27 March 1990 Appendix B — Modifying mail and Mail Tool 171 / When you set a variable to have a value that is expressed by more than one word, put the variable in quotes. For example, if you want f ilemenu to include more than one file, put the list of files in quotes: '+trash +mbox'. Mail Tool cannot flash without beeping, but it can beep without flashing. This means that if you set flash to 3 and bell to 1, you will get one flash and one beep. If you set bell to 3 and flash to 1, you will get three beeps and one flash. See bell, above. Change frequency new mail is checked for with interval Time (in seconds) that Mail Tool waits before checking for new mail Default: 300 seconds (5 minutes). Set prompt in composition window with moveinputf ocus move input focus controls where you type when you start a composition window: with moveinputfocus set, the composition window automati- cally becomes the window you’re typing in as soon as it comes up. This feature only has meaning if you are using “Click-to-Type,” described in the S unView User’s Guide. Default: turned off. Change proportion of message to composition window with msgpercent This controls how much of the message subwindow will be used for a com- position window when composing a letter. Default: 50 percent. But if alwaysusepopup is set, this setting has no meaning. Set print command with printmail The command for printing a letter. You can use whatever printing scheme works best for you. Normally set to ' lpr -p ' . Store deleted letters with trash trash is a file that collects your deleted letters; they stay here until you push the Done button. Setting trash allows you to look at deleted letters as though they were saved in a regular file. You set trash to the name of your trash file. If set to +t rash, it can be accessed like any other folder. include -i-trash and -i-mbox. (See trash and MBOX, below.) Set number of files in File: menu with f ilemenusize Maximum number of files in the File : prompt’s menu. Default: 10. Mail Tool flashes when mail arrives with flash Number of times to flash Mail Tool when mail arrives. Also flashes the Mail Tool icon when Mail Tool is closed. Default: 0. Options Relating to the Appearance of Mail Tool: Change size of header list window with headerlines Default: 10 lines. Revision A, of 27 March 1990 172 SunOS User’s Guide: Getting Started Change size of message window with maillines Default: 30 lines. Change size of composition windows with popuplines Default: 30 lines. B.3. Options Affecting Both mail and Mail Too! Treat network names with matching usernames as identical with allnet All network names whose usernames (e.g., helen in helen@ troy, helengkeller, and helenglavosh) match are treated as identical. Default: turned off. Ignore [ Ctrl-C ] when typing letters with alwaysignore See Section B.5 for more on alwaysignore. Add letters to beginning of mbox with append Normally letters are added to the end of mbox; if you prefer to have your most recent arrivals go to the beginning, set noappend or set to ‘No’ with the Defaults Editor. See MBOX and hold. ask No longer implemented. See asksub. Set automatic carbon copy prompt with askcc When this is set you are automatically given the “Cc:” (carbon copy) prompt when composing a letter. The default setting is to have this feature turned off. Set automatic subject prompt with asksub Automatically prompts for a subject when you’re composing a letter. Default: turned on. Display next letter after a deletion with autoprint With autoprint on, mail and Mail Tool display the next letter in the mailbox when one is deleted. Default: turned off. Specify file to store interrupted letters with DEAD This ghoulish variable takes the name of a file (with its full path name) where partial letters get stored in case of an interruption like a power failure. DEAD is normally set to be a file called dead . letter in your home directory. The save variable must be set for this variable to take effect. See save. Designate folder directory with folder This is the directory that contains your mail folders. For more information, see the outf older variable below. Keep letters in mailbox with hold Revision A, of 27 March 1990 Appendix B — Modifying mail and Mail Tool 173 When hold is turned on, letters you’ve read are still kept in your mailbox until you save or delete them. When hold is turned off, already-read letters are moved to a file (usually located in your home directory and called mbox) when you do a commit, hold is turned off for mail, on for Mail Tool. See MBOX. Indent included letters with indentpref ix When composing a letter, you can include another letter, indented to set it off. indentpref ix is what gets put to the left of a letter when it’s indented. The default is just a tab; you can put in one or more characters of your choice, surrounded by quotes, to indicate that this is an included letter. A tab is indicated by a I Ctrl-1 1 or "'I. Keep mailbox with keep keep signals that you want to keep your mailbox even when it’s empty. Turning keep on means that your mailbox is truncated to zero length when empty, instead of removed and created anew when you get mail. Default: turned off. Retain saved letters in mailbox with keeps ave Normally when you save a letter into a file or folder, you delete it from your mailbox. (In Mail Tool, letters are not deleted if you use the ‘Copy’ option of Save.) Setting keepsave prevents mail or Mail Tool from deleting it automatically. Remember, multi-word variable Set command to display folder directory with LISTER values, like 'Is -F' , should go in quotes. LISTER is set to a SunOS shell command which you use for displaying the contents of your folder directory. In Mail Tool, the default is Is -F; in mail, the default is Is. If you change LISTER, the command you replace it with must display directories as a “/” the way Is -F does, for Mail Tool to work correctly. See Is in the SunOS Reference Manualor type man Is for more informa- tion. Designate mailbox file with MBOX Normally, letters you’ve read are kept in your mailbox until deleted or saved. When hold is turned off, however, these letters are saved into a file specified by MBOX. Normally this is a file called mbox in your home direc- tory. See hold. Designate yourself as recipient with metoo When you send something to an alias group of which you’re a member, you don’t receive a copy of the letter unless you specifically address it to your- self as well. Setting metoo, however, includes you among the recipients. Default: turned off. metoo will work for alias groups that you declare in your ,mai lrc file. Whether it works for other mail aliases depends on how your system is set up. Revision A, of 27 March 1990 174 SunOS User’s Guide: Getting Started Addresses given relative to yours with onehop When you receive a letter that was sent to several people, the other reci- pients’ machine addresses are normally given relative to the author’s address. Setting onehop allows the others’ addresses to be given relative to your own — i.e., just “one hop” away from you, not through the author. This makes your replies more efficient. Place letter record in folder directory with outf older You can keep a record of every letter you send; they go into a file set by the variable record. If outfolder is turned on, then this file will be located in your folder directory. Default: turned off. See also folder and record. Designate letter record file with record You set record to be the name of a file that receives a copy of every letter you send. If outfolder is turned on, then this file is located in your folder directory (set with the folder variable). If outfolder isn’t turned on, then record should include the full pathname of this file. Reverse reply commands with replyall The net effect of setting replyall is to reverse mail’s R and r com- mands or, in Mail Tool, to reverse the meanings of ‘Reply’ and ‘Reply (all).’ Default: turned off. Store interrupted letters with save When turned on, mail and Mail Tool save partial letters into the file specified by DEAD in case of an interruption like a power failure. Default: turned on. See DEAD . Specify mail delivery program with sendmail mail and Mail Tool usually use the program sendmail to deliver mail; you can specify an alternate program here. Display letter recipient with showto Sometimes you send letters to yourself (for example when you “Cc:” your- self or send a letter to an alias group that includes you). If you set showto, mail and Mail Tool display the letter’s recipient, rather than the sender (who is yourself). That way you see why you received mail you sent, rather than that you sent it. By default, mail and Mail Tool display the sender in all cases. B.4. Options That Affect Only Mail bang (for advanced users) Enables the special-casing of exclamation points (!) in shell escape com- mand lines as in vi. ! (not followed by a shell command) gives you a his- tory of shell commands you’ve done in mail. Default: turned off. microsystems Revision A, of 27 March 1990 Appendix B — Modifying mail and Mail Tool 175 cmd (for advanced users) Example: set cmd=' lpr -h'. When you type | ("pipe”) at the mail The default shell command for the pipe command in mail, prompt, it is interpreted as “Pipe to lpr -h.” Convert uucp addresses to internet with conv Convert uucp addresses to the specified address style. The only valid conversion now is internet , which requires a mail delivery program conforming to the RFC822 standard for electronic mail addressing. Conver- sion is normally disabled. See the -U command-line option in the mail section of the SunOS Reference Manual. Set crt number of lines with crt crt is a number roughly corresponding to the number of vertical lines in many terminal screens. If a letter has more than this number of lines, mail pipes it through a displaying command set by PAGER (usually the more command). Default: turned off. See PAGER. Terminate letters with a dot Accept a dot (V) alone on a line to terminate a letter. This is the default. The variable ignoreeof takes precedence over dot. See ignoreeof in this section. Edit mail headers with editheaders If set, the message headers are included in the text to be edited by the " e and ~v commands. Set editor with EDITOR The edit and ~e commands invoke an editor to use when writing letters; EDITOR sets the editor to use. The default is ex. Change mail escape character with escape You can replace the ~ in commands such as ~h, ~e, and ~m with a char- acter of your own choosing. Turn off header list display with header This variable is normally set, so that when you enter mail the header list is displayed. You can suppress the initial display of the header list by turning this variable off. Ignore ( Ctrl-C 1 when typing letters with ignore You may wish to ignore a I Ctrl-C 1 when typing a letter, especially if you have a noisy dial-up line. Terminate letters with dot or tilde-dot with ignoreeof Normally you terminate a letter with a I Ctrl-D ) . Setting ignoreeof means you must end a letter with either a period on a line by itself or the ~ . command, ignoreeof takes precedence over dot. Insert form feeds with page microsystems Revision A, of 27 March 1990 176 SunOS User’s Guide: Getting Started Remember to enclose your signa- ture in quotes. Insert a form feed after each letter. Default: turned off. Set command to display long letters with PAGER The command that mail uses to display long letters — usually more. See crt . Set mail prompt with prompt Set to & by default. You can change the symbol. Suppress display of first letter with quiet mail normally displays a short message, including its version number, when it starts up. You can turn this off to suppress this message. Set number of header summaries displayed with screen The maximum number of header summaries to be displayed at one time; i.e., the amount of the screen to be taken up by the header list. No default. Mail waits to return prompt with sendwait With sendwait set, mail (or Mail Tool) waits until it has finished send- ing off a letter before coming back to the user. Default: turned off. Set command interpreter with SHELL The name of a preferred command interpreter; usually sh; you can set this to (for example) /bin/csh . The command interpreter is inherited from the environment unless you specify it here. Designate special signature with sign You can “sign” your letter with the ~a command in mail; the sign variable is your “signature.” It could be some pithy phrase you want to finish your letters with. Specify number of lines displayed with top lines The top command in mail prints out the first few lines of letters whose letter numbers you give, toplines specifies how many lines to print out. Default: 5 lines. Set verbose option with verbose When set, sendmail is used with the -v (verbose) option. Default: not set. See sendmail ( 8 ) in the SunOS Reference Manual or type man 8 sendmail. Specify screen editor with VISUAL The name of the screen editor used when you type the ~ v command in mail. Default: vi. #sun microsystems Revision A, of 27 March 1990 Appendix B — Modifying mail and Mail Tool 111 B.5. Suppressing Header Your letters begin with a header that contains lines like these: Lines in Letters From loeb@leopold Fri Aug 21 15:18:42 1924 Return-Path: Received: from leopold.XXX.uucp by darrow .XXX .uucp (3 . 2/SMI-3 . 0) id AA21411; Fri, 21 Aug 87 15:18:32 PDT Received: by leopold.XXX.uucp (3 . 2 /SMI-3 . 0) id AA20410; Fri, 21 Aug 24 15:22:11 PDT Date: Fri, 21 Aug 24 15:22:11 PDT From: loeb@leopold (Arthur Garfield Hayes) Message-Id: <8788212322 . AA00410@leopold. XXX. uucp> To: clarence@darrow Subject: Scopes Case Background Status : RO You can have mail and Mail Tool suppress the display of any of these lines by including an “ignore” line in your .mailrc file. For example, the following line ignore message-id return-path received date status via produces a header that looks like this: From loebSleopold Fri Aug 21 15:18:42 1924 From: loeb@leopold (Arthur Garfield Hayes) To: clarenceSdarrow Subject: Scopes Case Background You can pick and choose which of the header categories you want to have displayed. You cannot use the Defaults Editor to add an ignore line to .mailrc. You must edit .mailrc with a conventional editor such as vi or Text Editor. The header categories that you tell mail and Mail Tool not to display are still included when the letter is saved. However, if alwaysignore is set, then these header lines are not saved, either. This is also true for copying and includ- ing letters as well. In Mail Tool, you can use the Show button’s menu to override the ignore option. The ‘Show Full Header’ option will display a letter’s full header. microsystems Revision A, of 27 March 1990 Index Special Characters * (indicates executable), 26 . (current directory), 14 . . (parent directory), 14, 19, 21 / (indicates directory), 26 / (pathname separator), 10 / (root directory), 10 < input redirection symbol, 75 = (indicates AFJJNIX socket), 26 > output redirection symbol, 74 > ! (overwrite file), 75 >& redirect standard output and standard error, 79 » append output, 75 »& append standard output and standard error, 79 @ (indicates link), 26 [ and ] , 73 \ ! * (alias argument designator), 86 \ ! n (alias argument designator), 86 { and } , 73 | pipe symbol , 76 | & send diagnostic output through pipe, 79 ' (home directory), 14, 19, 24 A abbreviation AFJJNIX socket (=), 26 current directory (.), 14 directory (/), 26 executable (*), 26 home directory ('), 14, 19, 24 multiple filename characters (*), 28 parent directory (..), 14, 19, 21 pathname separator (/), 10 root directory (/), 10 single filename character (?), 29 table of basic, 18 absolute pathname, 11, 22, 24 account, 5 alias, 85 thru 88 argument designators, 86 escaping, 87 making global, 87 making permanent, 87 remote, 108 removing, 88 seeing current aliases, 87 alias, continued substitution, 85 alias command, 85 seeing current aliases, 87 argument definition, 72 quotation marks, 93, 95 ARPANET, 100 at command, 90 atq command, 91 atrm command, 91 B background definition, 88 running processes in, 88, 104 batch command, 91 bg command (C shell only), 89 brackets, pattern matching, 73 c C shell [ and ] , 73 { and } , 73 and alias substitution, 85 and command repetition, 82 and command substitution, 81 and command-line editing, 81 and . cshrc file, 74, 81, 83, 87 and filters, 76 and history substitution, 81 and kernel, 71 and long command line, 74 and processes, 83 appending to file, 75 arguments, 72 backgrounding commands, 88 brackets, pattern matching, 73 cmdtool command, 72 command line, 72 definition, 71 dirs command, 23 history command, 81 history variable, 81 job control, 88 matching filenames, 73 noclobber variable, 74 - 179 - Index — Continued C shell, continued. options, 73 overriding no clobber, 75 pattern matching, braces, 73 pattern matching, ranges, 73 patterns and filename substitution, 73 pipes and pipelines, 76 popd command, 23 prompt variable, 83 pushd command, 23 redirecting standard error, 79 redirecting standard input, 75 redirecting standard output, 74 redirecting standard output with backquotes, 80 separating commands, 73 separating standard error fron standard output, 79 shelltool command, 72 source command, 74 standard error, 79 standard input, 74 standard output, 74 starting, 72 stopped jobs warning, 89 string, pattern matching, 73 wild card characters, 73 campus area network, 97 can, 97 cat command, 29, 34 and redirection, 81 show invisible characters with -v, 78 cd command, 18 changing directories, 18 changing file ownership, 42 changing file permissions, 40 character *,26 .,14 ..,14 /, 10, 26 ?, 29 *, 14 asterisk, 26 asterisk wild card, 28, 73, 93 dot, 14 escaping, 95 line kill, 2 period, 14 question mark wild card, 28, 29, 73 showing invisible with cat -v, 78 slash, 10, 26 tilde, 14 two dots, 14 wild card, 28, 73, 93 chess game, 11 chfn command, 157 chmod command, 40 chown command, 42 cmdtool command, 72 command alias, 85 and command-line editing, 81 argument, 72 command continued argument as standard input, 75 at, 90 atq, 91 atrm, 91 batch, 91 bg (C shell only), 89 cat, 29, 34, 81 cd, 18 chfn, 157 chmod, 40 chown, 42 cmdtool, 72 cp, 30, 31 date, 76 dirs (C shell only), 23 f g (C shell only), 89 file, 26 filters, 76 finger, 107 fmt, 78 from, 155 grep, 77, 78, 85, 91 thru 95 groups, 42 head, 77 history, 81 jobs, 88 kill, 85 lpq, 36 lpr, 35, 36 lprm, 36 Is, 25 thru 28, 43 1 s -a, 25 Is -F, 26 Is -1,27,37,38,42 Is -Id, 28 Is -lg, 42 mkdir, 23 more, 29, 77 mv, 33 ping, 106 pipes and pipelines, 76 popd (C shell only), 23 pr, 78 ps, 83 pushd (C shell only), 23 pwd, 19 rep, 32, 33 rev, 78 rlogin, 101 rm, 34 rm -i, 34 rm -ir, 25 rm -r, 24 rmdir, 24 rsh, 108 running in background, 88 running later with at, 90, 91 rup, 106 rusers, 107 sed, 78 shelltool, 72 sort, 78 source, 74 180 - Index — Continued command, continued spell, 78 standard input, 74 standard output, 74 tail, 77 umask, 41 unalias, 88 uptime, 106 users, 107 w, 107 wc, 76 who, 107 command argument definition, 72 command execution on another machine, 108 command line analysis of, 72 continuing, 74 editing, 81 command option definition, 73 command prompt, 7 command repetition, 82 command substitution, 81 command-line editing, 81 contents of a directory, listing, 25 thru 28 control keys Ctrl-D, 8 table, 3 copying files and directories, 30 thru 33 different machines, 32 same machine, 30 copying filesystems different machines, 33 same machine, 31 cp command, 30 -r, 31 creating files, 34 creating new directories, 23 .cshrcfile.74,81,83, 87,108 current directory, 32 finding out what is, 19 D daemon, definition of, 98, 108 date command, 76 default permissions, 41 Defaults Editor, 168 defaultsedit command, 168 Defense Data Network, 100 /dev/null what is, 9 device what is, 9 directory . (current), 14 .. (parent), 14, 21 " (home), 14 above and below, 1 1 changing, 18 child, 11 directory, continued copying, 30 thru 33 creating, 23 current, 19, 32 definition, 9 home, 14, 19, 24 information on (1 s -Id), 28 listing contents, 25 moving to and from, 18 moving to home, 18 parent, 11, 21 removing (empty), 24 removing (non-empty), 24 removing safely (non-empty), 25 vs. files, 9 working, 19, 32 dirs command, 23 display first n lines of a file (head command), 77 displaying invisible characters with cat -v, 78 E escaping an alias with "",87 with \, 87 /etc/aliases file mail aliases, 164 executable file, what is, 9 executing commands on another machine, 108 F f g command (C shell only), 89 file, 9 appending to, 75 basic commands, 17 thru 43 basic concepts, 9 thru 15 basic manipulation commands, table of, 18 cat command, 29, 34 copying, 30 thru 33 core, 3 .cshrc,74, 81, 83, 87, 108 definition, 9 /dev/null, 9 /dev/tty (name of terminal), 79 different kinds of, 9 /etc/aliases, 164 executable, 9 executable, what is, 9 .exrc, 61 . forward, 156 group ownership, 42 hidden, 25 kinds of, 9 links, 43 • mailrc, 127, 149, 163, 164, 166, 167 thru 111 Mailrc sample .mailrc, 167 manipulating, 17 thru 43 more command, 29 moving, 33 ownership, 27, 42 permissions, 27, 37 printing, 35 thru 37 removing, 34 removing (safely), 34 - 181 - Index — Continued file, continued renaming, 33 seeing hidden, 25 seeing types with file, 26 seeing types with Is -1,26 size, 27 SunOS hierarchy, 14 system wastebasket, 79 transforming with filters, 76 vs. directories, 9 file command, 26 filesystem, 99 copying (different machines), 33 copying (same machine), 31 definition, 12 filters, definition of, 76 finding out current directory (pwd), 19 finger command, 107 fmt command, 78 foreground running processes in, 88 formatting files for printing with pr, 78 formatting text with fmt, 78 formatting text with nrof f , 65 thru 69 sample memo, 65 formatting text with trof f , 65 thru 69 sample memo, 65 . forward file, 156 from command, 155 G gateway, 99 getting rid of directories, 24 grep command, 77, 78, 85, 91 thru 95 and regular expressions, 93 as filter, 92 complement search, 93 problems, 93 search more than one file, 93 -v option, 93 with argument quotes, 93 with multi-word string, 93 group examples of, 42 file ownership (Is -lg), 42 finding which you belong to, 42 what is, 42 group ID file ownership (Is -lg), 42 groups command, 42 H head command, 77 hidden files, 25 hierarchy home directory, 19 illustration of, 10 moving laterally, 21 moving up, 21 parent directory, 21 SunOS operating system, 14 history C shell variable, 81 history command, 81 history substitution and aliases, 85 and the C shell, 81 home directory, 14, 19, 24 moving to, 18 hostname, 5 I I/O, input/output, 76 Internet, 99 mail over, 161 internetwork, 97 internetwork protocol, 99 interpretation history substitution, 81 invisible characters displaying with cat -v, 78 J job control background, 88 foreground, 88 stopped job, 88 stopped jobs warning, 89 job number, 104 jobs command, 88 K key backspace, 2 control, 2, 8 delete, 2 escape, 3 meta-keys, 3 return, 1, 6 rub out, 2 shift, 2 space bar, 2 tab, 2 keyboard illustration, 1 kill command, 85 L LAN, 97 links, 27,43 listing contents of a directory, 25 thru 28 In command, 43 load average, 106 local area network, 97 local network, 99 login, 5 thru 7 incorrect, 6 information, 6 prompt, 5 system message, 116 . login file, 114, 115 logout, 8 Ctrl-D, 8 problems, 8 182 - Index — Continued lpq command, 36 lpr command, 35 -h, 36 -P, 35 -t, 35 and pr command, 78 lprm command, 36 Is command, 25 thru 28 -a, 25 -F, 26 “F (*), 26 -F (/), 26 -F (=), 26 -F (@), 26 -1, 27, 37, 38, 42 -Id, 28 -lg, 42 M machine name, 5 mail, 139 thru 153, see also mail variables ? command, 151 addressing a letter, 140, 141, 145 aliases, 163 thru 166 aliases in /etc/aliases, 164 aliases in .mailrc, 163 thru 164, 166 and Mail Tool, 139 and vi, 151 Bcc:, 145 blind carbon copies, 145 ■ c command, 145, 149 canceling a letter, 145 carbon copies, 145 Cc : , 145 changing name in outgoing mail, 157 chf n command, 157 command tables, 151 thru 153 composing a letter, 140 Ctrl-C, 145 Ctrl-D, 140, 145, 151 copying a letter into file, 149 copying a letter into folder, 149 thru 150 copying vs. saving, 148 current letter, 142, 143 d command, 143 Date:, 143 defaults, 149 defined, 139 deleted letter, 142 deleting a letter, 143 folder directory, 149 thru 150 folders, 149 thru 150 . forward file, 156 forwarding a letter, 156 From:, 143 from command, 155 ~h command, 145 header, 141, 143, 145, 148 help, 142, 151 thru 153 incoming mail, 156 inserting a file, 147 inserting a letter, 146 thru 147 Internet, 161 mail, continued letter number, 141, 142, 143 letter status, 142 ~m command, 146, 148 mail command, 139, 145 mailbox, 141, 142, 144, 148 .mailrc file, 149 mbox file, 142 Message-Id:, 143 modifying, 143, 145, 149 name, changing in outgoing mail, 157 new letter, 142 notification of, 142 options, 143, 145, 149 “p command, 146 printing a letter, 144 q command, 142, 144 quitting vi, 151 quitting with q command, 142, 144 quitting with x command, 144 r command, 148 ' r command, 147 Re: Subject:, 148 reading a letter, 140, 142 thru 144 reading a letter in file, 150 reading a letter in folder, 150 Received:, 143 remote networks, 159 thru 161 replying to a letter, 148 replying with vacation, 155 retrieving a letter, 148 thru 150 Return-Path:, 143 s command, 148, 149 saving a letter, 148 thru 150 saving a letter into file, 148 saving a letter into folder, 149 thru 150 saving a letter with . forward, 156 selecting a letter, 143 sender, 155 sender of letter, 143 sending a letter, 139, 140, 141, 145, 151 sending a letter to file or folder, 150 set folder variable, 149 size of letter, 143 starting, 139 starting vi, 151 status, 142 Subject:, 140, 143, 145, 151 subject of letter, 143 suppressing header, 143 tilde commands, 151 tilde escapes, 151 time letter sent, 143 To:, 143, 145 u command, 144 undeleting a letter, 144 unread letter, 142 UUCP network, 159 thru 161 ~v command, 151 vacation program, 155 variables, 143, 145, 149, see also mail variables viewing inserted letter, 146 writing a letter, 140 x command, 144 - 183 - Index — Continued Mail Tool, 117 thru 137, see also Mail Tool variables active letter, 124 address template, 135 addressing a letter, 129 aliases, 163 thru 166 aliases in /etc/aliases, 164 aliases in .mailrc, 163 thru 164, 166 alwaysusepopup variable, 129 and mail, 117 askbcc variable, 129 background, running in, 1 17 Bcc:, 129 Cancel button, 129, 134 canceling a letter, 134 Cc:, 129 changing directories in, 128 changing name in outgoing mail, 157 chfn command, 157 clearing composition window, 135 closed form, 118 closing, 136 closing composition window, 135 command panel window, 121 committing changes, 123, 128, 136 Compose button, 122, 129, 133, 135 composing a letter, 129 composition window, 122, 129 thru 136 copying a letter into file, 126 copying vs. saving, 126 current letter, 124 date, 121 Defaults Editor, 117, 123, 124, 126, 127, 129 Delete button, 128 deleting a letter, 128 Deliver button, 129, 134 delivering a letter, 134 Disappear button, 135 displaying a letter, 124 Done button, 127, 136 expert variable, 135 fields, 129 File:, 126, 127 Folder button, 127 folder directory, 127 thru 128 folders, 119, 124, 127 thru 128 . forward file, 156 forwarding a letter, 130, 156 from command, 155 header, 120, 124 header list, 124 header list window, 120, 124 iconic form, 118, 123 ignoring header lines, 124 Include button, 129, 130, 131 including a file, 133 including a letter, 130 incoming mail, 123, 156 Internet, 161 line wrap, 130 mailbox, 120, 128 • mailrc file, 117, 127, 137 menus, 123 message number, 121 message window, 121 Mail Tool, continued Misc button, 127, 128, 137 mouse buttons, 123 name, changing in outgoing mail, 157 new mail, 121, 123 New Mail button, 124, 127, 136 Next button, 124 open form, 118 options, 126, 127, 129, 135, 137 pop-up composition window, 135 Print button, 126 printing a letter, 126 printmail variable, 126 pushing a button, 121, 123 quitting, 136 thru 137 Re-address button, 129, 135 re-addressing composition window, 135 reading a letter, 124 thru 126 reading a letter in file, 127 reading a letter in folder, 127 reading mail, 123 thru 128 receiving mail, 123 thru 128 remote networks, 159 thru 161 Reply button, 122, 130, 133 replying to a letter, 130 replying with vacation, 155 retrieving a letter, 127 reusing composition window, 135 Save button, 126 saving a letter, 126 thru 128 saving a letter into file, 126 saving a letter into folder, 127 saving a letter with . forward, 156 selecting a letter, 124 sender, 121, 155 sending a letter, 134 sending a letter to a file or folder, 129 set folder variable, 127 Show button, 124 starting Mail Tool, 117 status indicators, 121 Subject :, 129 sub windows, 120 thru 123 SunView, 117, 121 suppressing header information, 124 Text Edit, 130, 133 time, 121 To:, 129 turning confirmations off, 135 undeleting a letter, 128, 136 unread letter, 121 UUCP network, 159 thru 161 vacation program, 155 variables, 126, 127, 129, 135, 137, see also Mad Tool vari- ables word-wrap, 130 writing a letter, 129 Mail Tool variables add letters to beginning of mbox, 172 addresses given relative to yours, 174 allnet, 172 allowreversescan, 170 alwaysignore, 172 alwaysusepopup, 170 184 - Index — Continued Mail Tool variables, continued append, 172 ask, 172 askbcc, 170 askcc, 172 asksub, 172 automatic blind carbon copy prompt, 170 automatic carbon copy prompt, 172 automatic subject prompt, 172 autoprint, 172 Bcc:, 170 beeps upon mail arrival, 170 bell, 170, 171 composition window proportion of message window, 171 composition window size, 172 confirm edits in message window, 170 DEAD, 172 Defaults Editor, 168 designate folder directory, 172 designate mailbox file, 173 designate yourself as recipient, 173 disable confirmations, 170 disablefields, 170 display folder directory, 173 display letter recipient, 174 display next letter, 172 editmessagwindow, 170 expert, 170 filemenu, 171 f ilemenusize, 171 flashes upon mail arrival, 171 folder, 169, 172 frequency of checking new mail, 171 header list window size, 171 headerlines, 171 hold, 173 ignore Ctrl-C, 172 indent included letters, 173 indentpref ix, 173 interval, 171 keep, 173 keep letters in mailbox, 173 keep mailbox, 173 keepsave, 173 letter record file, 174 letter record in folder directory, 174 LISTER, 173 maillines, 172 .mailrc file, 167 thru 177 Mailrc sample .mailrc file, 167 MBOX, 173 message window size, 172 metoo, 173 moveinputfocus, 171 msgpercent, 171 onehop, 174 outfolder, 174 popuplines, 172 printmail, 171 record, 174 remove address fields, 170 replyall, 174 retain saved letters in mailbox, 173 reverse reply commands, 174 Mail Tool variables, continued save, 174 sendmail, 174 separate composition window, 170 set printing command, 171 set prompt in composition window, 171 setting File : menu, 171 setting variables, 169 showto, 174 size of File: menu, 171 specify mail delivery program, 174 store deleted letters, 171 store interrupted letters, 172, 174 suppressing header information, 177 trash, 171 treat network names identical to usernames, 172 mail variables ! as a special case in vi, 174 add letters to beginning of mbox, 172 addresses given relative to yours, 174 allnet, 172 alwaysignore, 172 append, 172 ask, 172 askcc, 172 asksub, 172 automatic carbon copy prompt, 172 automatic subject prompt, 172 autoprint, 172 bang, 174 change mail escape character, 175 cmd, 175 conv, 175 convert uucp addresses, 175 crt, 175, 176 DEAD, 172, 174 default shell command for pipe, 175 Defaults Editor, 1 68 designate folder directory, 172 designate mailbox file, 173 designate special signature, 176 designate yourself as recipient, 173 display crt number of lines, 175 display folder directory, 173 display letter recipient, 174 display long letters, 176 display next letter, 172 dot, 175 edit mail headers with editheaders, 175 editheaders, 175 EDITOR, 175 escape, 175 folder, 169, 172, 174 header, 175 hold, 172, 173 ignore, 175 ignore Ctrl-C, 172, 175 ignoreeof, 175 indent included letters, 173 indentpref ix, 173 insert form feeds, 176 keep, 173 keep letters in mailbox, 173 keep mailbox, 173 - 185 - Index — Continued mail variables, continued keepsave, 173 letter record file, 174 letter record in folder directory, 174 LISTER, 173 .mailrc file, 167 thru 177 Mailrc sample . mailrc file, 167 MBOX, 172, 173 metoo, 173 number of header summaries displayed, 176 number of lines displayed, 176 onehop, 174 outfolder, 174 page, 176 PAGER, 175, 176 prompt, 176 quiet, 176 record, 174 replyall, 174 retain saved letters in mailbox, 173 reverse reply commands, 174 save, 172, 174 screen, 176 sendmail, 174 sendwait, 176 set command interpreter, 176 set editor, 175 set mail prompt, 176 set verbose option, 176 setting variables, 169 SHELL, 176 showto, 174 sign, 176 specify mail delivery program, 174 specify screen editor, 176 store interrupted letters, 172, 174 suppress display of first letter, 176 suppressing header information, 177 terminate letters with dot, 175 toplines, 176 treat network names identical to usernames, 172 turn off header list display, 175 verbose, 176 VISUAL, 176 waits to return prompt, 176 • mailrc file, 127, 149, 167 thru 111 aliases, 163 thru 164, 166 Mailrc sample .mailrc file, 167 making new directories, 23 making new files, 34 matching filenames, 73 mesg command, 114, 115 message of the day, 6, 116 messages. 111 thru 116 talk, 111 wall, 115 broadcast, 115 interactive, 111 non-interactive, 114 prevent appearance, 114, 115 system, 116 to everyone, 1 15 types of. 111 messages, continued write, 114 MILNET, 100 mkdir command, 23 more command, 29, 77 mounting remote filesystems, 99 moving files, 33 moving to new directory, 18 mv command, 33 N network, 99 ARPANET, 100 common problems, 108 Defense Data Network, 100 definition, 99 error notifications, 108 Internet, 99 internetwork protocol, 99 local, 99 MILNET, 100 protocol, 99 remote, 99, 100 remote login, 101 UUCP, 100 network error notification, 108 Address already in use, 109 Connection refused, 109 Connection timed out, 109 File not found, 109 Host name for your address unknown, 109 Login incorrect, 109 Network is unreachable, 109 NFS server not responding still trying, 109 No such file or directory, 109 Permission denied, 109 RPC: Timed out, 109 RPC: Unable to receive, 109 RPC: Unable to send, 109 RPC_PMAP_FAILURE, 109 RPC_UNKNOWNHOST, 109 unknown host, 109 Network File System, 97 Network Information Service, 100 new directory making, 23 moving to, 18 new mail system message, 116 NFS, 97 NIS, 100 noclobber C shell variable, 74 overriding, 75 nroff program, 65 thru 69 . B command, 68 . br command, 68 . ce command, 68 centering text, 68 . I command, 68 . IP command, 68 itemized paragraphs, 68 left-justified paragraphs, 68 - 186 - Index — Continued nrof f program, continued line breaks, 68 line-spacing, 68 . LP command, 68 macro package, 67 macros, 67 -ms, 67 primitives, 67 printing files, 68 printing formatted file, 69 running, 68 sample memo, 65 . sp command, 68 strike-over text, 68 . UL command, 68 underlining text, 68 o option definition, 73 ownership, 27 changing, 27 P parent directory, 21 passwd command, 7 password, 5 thru 8 aging, 8 change, 7 problems, 7 prompt, 6 security, 7 short, 7 pathname absolute, 11, 22, 24 definition, 11 relative, 11, 12, 21, 24 pattern matching braces, 73 ranges, 73 patterns and filename substitution, 73 permissions, 27 changing, 40 default, 41 setting, 40 PID, 83 ping command, 106 pipes and pipelines, 76 popd command, 23 pr command, 78 print working directory (pwd), 19 printing files, 35 thru 37 checking printer queue, 36 nroff /trof f output, 35 pr command, 78 removing print jobs, 36 to different printer, 35 without header pages, 36 process, 83 process identification number, 83 process, explanation of, 105 program running later with at command, 91 prompt C shell variable, 83 protocol, 99 ps command, 83 pushd command, 23 pwd command, 19 Q quotation marks around arguments, 93 R r (indicates readable directory), 39 r (indicates readable file), 39 ranges, pattern matching, 73 rep command, 32 -r, 33 from your machine, 32 to your machine, 32 redirection filters, 76 pipes and pipelines, 76 standard error, 79 standard error only, 79 standard input, 74, 75 standard output, 74 standard output with backquotes, 80 regular expressions and grep command, 93 relative pathname, 11, 12, 21, 24 remote aliases, 108 remote command execution, 108 remote daemon, 108 Remote File System, 97 remote load average, 106 remote login, 101 thru 104 aborting a connection, 103 different username, 102 no home directory, 102 non-existent machine, 103 problem, 102, 103 suspending a connection, 104 remote network, 99, 100 remote status information, 106 remote system uptime, 106 remote user information, 107 removing an alias, 88 removing directories, 24 removing empty directories, 24 removing files, 34 safely, 34 removing non-empty directories, 24 safely, 25 removing print jobs, 36 renaming files, 33 return code and the parent process, 83 rev command, 78 reversing characters in a line, 78 RFS, 97 rlogin command, 101 - 187 - Index — Continued r login command, continued -1 option, 102 rm command, 34 -i.34 -ir, 25 -r, 24 rmdir command, 24 rsh command, 108 rup command, 106 rusers command, 107 s searches with grep, 91 thru 95 security password, 7 sed command, 78 separating commands, 73 server, definition of, 98 setting file permissions, 40 shelltool command, 72 show first n lines of a file (head command), 77 show last n lines of a file (tail command), 77 showing invisible characters with cat -v, 78 sort command, 78 source command, 74 spell command, 78 standard error, 79 separating from standard output, 79 standard input, 74 as an argument, 75 pipes, 76 redirecting, 75 standard output, 74 filters, 76 pipes, 76 redirecting, 74 redirecting with backquotes, 80 status information, 106 string definition, 91 explanation of, 77 pattern matching, 73 substitution alias, 85 SunOS file hierarchy, 14 symbolic links, 43 system messages, 116 login, 116 new mail, 116 system uptime, 106 system wastebasket, 79 T tail command, 77 talk command, 111 terminal, 105 terminal, name of (/dev/tty), 79 text formatter (nrof f), 65 thru 69 sample memo, 65 text formatter (troff), 65 thru 69 text formatter (troff), continued sample memo, 65 troff program, 65 thru 69 . B command, 68 boldface text, 68 . br command, 68 . ce command, 68 centering text, 68 . I command, 68 . IP command, 68 italicizing text, 68 itemized paragraphs, 68 left-justified paragraphs, 68 line breaks, 68 line-spacing, 68 . LP command, 68 macro package, 67 macros, 67 -ms, 67 primitives, 67 printing files, 69 running, 69 sample memo, 65 . sp command, 68 . UL command, 68 underlining text, 68 u umask command, 41 unalias command, 88 unaliasing, 88 uptime command, 106 user information, 107 username, 5 users command, 105, 107 UUCP network, 100 mail over, 159 thru 161 V vacation program, 155 vi editor, 45 thru 63 a command, 46, 50, 51 abbreviations in commands, 56 arrow key substitutes, 49 arrow keys, 48 Back Space key, 50 breaking lines, 52 Breton, Andre, 54 buffer, 60 C command, 5 1 canceling search-and-replace, 58 case-sensitive commands, 48 cc command, 51 changing defaults, 61 changing line, 51 changing part of line, 51 changing text, 51 thru 52 changing word, 51 clearing screen, 51 : co command, 55 command mode, 48, 50, 52, 53 command table, 62 copying lines ( : co), 55 - 188 - Index — Continued vi editor, continued copying lines (yank and put), 53 copying text, 53 thru 56 crashing and recovering file, 61 Ctrl-B command, 50 Ctrl-C command, 58 Ctrl-D command, 50 Ctrl-F command, 50 Ctrl-L command, 51 Ctrl-U command, 50 Ctrl-Z command, 61 cursor moving commands, 48 thru 50 cw command, 51 D command, 52 dd command, 52, 53 defaults, 61 deleting character, 52 deleting line, 52 deleting part of line, 52 deleting text, 52 thru 53, 56 deleting word, 52 disinformation, 57 thru 58 dw command, 52 entering text, 46, 50 thru 51 ex editor commands, 61 . exrc file, 61 finding a line, 58 G command, 58 i command, 5 1 input mode, 48, 50 inserting file, 59 inserting text, 46, 50 thru 51 J command, 52 joining lines, 52 last-line mode, 48, 53 line numbers, setting, 54 :m command, 56 modes, 48 moving cursor, 48 thru 50 moving cursor by word, 50 moving cursor down, 50 moving cursor left, 50 moving cursor right, 50 moving cursor to bottom of screen, 50 moving cursor to middle of screen, 50 moving cursor to top of screen, 50 moving in file, 48 thru 50 moving lines (delete and put), 53 moving lines ( : m), 56 moving text, 53 thru 56 n command, 56 newspeak, 58 o command, 51 opening file to line number, 59 opening file to pattern, 59 opening new lines, 51 options, 61 Orwell, George, 54 p command, 53 putting lines, 53 : q command, 48, 60 : q! command, 61 quitting, 48, 60 thru 61 quitting without saving, 60 vi editor, continued r command, 51, 52 recovering file after crash, 61 redrawing screen, 51 repeat factors, 52, 53 repeating commands, 53 replacing character, 51 replacing character string, 58 Return key, 50 s command, 51 saving and quitting, 60 saving work, 47, 60 scrolling, 50 scrolling backward, 50 scrolling down, 50 scrolling forward, 50 scrolling up, 50 searches, special characters in, 57 searching, 56 thru 58 searching and replacing, 58 Space Bar, 50 starting, 45 stopping, 60 thru 61 string, definition, 56 substituting characters, 51 substituting string, 51 substituting text, 51 thru 52 suspending, 61 transposing characters, 52 u command, 52, 56 undo, 52, 56 view program, 45 : w command, 47, 60 : wq command, 60 writing a file, 47 x command, 52 xp command, 52 Y command, 53 yanking lines, 53 yy command, 53 Z Z command, 60 view program, 45 w w (indicates writable directory), 39 w (indicates writable file), 39 w command, 105, 107 wall command, 115 wan, 97 wc command, 76 what kind of file is this? (file), 26 what kind of file is this? (Is -1,26 where am I? (pwd), 19 which directory is this? (pwd), 19 who command, 105, 107 who’s logged in?, 105 wide area network, 97 wild card characters, 28, 73, 93 working directory, 32 finding out what is, 19 write command, 114 - 189 - Index — Continued X x (indicates executable file), 39 x (indicates searchable directory), 39 Y ypbind, 101 ypserv, 101 - 190 - Notes Notes Notes Notes Notes Systems for Open Computing™ Corporate Headquarters Sun Microsystems, Inc. 2550 Garcia Avenue Mountain View, CA 94043 415 960-1300 TLX 37-29639 For U.S. Sales Office locations call: 800 821-4643 In CA: 800 821-4642 European Headquarters Sun Microsystems Europe, Inc. Bagshot Manor, Green Lane Bagshot, Surrey GU19 5NL England 0276 51440 TLX 859017 Australia: (02) 413 2666 Canada: 416 477-6745 France: (1) 40 94 80 00 Germany: (089) 95094-0 Hong Kong: 852 5-8651688 Italy: (39) 6056337 Japan: (03) 221-7021 Korea: 2-7802255 New Zealand: (04) 499 2344 Nordic Countries: +46 (0)8 7647810 PRC: 1-8315568 Singapore: 224 3388 Spain: (1) 2532003 Switzerland: (1) 8289555 The Netherlands: 033 501234 Taiwan: 2-7213257 UK: 0276 62111 Europe, Middle East, and Africa, call European Headquarters: 0276 51440 Elsewhere in the world, call Corporate Headquarters: 415 960-1300 Intercontinental Sales