J SunOS User’s Guide: Customizing Your Environment SunOS User ? s Guide: Customizing Your Environment Sun Workstation and Sun Microsystems are registered trademarks of Sun Microsystems, Inc. SunView, SunOS, and the combination of Sun with a numeric suffix are trade- marks of Sun Microsystems, Inc. UNIX is a registered trademark 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 Overview 1 1.1. The SunOS Environment 1 1.2. Interactive Programs and Setup Files 1 1.3. Installing the Setup Files in Your Home Directory 2 1.4. Setting Up Your Terminal 2 1.5. The File System Hierarchy 5 Chapter 2 The C Shell and the .cshrcFile 7 2.1. Selecting C Shell Features 7 2.2. A Sample .cshrcFile 8 Explanation of Command Lines 12 Chapter 3 The C Shell and the .login File 21 3.1. A Sample . login File 22 Explanation of Command Lines 24 Chapter 4 The C Shell and the .logout File 27 4.1. A Sample .logout File 27 Explanation of Command Lines Lwiit 29 Chapter 5 vi and the . exrc File , 31 5.1. Setting Options While in vi 31 5.2. A Sample . exrc File 32 Explanation of Command Lines 34 — iii — Contents — Continued Chapter 6 Login Access to Other Machines 37 6.1. Trust Amongst Machines on a Network 37 /etc/hosts 37 /etc/hosts . equiv 38 Chapter 7 Mounting Remote Filesystems With NFS 39 7.1. The mount Command 39 7.2. The /etc/f stab File 40 The umount Command 41 7.3. Options to mount and umount 42 7.4. The Automounter 43 7.5. Who’s Mounting This System? showmount 45 Chapter 8 Sharing Files Under RFS 47 8.1. Advertising Resources With adv 47 Displaying Your Advertised Resources 48 8.2. Mounting Remote Filesystems 49 What’s Available? The nsquery Command 49 Unadvertising With unadv 50 The mount Command 50 Displaying the Current Mounts 5 1 Unmounting With umount 51 8.3. The /etc/f stab File 51 Index 53 - iv - Figures Figure 7-1 A Sample f stab File 41 - V - Preface SunOS User’s Guide: Customizing Your Environment describes the setup files for the C shell command interpreter and the interactive editor vi. (See SunOS User’s Guide: Getting Started for tutorials on these topics.) Each of these files is read in automatically by the appropriate program, and contains commands and instructions to set up (or disable) various features of that program. Your environment is — loosely defined — the various options and features that affect how the system or interactive program responds to you. There is a sample of each setup file and a line-by-line explanation of its contents. Culled from a variety of expert users, these files contain some very convenient combinations of features and commands. Most importantly, these samples pro- vide a starting point from which you can begin tailoring the system to your specific needs and style. Chapter 1 is an overview of various setup files and a description of how they are used by the interactive programs. Chapter 2 describes the . cshrc file for the C shell. Chapter 3 describes the . login file for the C shell. Chapter 4 describes the . logout file for the C shell. Chapter 5 describes the . exr c file for vi (and the line editor ex). Online copies of the sample files are located in: .cshrc /usr/lib/Cshrc .login /usr/lib/Login .logout /usr/lib/Logout .exrc /usr/lib/Exrc Other chapters describe how to mount file systems from remote machines with NFS and RFS, and how to use the automounter. — Vll — 1 Overview If you have been using the system for a while, you have probably discovered features that you like and features you would like. The interactive programs that you have used so far have many optional features that you may not know about. This manual describes a number of these features and how to set things up so that you get the features you want automatically. 1.1. The SunOS When working with the system, the interactive program that is currently running Environment on your terminal provides a context in which you do your work. When you first log in, you are said to be “in” the command interpreter or shell. When you change directories, you are said to be “in” a new one. When using the text editor, you are said to be “in” vi. While in the shell, you typically run the commands described in the SunOS Reference Manual. When in vi, you typically use text editing commands to read and modify files, as described in SunOS User’s Guide: Getting Started . While in mail or Mail Tool, you typically use commands to read and dispose of messages, or to compose and post messages. In keeping with this analogy, you can think of the environment as characteristics of the system and the current interactive program that affect the way you work. When you change interactive programs (by running mail for instance), some characteristics, such as the commands that are accepted, also change. Others, such as the current working directory, may not. But most importantly, you usu- ally wish to perform different sorts of tasks, so your expectations about what is a proper response from the system also change. The technical meaning of environ- ment with respect to the SunOS operating system is more restricted: the environment is a body of infor- mation that is inherited from the “parent” of a process (program currently running). For example, the name of the current directory is passed along when you start vi, so it appears that you “stay in the same directory.” For more informa- tion about processes, see SunOS User’s Guide: Doing More. 1.2. Interactive Programs The interactive programs that you use most often, such as the C shell command and Setup Files interpreter, mail, and vi, have a variety of optional settings that affect the way they respond to your commands. Unlike options that you type in on the com- mand line (such as 1 s -1), you typically select interactive features by typing in commands while you are using that program. 1 1 Most interactive commands also have command-line options that you can specify. Refer to the entry for the command of interest in the SunOS Reference Manual for information about its command-line options. 1 Revision A, of 27 March 1990 2 SunOS User’s Guide: Customizing Your Environment To save you time, most interactive programs allow you to put a list of commands (to select features that you normally want in effect) in a setup file in your home directory. Each program reads its setup file(s) automatically and performs the commands it contains. Subsequent chapters present samples of the various setup files for vi and the C shell command interpreter. Each file is described command by command. The . mailrc File . mailrc, a file that modifies the behavior of mail and Mail Tool, is discussed in SunOS User’s Guide: Getting Started . 1.3. Installing the Setup The sample files described in this manual are located in the directory Files in Your Home / usr/lib, and you can copy them to your home directory. But before you do, Directory check to see if there are setup files already present: CAUTION If one or more of these files are present in your home directory, check with your system administrator before you copy the samples. To copy the setup files, type in these commands: (~ venus % cd venus % cp /usr/lib/Cshrc . cshrc venus% cp /usr/lib/Exrc .exrc venus% cp /usr/lib/Login » i login venus % cp /usr/lib/Logout §; logout v i : : » Once copied, you can modify them as you like using vi or any other text editor. These samples have been culled from the setup files of a variety of expert users. They contain many useful features and ideas. Even so, you will want to edit them to suit your own personal needs and tastes, and to remove references to features that you don’t want. Generally speaking, the smaller the setup file is, the faster the program will start up. Underlying all of these considerations is the terminal you are using and its characteristics. As mentioned in SunOS User’s Guide: Getting Started , you can assign terminal functions such as erase and kill (erase the entire line typed in so far) to control keys such as [Dell and [ Back Space I . 2 2 If you are using SunView on the Sun workstation, you can assign commands and functions to the special function keys on the keyboard. See SunView User’s Guide for details. 1.4. Setting Up Your Terminal Revision A, of 27 March 1990 Chapter 1 — Overview 3 The command stty provides you with a means to set up these and other termi- nal characteristics. To find out what your current terminal characteristics are, type in the command: stty everything Or stty -a This gives you a list of all terminal characteristics currently in effect: venus% stty everything speed 9600 baud, 34 rows, 80 columns parent -parodd cs7 ,-|c'3t : opb ; - hup cl : dread local -ignbrk brkint ignpar -parmrk -inpck istrip -inlcr -igncr icrnl -iuclc ixon -ixany -ixoff imaxbel isig iexten icanon -xcase echo echoe echok -echonl -noflsh -tostop echoctl -echoprt echoke opost -olcuc onlcr -ocrnl. -onocr -onlret -of ill -of del erase kill werase rprnt flush Inext susp intr quit stop eof ~U ~W "R "0 IV 1Z / " Y " S/ "Q "D The command stty all displays a shorter list. For now, you can ignore all but the last two lines, 3 which describe terminal-control functions and the keys they are set to. These are described below: erase Erase character. Backspace and erase one character. This is the [Dell key by default on some keyboards. On others, this function is assigned to the ( Back Space 1 key. kill Kill the whole line. Erase the entire command line typed in so far. werase Delete word. Erase the last word typed in (back to a space or tab); usually assigned to ( Ctrl-W 1 . 3 For Manual. more information about the remaining terminal characteristics, refer to stty in the SunOS Reference microsystems Revision A, of 27 March 1990 4 SunOS User’s Guide: Customizing Your Environment rprnt Reprint. Reprint the line typed in so far. This is useful when you type ahead and the prompt gets displayed in the middle of your text. flush Wait for a keystroke. Stops terminal output until you press a key. Inext Literal next-character. Interprets the next (control) character as literal text. This is useful for entering control or escape characters. susp Suspend the program. Temporarily halts execution of the program currently running and puts it in the background. To resume execution of the com- mand, type %. 4 When you type the suspend character, usually ( Ctrl-Z ] . in the middle of a C shell command-line, the shell ignores that line and issues a new prompt. intr Interrupt. Interrupt the program currently running, quit Halt the current program and leave a binary image in a file called core, stop Stop the display. To resume, press 1 Ctrl-0 1 . eof End-of-file. Send the program an end-of-file character. To assign any of these functions to another control key, supply the function, a space, and the circumflex character (~), followed by the new key, as an argu- ments to stty: A question mark has a special meaning to the SunOS operating system; you must escape it with a backslash to make it a simple ? character. This avoids problems trying to type in a key that is already assigned. To assign erase to the I Back Space I key, use the command: stty erase ~h To assign werase to the I Del 1 key, use: stty werase ~\7 To assign kill to the I Esc I key, use: ( 'N venus % stty werase . verius % stty erase *\? venus % v " 4 C shell only. microsystems Revision A, of 27 March 1990 Chapter 1 — Overview 5 stty kill ~ [ Chapter 3 has more information about setting up terminal characteristics. For a description of other terminal characteristics that you can set up, refer to stty in the SunOS Reference Manual. To assign commands to the special function keys on the workstation keyboard, refer to SunView User’s Guide. 1.5. The File System Hierarchy The file system’s directory hierarchy is a part of the “landscape” that you will want to become familiar with. To see an example of a typical SunOS hierarchy, type man hier or look under hier in Section 7 of the SunOS Reference Manual. microsystems Revision A, of 27 March 1990 The C Shell and the . cshrc File The C shell is one of the two command interpreters available on the Sun work- station, and it’s the one that we recommend for interactive use. Whenever you start running the C shell, such as when you log in or open a shelltool or cmdtool, the C shell looks for the . c shr c file in your home directory for its initial instructions. You can include in this file any command that you might ordinarily type on the command line. The name is derived from csh, which is the program that uses it. Setup files ending in rc are read at the time you run the command. The dot at the beginning of the filename indicates that this file is to remain hidden from view when you give the Is command. Setup files are rarely of interest unless you are editing them specifically, and in that case you already know the filename and directory location. (To list hidden files, use the -a option of Is.) 2.1. Selecting C Shell Features While in the C shell, you can use the set command to select the options you would like. For instance, if you want the C shell to prevent you from acciden- tally logging out by typing a I Ctrl-D I . you can set the ignoreeof option (or, technically speaking, variable ): To turn off an option, use the unset command: Some options allow you to supply a specific number or value. For instance, you can use the history variable to select the size of the history list; that is, the number of previous commands to remember: : a;; “ — — 'v venus% set histoxy=40 V - ■ — _ : : ' ^ _ — — : — —J Or you can alter the prompt that the shell displays: #sun Xr microsystems 7 Revision A, of 27 March 1990 8 SunOS User’s Guide: Customizing Your Environment venus % set prompt = "THIS IS A VERY LONG PROMPT | " THIS IS A VERY LONG PROMPT: . ■ / \ 1- i-..' ... • J To see what options are currently in effect, and their values (if any) use the set command with no arguments: f x:? venus % set ' ' . argv fiiiiii ini i iiiii ■ 111 1 1 ; ; cdpafch.Y ( . • / home /s am. /home/sam/bin /usr/sam/src) . : 'cwd. /home/ s am/ eh v; , . . history 5 40 . home yhome/aarnii: ignoreeof nop lobber notify path ... (.: /home/.s.am /homb/s^iri/bin i/iisr/ucb /usr/bin -/join ) prompt • venu s %• : . ‘ • •"shell • /Toi n / csh • . . • "status ' •fe.. : -- v : ..term sun: I . II llll ||||i . | . IIIII • . . | .iisep; .. . sam. . V: ; . . xxxlxj You can find descriptions of all C shell options (predefined variables) under csh in the SunOS Reference Manual. (Or type man csh.) 2.2. A Sample .cshrc The following pages contain an annotated listing of the sample .cshrc file File located in /usr /lib/Cshrc. This is a very large sample file. Many of the commands and features it includes may not pertain to you, and we recommend that you delete those that you don’t want from your copy of the file. A number of commands have been “commented out” by placing a pound sign (#) to their left. The C shell will ignore these commands unless you remove the pound sign character. Commands that are listed but commented out are felt to be interesting and educational, but not necessarily those that a beginner would use. microsystems Revision A, of 27 March 1990 Chapter 2 — The C Shell and the . cshrc File 9 ################################################################# # # .cshrc file # # initial setups for both interactive and noninteractive # C-Shells # ################################################################# # set up search path set lpath = ( ) # add directories for local commands ; set path = ( . ~ "'/bin $lpath /usr/local /usr/ucb /usr/bin /bin) 2 # cd path set led = ( ) # add parents of frequently used directories 3 set cdpath = (.. ~ ~/bin ~/src $lcd) 4 # set this for all shells set noclobber 5 # aliases for all shells alias cd 'cd \!*;echo $cwd' 6 alias cp ' cp -i' 7 alias mv 'mv -i' 8 alias rm ' rm -i' 9 alias pwd 'echo $cwd' 10 #alias del 'rm -i' n #umask 0 02 12 # skip remaining setup if not an interactive shell if ($?USER == 0 || $?prompt == 0) exit 13 # settings for interactive shells set history=40 m set ignoreeof 15 #set notify 16 #set savehist=40 17 #set prompt= TI % " 18 #set prompt= ,! 'hostname '{ 'whoami '} \ ! : 11 19 #set time=100 20 # commands for interactive shells A see Revision A, of 27 March 1990 microsystems 10 SunOS User’s Guide: Customizing Your Environment #date 21 #pwd 22 # other aliases #alias a alias 23 #alias h ' history \!* | head -39 | more' 24 #alias u unalias 25 #alias clear 26 #alias list cat 27 #alias lock lockscreen 28 #alias m more 29 #alias mroe more 30 #alias type more 31 #alias 'echo $cwd' 32 #alias . . 'set dot=$cwd;cd 33 #alias t ' cd $dot ' 34 #alias dir Is 35 #alias pdw 'echo $cwd' 36 #alias la 'Is -a' 37 #alias 11 'Is -la' 38 #alias Is i CO 1 — 1 39 #alias pd dirs 40 #alias po popd 41 #alias PP pushd 42 #alias +w ' chmod go+w' 43 #alias -w ' chmod go-w' 44 #alias X 'chmod +x' 45 #alias j 'jobs -1' 46 #alias bye logout 47 #alias ciao logout 48 #alias adios logout 49 #alias psg 'ps -ax | grep \!* | grep -v grep' 50 #alias punt kill 51 #alias r rlogin 52 #alias run source 53 #alias nms ' tbl \ ! * | nroff -ms | more' # nroff -ms 54 #alias tms ' tbl \ ! * | troff -t -ms >! troff. output &' # troff -ms 55 #alias tpr ' tbl \ ! * | troff -t -ms | lpr -t &' # troff & print 56 m sum microsystems Revision A, of 27 March 1990 Chapter 2 — The C Shell and the . cshr c File 1 1 #alias ppr ' lpr -t \!* &' # print troffed 57 #alias lpl ' lpr -PI' 58 #alias lql ' Ipq -PI' 59 #alias Irl ' Iprm -PI' 60 #alias sd ' screendump | rastrepl | lpr -v & ' 61 #alias edit textedit 62 #alias help man 63 #alias key 'man -k' 64 #alias mkae make 65 microsystems Revision A, of 27 March 1990 12 SunOS User’s Guide: Customizing Your Environment Explanation of Command Lines Line 1 : set lpath = ( ) # add directories for local commands Creates a variable in which to add the pathnames of directories containing local commands. Add the pathnames for any such directories between the parentheses (ask your system administrator for the appropriate names). These directories are incorporated into the path variable in line 2. Line 2: set path = (. ~ '/bin $lpath /usr/local /usr/ucb /usr/bin /bin) Sets the path variable to include the standard directories containing SunOS commands. Line 3: set led = ( ) # add parents of frequently used directories Creates a variable in which to add the pathnames of directories that are parents of those that you often cd to. For instance, if you often cd to /usr/man/manl, put the pathname /usr/man between the parentheses. These directories are added to the cdpath variable in the next line. Line 4: set cdpath = ~ '/bin ~/src $lcd) Sets the cdpath variable. You need not specify pathnames when you cd to directories that are contained in any of those listed. With . . set in your cdpath (as above), if you were in /usr/man/manl and you wanted to cd to /usr/man/catl, you could use the command cd catl to do so. Note that cdpath is followed linearly, so if both ~ /bin and ~/src con- tain a subdirectory called local, and you enter the command cd local, you will change directory to '/bin/ local. Line 5: set noclobber Prevents unintentional overwrite of files when copying cp)( a file onto an already existing file. Also prevents unintentional overwrites of files when you use the > symbol. See SunOS User’s Guide: Doing More for details. Line 6 : alias cd 'cd \!*;echo $cwd' Displays the new directory when you use cd. to change directories. See SunOS User’s Guide: Getting Started for more on aliases. Line 7: alias cp ' cp -i' 4SS' ^ *-* ** microsystems Revision A, of 27 March 1990 Chapter 2 — The C Shell and the . cshrc File 13 Asks for confirmation before overwriting existing files with cp. Line 8: alias mv 'mv -i' Asks for confirmation before overwriting existing files with mv. Line 9: alias rm 'rm -i' Asks for confirmation before removing files. Line 10: alias pwd 'echo $cwd/ A faster way of finding out which directory you’re in than the built-in pwd command. Line 1 1 : #alias del 'rm -i' A name for rm that is familiar to PC users. Line 12: #umask 002 Sets the default permissions mask for new files to allow read and write access to the owner’s group as well as to the owner. Line 13: if ( $?USER ==0|| $?prompt == 0) exit Tests to see whether there is a variable called USER, or a variable called prompt currently set. If neither of them is not set, then the shell is non- interactive, so the C shell doesn’t bother to process the rest of the commands from this file. This saves time running subshells. Line 14: set history=40 The C shell records the last 40 commands typed in. Line 15: set ignoreeof Prevents accidental logouts when you type I Ctrl-D 1 . Line 16: #set notify microsystems Revision A, of 27 March 1990 14 SunOS User’s Guide: Customizing Your Environment Prevents waiting for display of C shell messages. Normally, the C shell waits until just before printing the prompt to print its messages. Commands, however, don’t always wait to print their messages, so setting notify means that all messages will work the same way. Line 17: #set savehist=40 When you log out, the C shell saves the last 40 commands, and uses them as the starting history list for your next session. Line 18: #set prompt="% " An alternate prompt favored by some SunOS wizards. Line 19: #set prompt=" 'hostname '{ 'whoami ' } \ ! : " An alternate prompt favored by some network wizards. This prompt gives the name of the machine, followed by the name of the user, followed by the history number of the command: venus {medici } 22 : Line 20: #set time=100 Display time statistics for commands that take longer than 100 CPU seconds. Line 21: #date Display the date and time when the C shell starts up. Line 22: #pwd Display the working directory when the C shell starts up. Line 23: alias a alias Abbreviate the alias command. Line 24: ialias h 'history \!* | head -39 | more' microsystems Revision A, of 27 March 1990 Chapter 2 — The C Shell and the . cshrc File 15 Abbreviate history, and delete the last line (containing h) from the display. (Assumes that you have the history variable set to 40, as above.) Line 25: #alias u unalias Abbreviate the unalias command. Line 26: talias ~L clear The I Ctrl-L ) character is the character often used to begin a new page or clear the current one. This alias mimics that behavior. Line 27: #alias list cat A name for cat that is familiar to PC users. Line 28: talias lock lockscreen An abbreviation for lockscreen. Line 29: talias m more An abbreviation formore. Line 30: talias mroe more A remedy for “fat fingers” (ie., for mistyping the word “more”). Line 31 : talias type more A name formore that is familiar to PC users. Line 32: talias . 'echo $cwd' An abbreviation for pwd. Line 33 : talias .. 'set dot=$cwd;cd ..' A quick way to change from child directory to parent (and back again with alias on the next line). microsystems Revision A, of 27 March 1990 16 SunOS User’s Guide: Customizing Your Environment Line 34: #alias , 'cd $dot ' A quick way to change back after using the . . alias above. Line 35: #alias dir Is A name for Is that is familiar to PC users. Line 36: #alias pdw 'echo $cwd' For those people who often mistype “pwd.” Has the same effect as the . alias for pwd, above. Line 37: #alias la 'Is -a' Abbreviation for command to list all filenames, including those that begin with a dot ( . ). Line 38: #alias 11 'Is -la' Abbreviation for a command to give a long listing of filenames, including those that begin with a dot. Line 39: #alias Is 'Is -F' This way, Is appends characters on the end of a filename to indicate that file’s type. These characters are / (slash) for directories; * for executable files; @ for symbolic links; and = for AFJJNIX domain sockets. Line 40: #alias pd dirs Abbreviation to display the directory stack maintained by pushd and popd. See SunOS User’s Guide: Getting Started for details. Line 41: #alias po popd Change directories to the one on the top of the stack, and remove its name from the stack. See SunOS User’s Guide: Getting Started . Line 42: Asun microsystems Revision A, of 27 March 1990 Chapter 2 — The C Shell and the . cshrc File 17 #alias pp pushd Change directories, adding the current directory and the destination to the stack. See SunOS User’s Guide: Getting Started . Line 43: talias +w 'chmod go+w' Make a file writable to the group and public. Line 44: #alias -w ' chmod go-w' Make a file unwritable to all but you, the owner. Line 45: #alias x 'chmod +x' Give a file execute permissions for all users. Line 46: #alias j ' jobs -1' Display the list of background jobs. With -1, the j alias also gives the pro- cess id number of the stopped job. Line 47: talias bye logout Another name for logout. Line 48: talias ciao logout An international term for logout. Line 49: talias adios logout The traditional South-of-the-B order way to log out. Line 50: talias psg 'ps -ax | grep * I grep -v grep' Check on the status of a command by its name. See SunOS User’s Guide: Doing More for details. Line 51: microsystems Revision A, of 27 March 1990 1 8 SunOS User’s Guide: Customizing Your Environment #alias punt kill Another name for kill. Line 52: #alias r rlogin Log in to another host machine on the net. See SunOS User’s Guide: Get- ting Started for details. Line 53: #alias run source The source command instructs the C shell to take a file (such as the . cshrc file) as a list of commands to perform. Line 54: #alias nms 'tbl \!* | nroff -ms | more' Format and display a document containing tbl instructions and ms macros on the terminal. For example, to format the file wombat, you would type nms wombat. Line 55: talias tms 'tbl \!* | troff -t -ms >! troff. output &' Format a document using tbl and ms macros, and place the output in a file for later printing. Line 56: #alias tpr 'tbl \!* | troff -t -ms | lpr -t &' Format a document using tbl and ms macros and print it. Line 57: #alias ppr 'lpr -t \!* &' Print a preformatted troff-output file. Line 58: #alias lpl 'lpr -PI' Abbreviation to print on printer #1. See SunOS User’s Guide: Getting Started for details. Line 59: #alias lql ' lpq -PI' microsystems Revision A, of 27 March 1990 Chapter 2 — The C Shell and the . cshrc File 19 Abbreviation to check the queue for printer #1. Line 60: #alias lrl ' lprm -PI' Abbreviation to remove a job or jobs from printer #1. Line 61: #alias sd ' screendump | rastrepl | lpr -v &' Abbreviation to print the contents of the workstation screen. Line 62: #alias edit textedit Abbreviation for the window-system text editor. Line 63: talias help man Another name for the man command. Line 64: #alias key 'man -k' Abbreviation for the man -k command (same as the wha t i s command described in SunOS User’s Guide: Doing More). Line 65 : talias mkae make Useful if you tend to misspell the word “make.” microsystems Revision A, of 27 March 1990 The C Shell and the . login File When you log in, after performing instructions in the . cshr c file, the C shell then performs instructions in the . login file. Subsequent C shells, such as the sheHtool or cmdtool windows, ignore the . login file. Like the . cshrc file, you can include any command that you might type in on the command line. However, we recommend that you use the . login file for initializing remote terminals (for when you log in by phone), starting your win- dow system (when you first log in to the workstation), and setting up special vari- ables called environment variables. Unlike shell variables and aliases, environ- ment variables are passed along to subsequent commands and programs automat- ically. You need not set them up again every time you start a new C shell or run a new program such as vi. Environment variables are useful for storing information that all programs need to know about. For instance, many commands and programs need to know what type of terminal you are using. This information is stored in the term environ- ment variable. Commands that send output to the printer need to know which printer to send their output to. You can use the PRINTER environment variable, to store the name of a printer to use by default. To set an environment variable, use the set env command. This command has two required arguments, the name of the variable, and its value: setenv name value For example: venus % setenv PRINTER lw Although not required, the convention is to use all capitals for names of environ- ment variables (to distinguish them from ordinary shell variables). To see what environment variables are currently in effect, use the printenv command: INun microsystems 21 Revision A, of 27 March 1990 22 SunOS User’s Guide: Customizing Your Environment . . . . .. — - — ; -7 — - — — — : — — : — : • • : venu s% • print 0 : ny • • HC)ME^ /home / sarii . SHELL- /b'in'/csh . PATH-! . : /home/sam: /.home /.sam/biii: : /14s r/Iocal : /usr/.ucb : /usr/biri : /bin ‘ TERM-sun • . . . . • USER-sam . ; ED I.TOR- /u s r /u cb/y i ■ ■■ ■ : 3 PRINTER— lw ; 3:- . WINDOW_PARENT-/dev/winO .. WMGR_ENV_PLACEHOLDER-/ dev/winl WINDOW_ME=/dev/win9 WI NDOW_GFX= s / dev / w in 9 To remove an environment variable, use the unsetenv command: r~~ : ^ • ' 1 N venus % unsetenv PRINTER ! • venus % echo : $PRINTER . : • • . PRINTER VUiUnde f i ned va r i abie v V*'"' •• V. ;• : i-::;.-..::.;:- : ; ; • : J 3.1. A Sample .login File The following pages contain an annotated listing of the sample . login file located in /usr/lib /Login. If you do not plan to log in from a remote ter- minal over the phone, you can delete the lines that pertain to remote terminals. Again, some commands are commented out. And again, we recommend that you delete or comment out commands that do not pertain to you. microsystems Revision A, of 27 March 1990 Chapter 3 — The C Shell and the . login File 23 ################################################################## # # .login file # # Read in after the .cshrc file when you log in. # Not read in for subsequent shells. For setting up # terminal and global environment characteristics. # ################################################################## # terminal characteristics for remote terminals: # Leave lines for all but your remote terminal commented # out (or add a new line if your terminal does not appear) . if ( $TERM ! = "sun" ) then l #eval 'tset -sQ -m dialup: ?925 -m switch: ?925 -m dumb: 7925 $TERM' 2 #eval 'tset -sQ -m dialup: ?hl9 -m switch :?hl9 -m dumb:?hl9 $TERM' 3 #eval 'tset -sQ -m dialup :?mac -m switch :?mac -m dumb:?mac $TERM' 4 #eval 'tset -sQ -m dialup : ?vtl00 -m switch : ?vt 100 -m dumb:?vtl00 $TERM' 5 #eval 'tset -sQ -m dialup : ?wyse-nk -m switch : ?wyse-nk -m dumb : ?wyse-nk $TERM ' 6 #eval 'tset -sQ -m dialup : ?wyse-vp -m switch : ?wyse~vp -m dumb : ?wyse-vp $TERM' 7 endif 8 # general terminal characteristics #stty -crterase 9 #stty -tabs 10 #stty crt ll #stty erase ' ~h r 12 #stty werase / "? /r 13 #stty kill ' ~ 14 #stty new 15 # environment variables #setenv EXINIT ' set sh=/bin/csh sw=4 ai report=2' 16 setenv MORE ' -c r 17 #setenv PRINTER lw 18 # commands to perform at login #W 19 if ( n 'tty' 11 != "/dev/console”) exit 20 echo -n "SunView? ("C to interrupt) " 21 sleep 5 22 sunview 23 4® sue microsystems Revision A, of 27 March 1990 24 SunOS User’s Guide: Customizing Your Environment Explanation of Command Line 1: T i nes if ( $TERM != "sun") then Perform the commands between this line and the endif line only when log- ging in on a terminal, rather than a Sun workstation. Line 2: #eval 'tset -sQ -m dialup:? 925 -m switch:? 925 -m dumb:? 925 $TERM' If logging in over a phone line, or some other remote means, set up terminal characteristics for a Televideo 925 terminal and place these characteristics in the environment for faster startup of interactive programs. Asks if terminal type 925 is correct by prompting you with TERM 925 Pressing [ Return 1 accepts the 925 as the terminal type; or you can enter another terminal type (from /etc/termcap). Refer to tset in the SunOS Reference Manual for more information. All of the lines pertaining to specific types are commented out. To activate the line that pertains to your terminal, remove the pound-sign. If your termi- nal does not appear, duplicate this line, change the 92 5 to the name of your terminal (see your system administrator for this information) and remove the pound sign. Line 3: #eval 'tset -sQ -m dialup :?hl 9 -m switch :?hl 9 -m dumb:?hl9 $TERM' Set up terminal characteristics for a Heathkit H19 terminal. Line 4: teval 'tset -sQ -m dialup :?mac -m switch :?mac -m dumb:?mac $TERM' Set up terminal characteristics for a Macintosh running Macterminal. Line 5: #eval 'tset -sQ -m dialup: ?vtl00 -m switch : ?vtl00 -m durnb:?vtlOO $TEEM' Set up terminal characteristics for a VT100 terminal. Line 6: #eval 'tset -sQ -m dialup: ?wyse-nk -m switch : ?wyse-nk -m dumb : ?wyse-nk $TERM' Set up terminal characteristics for a Wyse 50 terminal. Line 7: #eval 'tset -sQ -m dialup : ?wyse-vp -m switch : ?wyse-vp -m dumb : ?wyse-vp $TERM' &sun Xr microsystems Revision A, of 27 March 1990 Chapter 3 — The C Shell and the . login File 25 Set up terminal characteristics for a Wyse 50 in ADDS Viewpoint mode with “enhance” turned on. Line 8: endif Marks last line to be skipped when an if ... then statement is found to be false; in this case, when logging in to a Sun workstation directly (or from another Sun on the network). Line 9: #stty -crterase Set up the erase function to backspace without blotting out erased characters. Erased characters remain visible on the screen until you overwrite them with new ones, but are not transmitted to the C shell when you press [ Return 1 . Line 10: #stty -tabs Convert tabs to spaces when displayed on the screen. Line 11: #stty crt Set up standard CRT characteristics. Line 12: #stty erase ' 'h' Set the erase character to [ Back Space 1 . Note that with stty, control char- acters are indicated by the two-character symbol circumflex-character. ~ c . Line 13: #stty werase ' *?' Set the erase- word character to I Del 1 . Line 14: #stty kill ' “ [ ' Set line-kill character to I Esc 1 . Do not use this option if you use the vi edi- tor. vi interprets an [Esc I as “change from insert mode to command mode.” Line 15: #stty new Use the new version of the terminal driver. microsystems Revision A, of 27 March 1990 26 SunOS User’s Guide: Customizing Your Environment Line 16: tsetenv EXINIT 'set sh=/bin/csh sw=4 ai report=2' Another way to set up options for vi. vi recognizes the EXINIT variable as a startup command. If this variable is undefined, vi checks for startup commands in ~ / . exrc. However, if an exrc file exists in the current directory, vi takes its startup commands from this file, ignoring both ~ / . exrc and EXINIT. Line 17: setenv MORE '-c' Sets up more to overwrite the screen, rather than scrolling. Line 18: tsetenv PRINTER lw Indicate which printer is to receive jobs by default. Line 19: #w # see who is logged in See who is logged in on your system. Line 20: if ("'tty'" != "/dev/console") exit If the terminal is not your workstation console (the workstation when not running the window system), then stop further processing of this file. Line 21: echo -n "Sunview? ('C to interrupt) " Warn you that SunView is about to start. Line 22: sleep 5 Wait 5 seconds before starting SunView, to give you a chance to press I Ctrl-C I . Line 23: sunview Start the SunView window system. microsystems Revision A, of 27 March 1990 The C Shell and the . logout File When you log out completely (not just from a single window), the C shell per- forms instructions in the . logout file. This file is useful for running house- keeping type commands in the background while you are away. Like . cshrc and . login you can include any command that you might type in on the C shell command line. We recommend that you use this file only for displaying information about the session just ending that you want to know about and for running background commands. You should not put commands that run interactively in this file, nor should you include commands that take any significant amount of time unless the command runs in the background. Other- wise, someone may be able to interrupt the command and gain unauthorized access to your workstation or terminal. 4.1. A Sample . logout The following pages contain an annotated listing of the sample . logout file File located in /usr/lib/Logout. Some commands are commented out, and we recommend that you delete commands that do not pertain to you. #sun microsystems 27 Revision A, of 27 March 1990 28 SunOS User’s Guide: Customizing Your Environment ############################################################ # # .logout file # # Read in when you exit from the login shell. # For performing housekeeping while your are away. # ############################################################ clear ^ #echo "'hostname': 'whoami' logged out at 'date'" 2 #echo "Goodbye\!" 3 #if (-e /usr/games/f ortune) /usr/games/f ortune -a 4 #if (-r /etc/motd) cat /etc/motd 5 #unalias rm <5 #nice find ~ ' (' -name core -o -name '*.BAK' -o -name '^.CKP' \ 7 # -o -name '#*' -o -name junk ')' \ # -atime +3 -mtime +3 -user $USER -type f -exec \rm '{}' \; & microsystems Revision A, of 27 March 1990 Chapter 4 — The C Shell and the . logout File 29 Explanation of Command Lines Line 1: clear Clears the terminal screen. Line 2: #echo "'hostname': 'whoami' logged out at 'date'" Displays the name of the host machine, your user name, and the date and time you logged out. Line 3: #echo "Goodbye \ ! " A more traditional parting wish. Line 4: #if (-e /usr/games/fortune) /usr / games / fortune -a If the fortune command is available, use it to display one of many humorous sayings. Line 5: #if (-r /etc/motd) cat /etc/motd If the message of the day is readable, display it. Line 6: #unalias rm If you used alias to change the rm command in some way, this resets it to its original, default value. Line 7: #nice find ~ ' (' -name core -o -name ' * . BAK' -o -name '*.CKP' \ # -o -name '#*' -o -name junk ')' \ # -atime +3 -mtime +3 -user $USER -type f -exec \rm '{}' Run find at low priority in the background, starting with your home direc- tory. Look for files named core, * . BAK, * . CKP, ' #*' or junk. Of these, select only those that are at least 3 days old, haven’t been modified for at least 3 days, belong to you, and are regular files (not directories). Remove each file selected, escaping any aliases that might be applied to rm. To activate this command, you need to delete the first pound sign in all three lines. microsystems Revision A, of 27 March 1990 5 Whenever you run vi, the editor looks in the . exr c file for initial commands and option settings. The vi editor has a number of options that are described in detail in Editing Text Files, vi has a : set command with which you select the editing options that you want, but you cannot use it to create new variables, as you can with the C shell’s set command. 5.1. Setting Options While To see the list of options that are currently in effect, type in : set with no argu- in vi ments: To see the list of current and possible settings, use the : set all command: frsun Nr microsystems 31 Revision A, of 27 March 1990 32 SunOS User’s Guide: Customizing Your Environment f " ... “ : : — ; \ auto.indent 1 1 •open . . . tabstop-8 autoprint nooptimize taglength^O noautowrlte prompt;.’ • %. tag stack / beautify ::; noreadonly term=sun directory-/tmp redraw • y rioter se'' :V noedcompatible y remap timeout noer r o rbell s ' report =5 ttytype=sun hardtabs=8 • sc roil =16 warn no igno recase . shel l^/biin/c'shi 1 : : windQW«3’3 nolisp \ shif twidth=8 ' wraps cari; : . nolist Vx. ' ho s howmat ch . • ' wrapmar gin* 3 8' : ' . magic noslowopen .. . ' riowrit'eany nohurnbe.r ‘ •[Hit return to continue |;i ; : v • ) To select a specific option or options, include them as arguments to the : set command. Note that for options having values, there are no spaces between the name, the equal-sign, and the value for that option. To turn off an option, add the prefix no to the name of that option as an argu- ment to : set. ( : : ■ • ,, ■■ \ :set jautoindehti beautify nomesq, number redra w.vterm^sun wrapma rqin=8 1 ■ . r ;set noautoindent ' : set [beautify nomesq number'’ redra w terrr.=sun wrapnarqin=8| l To change the value of a setting such as wrapmargin, use set to establish a new value: :set wrapmargin=0 (This has the effect of eliminating automatic wrapping at the end of the line). 5.2. A Sample . exrc File The following page contains an annotated listing of the sample . exrc file located in /usr/ lib /Exrc. vi does not accept comments in the same way as the C shell: lines in . exrc files are commented out with double quotes (") instead of with pound signs (#). Asun microsystems Revision A, of 27 March 1990 Chapter 5 — vi and the . exrc File 33 IT set autoindent l set autoprint 2 set noignorecase 3 set nomesg 4 set noslowopen 5 set noterse 6 set nonumber 7 IT set report=2 8 set tabstop=8 9 set wrapmargin=8 10 'map / : ll f map g • 9- • o 12 *map V 13 "map m ! } fmt -c 14 "map T ! } sort 15 microsystems Revision A, of 27 March 1990 34 SunOS User’s Guide: Customizing Your Environment Explanation of Command Lines Line 1: set autoindent When adding new lines, maintain the same indentation as the line above. Line 2: set autoprint Automatically print each line altered within ex, the line editor. Line 3: set noignorecase The case (upper or lower) of a character is significant in searches and substi- tutions. Use set ignorecase to make searches and substitutions case insensitive. But be careful if you do! Line 4: set nomesg Messages to the terminal do not interfere with the vi display. Line 5: set noslowopen Sets up vi for operation with a fast terminal or window. For terminals on slow dialup lines, use set slowopen to suspend updates of the screen during insertions for smoother operation. Line 6: set noterse vi gives more complete error messages for beginning users. For shorter messages, use set terse. Line 7: set nonumber Inhibits display of line numbers in both ex and vi. For a display of line numbers, use set number. Line 8: set report=2 Report on all substitutions or deletions that affect more than two lines. Line 9: set tabstop=8 microsystems Revision A, of 27 March 1990 Chapter 5 — vi and the . exrc File 35 Set tab stops every 8 characters. Line 10: set wrapmargin=8 When a space is typed within 8 characters of the right screen edge, insert a carriage-return at the end of the previous word, starting a new line automati- cally. To turn off this feature, set wrapmargin to 0. Line 11: map ; : While in vi command ( visual) mode, interpret a semicolon as if you had typed a colon. This allows you to use either a semicolon or a colon as the first character in a substitution command. Line 12: map g : % While in visual mode, interpret a g as if you typed the characters : %. This allows you to start commands to substitute throughout the file with either a g ora : %. Line 13: map v ~ While in visual mode, interpret a v as if you typed a ~, the command to invert the case of a character. Line 14: map m ! } fmt -c While in visual mode, interpret an m as if you typed in the command ! } fmt -c to adjust line-breaks for the lines between the cursor and the end of the para- graph as close to column 80 as possible (without breaking across words). Refer to Editing Text Files and fmt in the SunOS Reference Manual for more information. Line 15: map T ! } sort While in visual mode, interpret a T as if you typed in the command ! } sort a command to sort the remaining lines in the paragraph. Revision A, of 27 March 1990 * 6.1. Trust Amongst Machines on a Network /etc/hosts Login Access to Other Machines You can log in from your machine to another machine using r login, described in SunOS User’s Guide: Getting Started . Some systems trust certain users and certain machines to log in without requiring a password and other security mechanisms. You can allow or restrict login access by other users to your machine. You, or your system administrator, can set up your machine so that users must supply a password to log in to your machine, or so that certain users from certain machines simply can’t log in to your machine. When another machine running the UNIX system 5 on your local network trusts your username on your machine, that machine doesn’t require that you type your password or undergo other security checks to log in. The system files / etc/passwd and / etc/hosts . equiv control the users and the machines that may log in to your machine and to your account. Before we describe the files that control access privileges, let’s consider how one machine finds another over the network. The / et c / ho s t s file contains a list of machines — also known as hosts — and their corresponding addresses on the network. (The file can also contain any optional nicknames for machines.) Your own machine’s address is stored here. Programs use /etc/hosts to locate other machines for communicating over the network. However, if you’re running the NIS, the NIS file hosts may supplant or supple- ment your own / etc/hosts file; the NIS hosts contains the network addresses of every machine on the network . 6 Therefore, you (or your system administrator) need only maintain an up-to-date /etc/hosts file when the NIS is not available. Here is a sample /etc/hosts file: 5 The SunOS operating system is an enhanced version of UNIX, a registered trademark of AT&T. 6 Not every system runs the NIS; not all that do use the host s scheme. See SunOS User's Guide: Getting Started . 37 Revision A, of 27 March 1990 38 SunOS User’s Guide: Customizing Your Environment — V # # Sun Host Database # # If the yellow pages is running, this file is only consulted when booting # 127.0.0.1 localhost loghost # 192.9.90.114 gaia 192.9.90.103 venus V ) /etc/hosts . equiv The /etc/hosts . equiv file contains a list of machine names that your machine trusts. When a user on one of the machines in the list tries to log in or execute a command on your machine, your machine checks in your /etc/passwd file to see whether it should permit access. / etc/passwd regulates who can log in on a machine; it contains information about users, including their usernames, their passwords, their ID numbers, and so on . 7 If that person’s username is in /etc/passwd or in the NIS password database, then your machine checks / et c / ho st s . equiv. If it contains the name of the machine that he or she is using, then your machine allows him or her to log in. If the hostname isn’t there, then he or she is prompted for a password. Here is a sample /etc/hosts . equiv file that permits any users on machines gaia, pluto, and verlaine (who also appear in your /etc/passwd file or in the NIS database) to log in or execute commands on your machine from their machine. You must be root to modify this file. For information on becoming venus % cat /etc/hosts .equiv — — ^ — v : \ root, see SunOS User’s Guide: Get- gaia , ting Started and SunOS User’ s Guide: pluto Doing More. . ve rl a irie ; • venus % • : J If your system supports the NIS, you may put a single plus sign (+) all by itself in your / etc / hosts. equiv file. This signals that anyone on the network served by the NIS (who is also named in in the password database) may log in to your machine without providing a password. As a matter of fact, /etc/passwd also uses the plus sign convention, so you can thus allow every- one on the network access to your machine. You can also selectively bar some people in the NIS database from logging in to your machine. You can further restrict other people’s access to your machine with the . rho st s file, located in your home directory. For more on . r ho st s and /etc/hosts . equiv, see the SunOS Reference Manual, the System and Net- work Administration manual, or type man hosts, equiv. 7 For more information about the / etc/passwd file, see SunOS User's Guide: Doing More and the SunOS Reference Manual , or type an 5 passwd. microsystems Revision A, of 27 March 1990 Mounting Remote Filesystems With NFS If your workplace is running rfs instead of NFS, then you should refer to Chapter 8. Ask your system administrator which one you are using. You may very often find that you have a need to access programs or files located on another machine. Many times it is not practical, because of space limitations, to copy the files you need over to your machine. For this reason, NFS (described in Chapter 1) offers you the ability to mount other filesystems, allowing you to access files on other machines as though they were on your own. For example, if your company had a lot of software used by everyone, such as spreadsheets, demos, and text editors, a lot of valuable storage space would be taken up if each user had to have his or her own copies of all the pro- grams. People could use rlogin to access other machines, but this would be unsatisfactory if they had to do so every time they wanted to run a program. What your company could do, though, would be to put the relevant files on one host (also known as a server) and have users mount the filesystem containing those files. 7.1. The mount Suppose your company’s demos are located in /usr /demos on a server called Command slugfest. You create (or have your system administrator create) a directory, /usr/ demo s , on your own system. This /usr/ demo s is called a mount point ; you then use the mount command to create a sort of invisible connection between / usr/demos on slugfest and your / usr/demos mount point. As long as you maintain the mounting, every time you refer to /usr/demos, you access the one on slugfest as though it were on your own machine — you can list its contents with Is, cd in and out of it, view its files with more, run its programs, and so on. Mounting allows you to do all of this without hav- ing to rlogin in to slugfest. You must be root to use mount. For information on becoming root, see SunOS User's Guide: Getting Started and SunOS User's Guide: Doing More. Use the mount command to mount other filesystems. The general format of the command is mount machine-name: filesystem directory where machine-name is the name of the remote machine that contains the filesys- tem you want to access; filesystem is that remote filesystem; and directory is a directory on your system. (This directory is the mount point). Here’s how you would mount /usr/demo and view its contents: microsystems 39 Revision A, of 27 March 1990 40 SunOS User’s Guide: Customizing Your Environment venus# mount slugfest ; /usr/demo /usr/demo ■ /venus # Is BUTTONBOX BUTTONTEST CDROM . venus# v .■ /usr/demo WBmMMK FACES / '.GP SHADER SOUND SUNVIDEO ..SUNVIEW •• sunviewl You do not have to mount a remote filesystem to a filesystem of the same path- name. In other words, you don’t have to mount / usr/ demo on slugf est to a directory called /usr/ demo on your machine. You can mount it to any direc- tory you want. In fact, since most users aren’t allowed to create directories in /usr, you could, for example, create a subdirectory dem in your home directory and mount /usr/demo there (assume /home/art /medici is your home directory): Use su to become root. / — — : — " " “ ; f • ' N venus % xnkdir /home/art /medici/dem Pa s sword ; ■ •; (Type root ' s . passwdhd here. ) ■" • venus# mount slugf est : /usr/demo /home/ art /medici/ dem venus# exit venus % Is /home/art /medici/dem 3UTT0NB0X . DIAL30X Makefile SUNVIDEO : BUTTONTEST FACES SHADER SUNVIEW CD ROM GP SOUND Sunviewl venus % The important thing is that you make sure that there’s a mount point on your sys- tem to mount the remote filesystem to. Suppose you try to mount /usr/ demos to adirectory, /usr/showme, without creating /usr/ showme first. You’ll get an error like this: r — t - ■ — — — ■ — t - - — — ■ > venus# mount slugfest : /usr/demos /usr/showme mount: slugfest : /usr/demos on /usr/showme: no such file or directory mount: giving up on /usr/showme venus# - ; " — L — 7.2. The /etc/ f stab File You must be root to modify your / etc/f stab file. Rather than having to use mount for every filesystem you want to mount, you can make use of the file fstab which is located in the directory /etc. 8 f stab is a table of filesystems you want to mount, with any filesystem options you want. Every time your system is booted, it checks fstab to see what filesystems to mount. This can save you considerable time over using the mount command directly for each filesystem you want mounted. 8 fstab stands for “file system table.” microsystems Revision A, of 27 March 1990 Chapter 7 — Mounting Remote Filesystems With NFS 4 1 The general format of an entry in an f st ab file is machine :filesy stem directory type option freq pass where machine .-filesystem is the remote filesystem you want to mount and the machine on which it is located directory is the directory on your system you want to mount it to type is the filesystem type, in this case nfs or rfs options are the filesystem options, such as those described in Section 7.3 freq is the number of days between dumps pass partition check pass number When mounting filesystems through NFS, these last two fields should always be 0. Here’s an example of an /etc/f stab file: Figure 7-1 A Sample f st ab File ( dirt : /export /root /venus / nfs rw 0 0 dirt : /usr /usr nfs ro 0 0 dirt : /home /dirt /home /dirt nfs rw 0 0 moon : /usr/ spool/news /usr/ spool /news nfs ro, soft,bg, intr 0 0 anchor: /usr/games /usr/games nfs ro, bg 0 0 boodle: /usr/boodle /usr/boodle nfs ro, bg 0 0 boodle : /usr/man /usr/man nfs ro, soft,bg, intr 0 0 boodle : /usr/tools /usr/doctools nfs rw, hard, bg, intr 0 0 capulet : /usr/demo /usr/demo nfs ro, bg 0 0 olympia: /usr/doc /usr/doc nfs ro, hard, bg, intr 0 0 olympia : /usr/olympia /usr/olympia nfs rw, hard,bg, intr 0 0 buoy : /usr /buoy /usr/buoy nfs rw, hard 0 0 yow: /usr/src /usr/src nf s. ro, soft , bg, intr 0 0 USR /mnt rfs v rw,bg 0 0 The umount Command umount unmounts file systems that you have previously mounted, umount works similarly to mount; however, you only need to specify the mount point on your system when using it. You do not need to mention the remote machine it’s mounted from. So, for example, to unmount / usr /demos, which we mounted above, you would type as follows: §sun Xr microsystems Revision A, of 27 March 1990 42 SunOS User’s Guide: Customizing Your Environment 7.3. Options to mount and umount Filesystem Options As with mount, you must be root to use umount. There are various ways to use mount and umount. A few of the more com- mon ways are given here. Please note that you can combine a number of these options; for the exact syntax, consult the SunOS Reference Manual or type man mount. (with no options) mount with no arguments displays what you currently have mounted. You do not have to be root to use the mount command this way. -p (‘ ‘print’ ’) mount displays a list of mounted filesystems in the format used in fstab. You don’t need to be root to use mount this way, either. -v (“verbose”) Displays a message indicating each filesystem in /etc/fstab being mounted as it occurs. This option is also available with umount. -a (“all”) mount will attempt to mount all the filesystems in /etc/fstab. filesystem or directory If you use mount with either the name of a filesystem to be mounted or the name of one of your directories to mount to (but not both), mount searches fstab for the corresponding entry and mounts the filesystem as indicated there. Also true for umount. -h host (This is a umount option.) umount unmounts all the filesystems which are remote-mounted from the server host . In the sample fstab file shown above, there are a number of filesystems mounted from the server boodle ; to unmount them, you would give a command like this: venus# umount -v -h boodle /usr/man Unmounted /usr/boodle : Unmounted /usr/tools : Unmounted . venus# v -o options There are a number of options to mount. These affect the access you have to the remote filesystem, and the manner that mount goes about trying to mount the system. These are some of the more common filesystem options: hard or soft If you soft-mount a remote filesystem, mount will try up to a certain ftsun Xr microsystems Revision A, of 27 March 1990 Chapter 7 — Mounting Remote Filesystems With NFS 43 number of times and then give up, returning you an error message; when you hard-mount it, mount will continue trying the mount until it is successful. There are advantages to both hard- and soft-mounting. Hard-mounting ensures that mount will not give up on a server that is only tem- porarily inaccessible, but will eventually connect you. It is a good idea to always hard-mount filesystems that you write to; that way you lessen the chance of data being lost during a write operation. On the other hand, if you are hard-mounted to a server when it crashes, your system may hang up while waiting to connect with the remote server. This option is available only with NFS. bq or fg You can specify whether you want mount to retry failed mounting attempts in the background or the foreground. When a mount occurs in the foreground, the shell is tied up until the mount succeeds; if you run the mount in the background, the shell and you can do other things dur- ing the mount attempt. rw or ro You can mount the other filesystem as read-write or read-only. It is a good idea to mount filesystems as ro if you are only going to access their files and programs, not write or change them. intr If you hard-mount a filesystem, intr allows you to interrupt the mount from the keyboard (with I Ctrl-C D . This option is only available with NFS. For information on other options, see the SunOS Reference Manual. Remember, you can combine various options when using the mount command — see the SunOS Reference Manual. 7.4. The Automounter Just as the mount command removes the need to rlogin in to other machines every time you want to access their files, the automounter lessens the need for hand-mounting remote systems. The automounter mounts remote file systems “on the fly”; that is, it creates a temporary mount point (in the directory /tmp_mnt), mounts the remote system, and unmounts it automatically. It does so without your having to change your f stab file; nor do you need to become root to mount and unmount remote filesystems. The mounting takes place invisibly when you refer to the remote filesystem. Thus, you can cd to a remote directory, Is its contents, more a file on another machine, and so on, all without having to mount anything first. The syntax for using the automounter can vary from site to site, and from machine to machine. Here is a general example of how it is used. 9 9 These examples assume your site utilizes the NIS hosts and pa s s wd databases. (These contain the addresses of machines on the network, and the list of users and their home directories, respectively.) Because microsystems Revision A, of 27 March 1990 44 SunOS User’s Guide: Customizing Your Environment A reference to /net /machine/ filesystem will cause the automounter to automatically mount filesystem from the machine machine. For instance, in the example below, the command Is /net/ jupiter/var/spool causes the automounter to mount /var/spool from the machine jupiter; and Is lists its contents: venus% Is /net/ jupiter/var/spool .. cron iw ppd uucppublic ipd mail , rwho . : : : :,.Vpd ... lpd mqueue secretmail Ipd. lock •; venus % V news •; uucp mmmm Likewise, a reference to /homes /username causes the automounter to mount the home directory of the person with the username username. Using this syntax, the command cat /homes /bcleaver/ rhyme . f ile mounts the bcleaver ’s home directory, and cat displays the contents of the file rhyme . file: If you go a specified period (usually five minutes) without accessing the remote filesystem, automount unmounts it for you. The first time you mount a remote filesystem, the automounter can take a little while; once it’s mounted, though — and for as long as it remains mounted — access is more or less immediate. automount is started up automatically when your machine starts (“boots”). However, if your system administrator has not set the NIS maps that it needs, or you have not set local maps for it, the automounter exits (dies) silently. Use the command ps -aux | grep automount to see if you are running automount. In order to make its mounts, the automounter users a number of map files (located in /etc and beginning with “auto”); you can modify existing maps or each site running NFS is unique, consult your system administrator on how to use the automounter. See SunOS User’s Guide : Getting Started for more information on NIS . Xr microsystems Revision A, of 27 March 1990 Chapter 7 — Mounting Remote Filesystems With NFS 45 create your own. For example, to use the map /etc/auto . master, you would start the automounter as follows: For more information on using the automounter, see System and Network Administration. 7.5. Who’s Mounting This The showmount command gives the opposite information from typing System? showmount mount. It gives information about who has mounted filesystems from a particu- lar server. For example, let’s assume that user michael on the machine yazoo has mounted /usr/games from the server slugf est; reed on zippy has mounted /usr/demos from the same server, and roger, on yow, has mounted /usr/tools. The -a option displays all the remote mounts in the form hostname -.directory-. Sharing Files Under RFS As mentioned in Chapter 1, the SunOS operating system normally runs NFS as its system for allowing users to share files over a network. However, some sites running the SunOS operating system may elect to use RFS instead (or even in conjunction). Sharing files under RFS is similar to what you learned in Chapter 7, although the commands are somewhat different. Following is an introduction to mounting and accessing files under RFS. You may want to skim Chapter 7 to get a basic idea of what mounting is, what the file /etc/f stab is used for, and so filesystem is defined in Chapter 1 . Briefly, mounting a remote filesystem means making it look as though it were on your own machine. For example, suppose your company keeps a number of edit- ing programs in a directory called /usr/editor s on another machine called zippy. You (or your system administrator) can create your own directory /usr /editors on your machine, and then map the directory on zippy to your own /usr/editors. In this way, each time you refer to /usr /editors, you refer to the /usr/editors on zippy, as though it were on your own machine. 11 This mapping is known as mounting. Under RFS, machines on a network are grouped into domains', a domain is a group of machines, ranging anywhere from one machine to all the machines on the network. You can mount filesystems from machines in both your own domain and domains to which you don’t belong. Every domain has a domain server — a machine that keeps track of which filesystems are available for mounting, as well as password information for machines in the domain. 8.1. Advertising Resources In order for people to mount each other’s filesystems, they must first advertise With adv which filesystems, if any, are available for mounting. This is done with the adv command. The adv command puts the filesystem in the domain advertise table located on the domain server. An advertise table is a list of filesystems that have been advertised as available for mounting. The domain advertise table, then, is a list of all the available filesystems on all the machines in a domain. 10 NFS was developed at Sun Microsystems. RFS was developed by AT&T. 11 The /usr/editors on your machine is known as a mount point. It does not have to be the same as the directory on the remote system; you could, for example, mount zippy’s /usr/editors on /home/venus/bin/editors. XT microsystems 47 Revision A, of 27 March 1990 48 SunOS User’s Guide: Customizing Your Environment When you advertise a filesystem as available, you give it a special name that other people can identify it with. This special name identifies the filesystem as a resource. For example, if you’re making the directory / usr/ graphics/tools available, you can refer to it as the resource gra- phtools. Now anyone who wants to mount that directory can do so by mounting GRAPHTOOLS. This is the format of the adv command (optional arguments are in brackets): adv [-r] [-d "description"] resource pathname [ clients ] These are the various options and arguments: -r This means advertise this filesystem as read-only. -d description This is an optional description, up to 32 characters long and enclosed in quotes, of the resource being made available. resource This is the name you’re assigning to this filesystem. It may be up to 14 printable characters long. pathname This is the full pathname to the filesystem you want to share. clients If you want to restrict the availability of the resource to only certain machines, you can list them here. Here’s an example of advertising a resource: Note that you must be the superuser root to use most of these commands. See SunOS User’s Guide: Doing More. In this example, the user on machine venus is advertising the filesystem /home /venus /games to be available as the resource NERD GAMES. Displaying Your Advertised The adv command by itself gives a list of the resources on your machine that Resources you’ve advertised as available for others to mount: You do not have to be root to use adv without any arguments. (Note also that two of these lines are too long for the screen, and wrap around.) ' : — T" ■ \ venus% adv . . NERDGAMES /home/venu's/games read-write "Computer Nerd Games" unrestricted FILM /home/venus/medici/personal read-only "video listings" zippy moondog DCCTOOLS /usr/dpctoois . read-only "editors" , unrestricted ’;vemis%’ : v : ii ■ xi _ ; / In the example above, the word “unrestricted” refers to the fact that anyone can mount DOCTOOLS and NERDGAMES, while only users on machines zippy and moondog can mount the other resource. r- • • ■ • ’> venus# adv -d " Computer Nerd ' • Games :.:NEMGAM^ i/home / venu s /games : venus# \ J ^ microsystems Revision A, of 27 March 1990 Chapter 8 — Sharing Files Under RFS 49 8.2. Mounting Remote Filesystems What’s Available? The nsquery Command You do not have to be root to use nsquery. Now that you’ve made your files available to others, how do you go about getting access to theirs? The first thing to do is to find out what’s available — i.e., what resources other people have advertised as available for your use. The adv command, as illustrated above, showed you what was available for mounting from your machine; in other words, it displayed the local advertise table. The domain advertise table lists all the resources that everyone in your domain, including you, has advertised. Use the nsquery command to see this table. nsquery by itself displays the entire domain advertise table. Here’s how nsquery displays its results: \ venus %' nsquery'. ; A RESOURCE ■ ACCESS : : SERVER DESCRIPTION BUDGET . read-only -. admin. manag •Old budget guesses. CHEWY read/writ® foods . krakow Files on chewy foods ; CLIENT Si.;. • read/ write . admin . ducky '■ files on ' cu s t ome rs . DOCTbOLS ■read-only ; '• admin, venus . • editors EDITORS ; .i: read-only • ; ; ‘ v admin:, zippy text : ' v 'tdpls' 'I- NERDGAMES- • | : |read7Wr|t e | admin, venus Computer -'.Nerd Games ■ FILM read-only.: admin. venus • video . li stinqs • . : ROCKS' ■ venus % ■" v ' read/write • food s . Jcrakow : ; ; Fi 1 e.s on ’ • p ruhphy . ; f pods : :.v : Vi. y. J You can also give nsquery an optional domain or machine name. There are three possibilities for doing so: The command nsquery machine gives all the resources available on the named machine in your own domain. So typing nsquery z ippy would show everything available on the machine zippy. The command nsquery domain. (note the period) displays all the resources available in a different domain, so typ- ing nsquery graphics, gives all the resources in the domain graphics. Lastly, you can combine the two syntaxes: if you type nsquery domain . machine you’ll see all the resources advertised by that machine in that other domain. Here’s an example of using nsquery to display all the resources on the machine krakow in the domain foods: &sun XT microsystems Revision A, of 27 March 1990 50 SunOS User’s Guide: Customizing Your Environment Unadvertising With unadv The mount Command venus%. nsquery foods . krakow 1 . . •• V * . . RESOURCE ACCESS SERVER : . . ■.DESCRIPTION:; ||| . £§£3/writ‘e foods .krakow .^ii.es .jon chewy, fbods; . • :RPpkS. |.venuis% V. • read/write foods .krakow Files on crunchy foods J You can remove a resource you’ve advertised from advertise tables with the unadv command. Just type unadv followed by the resource you want to remove: Now that you know how to find out what resources are available, you can mount them. The format of the mount command is (as always, optional arguments in brack- ets): mount [ —r ] -d resource directory where resource is the resource on the other machine you want to access directory is the directory on your machine you want to map the resource to (the mount point), and -r indicates that you want the resource mounted read-only Now anytime you refer to /home/venus/medici/editors, you’ll have access to the editors which are on the machine z ippy : ; : ; veitju5‘% IS; /home ^ • SlowHand WordGush ex Spei « tool . . ed vi; . .. : WbrdAg6riy;> ... venus % . V : : - iL_ : ' • ' ' ’ ’ ' ’ ' ' / #sun \r microsystems Revision A, of 27 March 1990 Chapter 8 — Sharing Files Under RFS 51 Displaying the Current Mounts Unmounting With umount 8.3. The /etc/ f stab File The mount command by itself will display all the filesystems you have mounted: Likewise, the rmntstat command tells you what resources of yours other peo- ple have mounted: r . ,. ... : ... : , • : , . ,, . •: ; . : : - . venus# rmntstat RESOURCE PATHNAME HOSTNAME NERD GAMES /home /venus /games buddha TYPOS /home/venus/medici/spell venus#. ducky garden J This example tells you that someone on the machine buddha has mounted your games directory, while machines ducky and garden have the TYPOS resource directory mounted. To unmount a filesystem, use the umount command. Just type umount -d resource where resource is the name of the resource you want to unmount. You can have you machine automatically mount selected remote filesystems by putting them in your /etc/f stab file. 12 When you start your machine up, it will mount all the filesystems you list in / etc/f stab. The format of the f stab file is given in Section 7.2. 12 fstab stands for file system table. fsun Xr microsystems Revision A, of 27 March 1990 Index Special Characters # C shell comment symbol, 8 . prefix, explained, 7 ~ and stty, 4 A adv command, 47 advertise table, 47 aliases, escaping with \command , 29 automatic mounting (automount), 43 automount command, 43 automounter, see automount c C shell setup file, . cshrc, 7 cd command and the cdpath variable, 12 cdpath variable, 12 circumflex character, to specify control keys for stty, 4 command automount, 43 find, 29 man -k, 19 : map (vi), 32 mount, 39 mount (RFS), 50 printenv, 21 rmntstat, 51 set, 7 : set (vi), 31 setenv, 21 showmount, 45 stty, 3 tset, 24 umount, 42, 51 unadv, 50 unset, 7 comment symbol # in the C shell, 8 commented-out lines in startup files, 8 core file, 4 creating a mount point, 39 csh, name of C shell, 7 . cshrc C shell setup file., 7 D delete word terminal function, 3 displaying the domain advertise table, 49 domain in RFS, 47 domain advertise table, 47, 49 domain server in RFS, 47 domain tables removing resources from, 50 dot prefix, explained, 7 E end-of-file terminal function, 4 endif statement, C shell, 25 environment defined, 1 environment variables, 21 erase terminal function, 3 /etc /hosts file, 37 /etc/f stab file in RFS, 51 /etc/ho st s . equi v file, 38 EXINIT environment variable, 26 . exrc file, 31 F file /etc/hosts, 37 /etc/f stab (RFS), 51 /etc/hosts . equiv, 38 filesystem options to mount, 42 find command, 29 H jQ hard mounting, 43 history variable, 7 host, 37 I w $ if ... then statement, C shell, 24 if statement, C shell, 13 ignoreeof C shell option, 7, 13 interactive options as variables, 7 interrupt terminal function, 4 - 53 - Index — Continued L line kill terminal function, 3 literal next-character terminal function, 4 login access to other machines, 37 . login file, 21 . logout file, 27 M mail, 1 . mailrc file, 2 man command -k option, 19 : map command (vi), 32 mount command, 39, 50 mount point, 39, 47 creating, 39 mounting automatically, 43 with automounter, 43 mounting remote filesystems, 39 filesystem options, 42 hard, 43 soft, 43 under RFS, 47, 50 with automounter, 43 N network login over, 37 remote login, 37 NIS, 37 ns query command, 49 p print env command, 21 PRINTER environment variable, 26 R rc suffix, explained, 7 remote login, 37 trust, 37 reprint terminal function, 4 RFS mounting with, 47 . rhosts file, 38 rmntstat command, 51 s server, definition of, 39 set command, 7 : set command (vi), 31 set env command, 21 setup file, 2 command to list, 2 setup for remote terminals, 24 shell, name for a command interpreter, 1 showmount command, 45 soft mounting, 43 stop display terminal function, 4 stty and the circumflex, 4 stty command, 3 suspend terminal function, 4 T terminal functions, 3 trust between machines, 37 tset command, 24 u umount command, 42 in RFS, 51 unadv command, 50 unmounting remote filesystems, 42 unmounting remote filesystems (RFS), 51 unset command, 7 unsetting a vi variable, 32 v variables, environment, 21 vi editor, 1 w wait-for-keystroke terminal function, 4 - 54 - 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 GUI 9 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