TITLE: Introduction to the UNIX Operating System DOCUMENT NO: U-002 DATE: June 15, 1993 VERSION NO: 12 INTRODUCTION This document is intended to help the new user of the computers that run a version of the UNIX operating system, such as the RS/6000s (RS), the Sun Workstations (Sun) or the NeXT computers. The RS computers run IBM's version of UNIX called AIX, the Suns run their version of UNIX called SunOS and the NeXT's operating system is based on the Mach UNIX system developed at Carnegie Mellon University. The command interpreter described here is the Korn shell, which is the interface between the user and the UNIX system. The Korn shell is the default shell on ITC's UNIX systems so that user commands are generally the same on each UNIX machine. Any differences in a command among the machines will be noted in this document. If you don't already have it, pick up a copy of U-001, ``UNIX Resource List,'' which can be found on the document shelves in Gilmer Hall near where you found this document. It contains information on where to find everything you need to get started with UNIX. As it is difficult to include in one document the things that a wide audience of users might want to know, this document is packed full of in- formation. There is probably more here than you will want to try to as- similate in one sitting. Try reading a section at a time and experiment- ing on your account as you work your way through the document. There may be some sections for which you currently have no use; skip them. They will still be there when you need them. Things to Remember 1. The UNIX operating system is case-sensitive; i.e., a command in lower-case letters is interpreted differently from one in capital letters. _ALWAYS_ turn off the Caps Lock key on your terminal or microcomputer before you log in and enter all commands in lower-case letters unless otherwise instructed. 2. Be sure to end everything that you type with a carriage return (marked Return or <-| ). The Return key is shown as in this document. The computer doesn't know you are trying to tell it to do something until it sees a carriage return, so if the computer seems to be ignoring you, check to see if you forgot to press the carriage return. U-002 Introduction to the UNIX Operating System 2 GETTING STARTED Connecting to a UNIX Computer 1. If you are accessing a UNIX machine from one of ITC's public micro- computing facilities, follow the steps below. a. For all facilities except Stacks, insert the startup disk in the A drive, if it is not already there. The Stacks computers will boot from their hard drives. b. If necessary, turn on the computer. If the computer is already on, push the reset button, which is on the front of the computer. c. When prompted for login name, type the letter and number which appear on the blue label on the front of the computer. d. Strike any key to continue after the login message appears. e. The ITC MicroMenu ``Main menu'' will appear on the screen. Press the down arrow key (v) until ``Communications menu'' is highlighted. Press the return key. f. ``Telnet'' will be highlighted on the ``Communications menu.'' Select it by pressing the return key. g. The ``Host computers'' menu will appear. Use the down arrow (v) to highlight the name of the computer on which you have an ac- count. Skip to the next section entitled ``Logging In and Changing Your Password.'' 2. If you are accessing a UNIX machine from a microcomputer other than those in ITC's public facilities, you will be using NCSA PC Telnet to make the connection. (See TIB-165, ``An Introduction to PC Tel- net,'' for more information.) Boot your computer in the usual way. Once you have a prompt, to connect to a UNIX machine, type telnet machine_name where machine_name is the name of the computer and means to press the key marked with <-| or Return once. You may see several messages generated by NCSA Telnet, but eventually you should receive a message from the UNIX machine, followed by a line ending with login: Skip to the next section entitled ``Logging In and Changing Your Password.'' 3. If you are dialing in to Telnet, follow the instructions in M-012A, ``ProComm Plus User's Guide'' which is available from ITC in Gilmer Hall. All of ITC's UNIX computers are available via Telnet. When di- aling in and logging on to UNIX computers, try space parity, seven data bits and one stop bit (S71) or eight data bits with null parity and one stop bit (N81) for both logging in and file transfer via Kermit. These U-002 Introduction to the UNIX Operating System 3 settings can be entered on ProComm's dial-in menu (ALT-D). 4. If you are logging in at the console of a Sun Workstation, the login message and prompt will already be on the screen. If not, press the Return key to refresh the screen. Continue with the login process out- lined in the next section. Logging In and Changing Your Password You should now be looking at the computer's login prompt. 1. _In_ _lower_ _case_ (UNIX is case-sensitive), type the login ID that was given to you; it will probably be your initials with an alphanumer- ic suffix. 2. After you have typed your login ID, press the Return key. The system will respond with Password: Enter the password you were given, followed by a carriage return. 3. Once your password has been accepted, you will probably be asked to change it. On the Sun computers, you will be prompted to enter your old password (the one you were given), followed by a prompt for your new password. On the RS/6000 computers, you will only be prompted for a new password. Enter a new password with from six to eight characters including at least one numeric or special character. The RS/6000 com- puters require five alphabetic characters. You will be asked to enter it again for typing verification. Once this process is complete, you will see a welcoming message and possibly some news items. Choosing a password that provides system security is important, not only to protect your files, but also to protect the entire system from being accessed by the mischievous or unscupulous. Do not use your name or initials or any word that can be found in the dictionary. Putting a number in the place of a letter (the digit 1 for the letter l, for in- stance) is also not secure, nor is putting a digit at the beginning or end of a word or name. It is safer to use a sequence that is meaning- ful only to you or to use two words, joined with a character such as a hyphen or comma. If you are logging in to an RS/6000, you will receive the message: Enter terminal type [default is vt100]: In UVa's microcomputer facilities, vt100 is the type of terminal being emulated. To accept vt100, press the Return key. If you are using some other terminal type, enter it (such as adm5, tek4107 or xterm). Finally you will see the system's prompt. The prompt varies from machine to machine, but may include a $, which is the Korn shell's de- fault prompt. The machine is now waiting for you to enter a command. 4. You can change your password at any time by typing U-002 Introduction to the UNIX Operating System 4 passwd The system will prompt you for your old password, then for your new password. Choose a password following the guidelines given in Step 3 above. You will be asked to enter it again for typing verification. Terminating a Command, Halting Screen Output and Logging Out 1. Break Sequences to Terminate a Command If you want to stop a command before it completes execution, press the the the key sequence from the table below which is appropriate for the type of terminal you are using. This should return you to your initial prompt. _____________________________________________ | Break Sequences | | Terminal Key(s) | |___________________|________________________| | Microcomputer | CTRL-C or ALT-Y | | Sun or RS/6000 | CTRL-C | |AT&T 4425 Terminal | DISCON/BREAK or DELETE | |AT&T 5620 Terminal | DISCON/BRK or DEL | | ADM5 Terminal | RUB | |___________________|________________________| 2. Halting Screen Output If you want to temporarily halt output to your screen without terminat- ing the execution of the command, enter CTRL-S. Start output again by entering CTRL-Q. If you are on a microcomputer, the key marked Scroll Lock toggles between halting and resuming output. 3. Logging Out When you are ready to log out, press CTRL-D or type exit. UNIX Command Syntax The typical syntax of a UNIX command is command arguments files where the command options, also called arguments, are usually preceded by a hyphen (-). More than one file name may generally be given. Optional argu- ments will be surrounded by square brackets ([ ]) in the documentation on each command. FILES The File System UNIX uses a hierarchical (or tree-structured) directory system to store files. A diagram of a portion of a file tree is shown below, with the U-002 Introduction to the UNIX Operating System 5 directory /, called the ``root'' directory, at the top of the tree. _____ |__/__| (root) ||||||| ____________________________|||||||_______________________________ |_bin_| ____________________||||||______________________ |_etc_| |_usr_| ______________||||______________ |_dev_| __|__ |_tmp_| ________||_______ |_lib_| |passwd| |_home_| |_uva_| | | | ____________| | |______________ |_xyz8g_| ___|___ |_jkl2w_| |_abc3f_| ________| | |___________ |_News_| __|___ |_junk_| |_docs_| In the UNIX system, all the commands you type as well as peripheral devices such as disk and tape drives can be specified as a path to a file. A path name can be absolute, meaning it begins with /, or relative to the directory where you are attached, called the current or working directory. Directory names are separated by additional slashes (e.g., /etc/passwd). In the figure above, some of the directories shown are: Name Directory Contents Name Directory Contents /bin UNIX utilities, such as /etc administrative files ls, cat, cp, cal, and directories, such spell, date, tee, etc. as the file ``passwd'' (described below) which contains login information for each user account /usr additional utilities /lib libraries, such as C language and mathemat- ics libraries /tmp temporary files; this /dev peripheral devices, directory is cleaned such as disk drives and out periodically terminals /home user directories /uva locally installed util- ities You will be assigned a directory with your login ID as its name when you are given an account. On the RS computers, the user accounts reside in the /home directory. When you complete the login process, you will be at- tached at the directory /home/your-login-id in the file tree. Your login directory is called your HOME directory where HOME is one of the UNIX system's shell variables. Shell variables are read by many UNIX commands and can be given values either by the system or the user. For more informa- tion about shell variables, see ``Tailoring UNIX'' below. U-002 Introduction to the UNIX Operating System 6 You can create other directories and files below your HOME directory as you need them. For instance, if your login ID is ``abc3f,'' you may be as- signed a HOME directory with the name /home/abc3f. If you create a directo- ry named ``docs,'' you could put all the chapters of your thesis in that directory. Then the full path of a file named ``chap1.thesis'' would be /home/abc3f/docs/chap1.thesis The table on the next page gives some commands and selected options that are useful for manipulating files and moving around in the file system, including how to list the contents of a directory (ls), the contents of a file (cat) and how to move from directory to directory (cd). To get com- plete information on each command and all its options, use the man command to view the on-line documentation. The syntax is: man command If there are characters in square brackets ([ ]) after a command, this means that these characters are optional. Table of File Commands ____________________________________________________________________________ Command Meaning Result ____________________________________________________________________________ cat filename(s) catenate list contents of file(s) to the screen, one after the other. cd directory change directory change working directory to directory; if directory is omitted, changes to your HOME directory. cp file1 file2 copy make a new copy of file1 called file2. diff file1 file2 difference list the differences between file1 and file2. find dir -name find files beginning search at directory file -print dir matching file and list the entire pathname grep [-i] global reg. search files for string and list string files exp. processor path and line if found; use -i option to ignore case of string. head filename list first ten lines of filename U-002 Introduction to the UNIX Operating System 7 Table of File Commands ____________________________________________________________________________ Command Meaning Result ____________________________________________________________________________ ls [-AlpsCF] list return a list of the files in the current directory (see exam- ple below) -A all entries, including files beginning with period (.) -l long format -p put slash (/) after directories (RS) -s give size in blocks -C multi-column listing (with short format) -F put slash (/) after directories, asterisk (*) after executables mkdir dir make directory create a new directory named dir. more filename list contents of filename a screenful at a time; scroll for- ward with the space bar, back with b, end with q or CTRL-C. mv name1 name2 move rename file name1 to become name2 or move a file name1 to directory name2. page filename same as more (RS) pwd print working list the pathname of the working directory (current) directory. rm [-i] remove delete a file. -i option queries for y or n response; default n (do not delete). rmdir directory remove directory delete directory; directory must be empty. tail filename list last ten lines of filename. tee filename input to tee is sent to both filename and standard output. wc filename word count list the number of lines, words and characters in filename. U-002 Introduction to the UNIX Operating System 8 The ls Command Sample output from the command ls -Al is shown below, with column numbers at the top for reference with the explanation following. 1 2 3 4 5 6 7 8 ___________________________________________________________________________ -rm-r--r-- 1 abc3f usr 4193 Jun 10 10:11 .history -rw-r--r-- 1 abc3f usr 626 Jun 6 12:08 .kshrc -rw-r--r-- 1 abc3f usr 338 Mar 17 16:43 .mailrc -rw-r--r-- 1 abc3f usr 9156 Nov 9 13:06 .newsrc -rw-r--r-- 1 abc3f usr 800 Jun 6 14:28 .profile -rw-r--r-- 1 abc3f usr 1424 Jun 6 14:28 .variables.ksh drwxr-xr-x 2 abc3f usr 144 Jun 9 16:21 News drwxr-xr-x 4 abc3f usr 144 Apr 16 14:34 docs drwxr-xr-x 2 abc3f usr 64 Jun 3 10:34 progs.f -rw-r--r-- 1 abc3f usr 3289 Nov 9 10:09 junk Column 1: Ten characters giving file information; first character (-, l or d) is type of file; remaining nine are permissions. The first entry will generally be one of the following: d = directory l = link to a file - = ordinary file The next nine characters specify the file permissions given to user abc3f (first three characters), the group to which abc3f belongs (next three), and the other users on the system (last three). At UVa, the group to which the user belongs will gen- erally be the same as all other users. On the RS/6000s, it is possible to give a selected group of users permissions to a file; see Appendix C, ``Setting File Permissions with Access Control Lists.'' The permission characters are as follows: r for read w for write x for execute for permission denied If all permissions are given for a file, these entries would be rwxrwxrwx which gives the user, group and other read, write and execute permissions. For more information, see the section ``Setting File Permissions with chmod.'' Column 2: links; for a file, this is the number of directories it is in; for a directory, it is the number of directories it is in (its parent and itself) plus the directories under it. Column 3: owner of file. U-002 Introduction to the UNIX Operating System 9 Column 4: group to which owner belongs. Column 5: number of bytes (characters) in the file. Column 6: date file was last modified. Column 7: time file was last modified. Column 8: file name. Setting File Permissions with chmod One way to set the permissions on files and directories is with the chmod command. The command syntax is as follows: chmod mode filename where mode is a string of users and permissions; the default permission is read for everyone. filename is the name of the file whose permissions are to be changed. The example shown below gives mode as a string defined to be who_permission where who is u = user (abc3f in the example above) g = group (usr in the example above) o = other a = all (default) and + = gives permission - = denies permission and permission is r = read w = write x = execute Example 1: You want to remove read permission on a file named ``personal'' from everyone except you. Use the command: chmod go-r personal Example 2: You want to make a command file called ``printit'' readable and executable by everyone. Use the command: chmod ugo+rx printit or chmod a+rx printit U-002 Introduction to the UNIX Operating System 10 On the RS/6000s, you can give permissions to a selected group of users. See Appendix C, ``Setting File Permissions with Access Control Lists.'' Some Special Characters Some characters have special meaning to the UNIX system. These can be used so that you do not need to type long names of directories and files, or they can be used to ``wildcard'' (match more than one) directory and file names. Some of these characters are defined below. ____________________________________________________________________________ |File Expansion Characters Explanation | |___________________________________________________________________________| | . Current directory | | .. Parent of current directory | | ~/ The system will expand ~ before / to the HOME | | directory of the user. | | ~login_ID The system will expand ~ before a login_ID to the | | HOME directory of login_ID, using information from| | the /etc/passwd file. | | * Matches 0 or more characters; does not match a | | leading period (.) | | ? Matches any single character | | [...] Matches one character in a specification where ...| | can be a range (e.g., a-z, 0-9) or a list (e.g., | | aeiouy) or a combination of both (e.g., aeiouy0-9 | | matches any vowel or digit). | |___________________________________________________________________________| INPUT/OUTPUT AND REDIRECTION One of the features provided by the UNIX operating system is the abili- ty to redirect output from a command to a file or to another command. The characters used for redirection are: ________________________________________________________________ |Redirection Character Use | |_______________________________________________________________| | > Write output from a command to a file | | >> Append output from a command to a file | | < Read input to a command from a file | | | Send (``pipe'') output from one com- | | mand to another | |_______________________________________________________________| Combining redirection characters with the files called standard input (the keyboard, file descriptor 0) and standard output (the screen, file descrip- tor 1), standard error (file descriptor 2), and the command tee, you will have the tools and symbols you need to make use of redirection. Study the examples below to get some ideas. 1. To use electronic mail to send a letter you have prepared with an edi- tor and saved as a file called ``welcome.letter'' to U-002 Introduction to the UNIX Operating System 11 xyz3g@virginia.edu: mail xyz3g@virginia.edu errors 3. To send the output from the ls command to the file ``ls.output'' rather than to the screen: ls >ls.output 4. To join ``file1'' and ``file2,'' send the output to the sort command and then put the sorted output into file ``sorted.big.file'': cat file1 file2 | sort >sorted.big.file 5. To sort another file and append the output to ``sorted.big.file'': sort file3 >>sorted.big.file 6. To send output from the sort command both to a file ``new.file'' and to the screen: sort filename | tee new.file TAILORING UNIX Special Files Using some special UNIX files, it is possible to customize your UNIX environment. You can change the names of commands as well as specify which command options are selected. Some commands, like mail and rn (to read USENET news), check for a special file, often called a reconfiguration file (notice the letters ``rc'' at the end of many filenames) from which they get initialization information. The following are some of the special files you may see when you issue the ls -A command. .profile sets user's environment at login (see below) .history stores commands you have issued (see below) .mailrc sets electronic mail environment, including mail aliases (see U-010) .newsrc sets USENET news subscriptions (rn command, see U-011) .joverc initializes JOVE editor (see U-003) .exrc initializes Vi editor (see U-004) .kshrc sets user's command aliases, if specified (see below) .forward sends electronic mail to another address (see U-010) .variables.ksh sets values to shell variables U-002 Introduction to the UNIX Operating System 12 Default .profile, .mailrc, .joverc, .variables.ksh and .kshrc files ex- ist, but you can create your own versions of these files to set your ini- tialization preferences. The .history file is created automatically by the Korn shell and the .newsrc file is created by the rn program. You can look at and modify any of these files except the .history file, which is not a text file. More information follows on the .profile, .variables.ksh, .kshrc and .history files, but first it will be useful to know more about UNIX shell variables. Shell Variables The Korn shell sets up some variables called shell variables which are read by UNIX commands. One way that the UNIX environment can be tailored is to change the values of these variables. A complete list of the shell vari- ables set up by the Korn shell can be found on the ksh man page. A shell variable is written in upper-case letters (remember that UNIX is case sensitive) and its value is often a pathname to a directory or file. Many UNIX commands read the value of one or more UNIX shell variables when they execute. For example, full screen editors like JOVE or Vi need to know the type of display you are using, so they read the value of the TERM shell variable to get the information needed for full-screen display. Some shell variables are described below. EDITOR name of editor you use EXINIT string value to set initial specifications for editor Vi HISTFILE name of file in which commands are stored (default is .history) HISTSIZE number of commands stored (default is 128) HOME default is current directory when you log in; e.g., /home/abc3f MAILCHECK time in seconds for system to check for new mail PATH search path used to find executable files (commands) PRINTER path to a printer on the network (RS) PS1 prompt RNINIT string value to set initial specifications for rn program TERM type of terminal you are using ENV specifies file to be executed at shell invocation; good place for command aliases The PATH shell variable has special importance since it names the directories (separated by colons) that the system will search for commands you type. The directories are searched in order from left to right. For example, if you invoke the ls command by typing the complete path /bin/ls, the value of PATH would not be used since there is a / in the command. How- ever, if you type ls, the system searches the directories given in the PATH variable. The first executable file named ``ls'' found in one of the PATH directories will be executed. If no file is found, the error message ksh: ls: not found will appear. To see the current value of the PATH, issue the command: echo $PATH The directory specified by ``.'' represents the current directory. If you create your own executable command files (e.g., C programs or UNIX shell scripts), you could put them in a ``bin'' directory in your HOME directory. To get the system to search that directory, set your PATH value U-002 Introduction to the UNIX Operating System 13 to PATH=${HOME}/bin:${PATH} which will cause the system to search your bin directory before searching other directories. To see the current values of shell variables, issue the command set with no options. Sample .profile and .variables.ksh Files When you log in to a UNIX system at UVa, either the file named .profile or the file named .xinitrc.ksh will be run. The .xinitrc.ksh file is run if you log in using an X terminal. Both the .profile and .xinitrc.ksh files run a file called .variables.ksh which contains settings for the shell vari- ables. You can modify this file to your preferences. The default versions of these files on the RS/6000s are shown below. Note that when a variable is preceded by a dollar sign ($), the current value of that variable will be used. RS/6000 Sample .profile file # Lines beginning with # are comments. # This file is run after you telnet or rlogin to your account. # Your .variables.ksh file will be run by this file to set shell # variables. # The .profile file is NOT run when you log in to an X-terminal. # In that case, the .xinitrc.ksh will run the .variables.ksh. # The following command exports variables set here to your user shell. set -a # This command runs your ".variables.ksh" file. . ${HOME}/.variables.ksh # The following series of commands asks you to enter your terminal type, but # sets it to "vt100" if you hit return. If you are on an RS/6000 console, # your terminal type will be automatically set to "hft". if [ "$TERM" != "hft" ]; then echo '\nEnter terminal type [default is vt100]: \c' read TERM TERM=${TERM:-vt100} fi RS/6000 Sample .variables.ksh File # Lines beginning with # are comments. # This file is run after your ".profile" file or your ".xinitrc.ksh" # (if you are on an X-terminal) and this file will run the .kshrc # file to set command aliases. # Exports settings to your user shell. set -a # Tells the machine where to look for commands and programs PATH=.:${HOME}/bin:${PATH} # To access third party software add the directory to PATH line. # Search order is left to right. For example, to add Mathematica: # PATH=.:${HOME}/bin:${PATH}:/math/bin # Runs the ".kshrc" file. ENV=${HOME}/.kshrc # Tells the mailer where to look for your new mail. MAIL=/usr/spool/mail/$USER U-002 Introduction to the UNIX Operating System 14 # Tells your shell to check for new mail every 120 seconds. MAILCHECK=120 # Sets your default editor for programs (eg., mail) to be jove. EDITOR=/uva/bin/jove # Sets your default editor for programs (eg., mail) to be vi. # This line is currently commented out. #EDITOR=/usr/bin/vi # Sets your default editor for the Korn shell's fc (history) command. FCEDIT=$EDITOR # Sets your default editor for some programs VISUAL=$EDITOR # Causes the vi editor to read in your .exrc for it's settings. EXINIT=':so $HOME/.exrc' # Causes the trn news reader to work correctly TRNINIT='-X' # Sets your default paging viewer for programs (eg., mail) to be "more". PAGER=/usr/ucb/more # Set PRINTER to the name of your default printer. Type "man printers" # to get a list of available printers. PRINTER= After changing your .variables.ksh file, you can activate it by executing it with the command . ./.variables.ksh Sample .kshrc File The Korn shell provides the user with command aliasing, which is a way to rename a command along with your favorite options to a name of your choice. The ENV variable in the .variables.ksh file specifies the file $HOME/.kshrc . The default .kshrc is shown below. RS/6000 Sample .kshrc File # Lines beginning with # are comments. # This file is run after your ".variables.ksh" so it will be run for # all your terminal sessions, including those in xterm windows. # Exports variables set here to your user shell and makes your # command-line editor have emacs-like key sequences. set -a -o emacs # Exports variables set here to your user shell and makes your # command-line editor have vi-like key sequences. It is # currently commented out. #set -a -o vi # Sets the variable "HOST" to be the first part of your current # machine name (eg. kelvin, fulton, faraday, etc.) HOST=`hostname | sed 's/..*//'` # Causes all commands you issue to be stored in the # file ".history" in your home directory. HISTFILE=${HOME}/.history # Sets your command line prompt to the current directory. U-002 Introduction to the UNIX Operating System 15 PS1="${HOST}: \$PWD $ " # Causes you to be prompted before you delete a file or make a # destructive move or copy alias rm='rm -i' alias mv='mv -i' alias cp='cp -i' # Causes "ls" to list all files and directories (including filenames # beginning with a dot) and to mark directories ("/"), executables ("*") # and links ("@"). alias ls='ls -aF' # Causes typing "l" to give you the long listing of all your files and # directories (including filenames beginning with . ). alias l='ls -la' # On an RS6000 console, "stty sane" gets rid of odd terminal behavior. # stty sane # Sets default control keys for terminal commands. stty intr '^C' erase '^H' kill '^X' susp '^Z' To see the current aliases, issue the command alias with no parameters. To execute a new or modified .kshrc file, use the command . ./.kshrc To remove an alias from the current terminal session, use the command: unalias name HOW TO USE COMMAND HISTORY The Korn shell stores the commands you enter in a file named .history. There are two ways to make use of the .history file to re-execute commands you have previously typed. 1. First method: Enter the command history which will produce a list of the sixteen most recent commands you have issued. When you locate the command you want to re-execute, note the number of the command, and enter r command-number U-002 Introduction to the UNIX Operating System 16 2. Second method: This method gives you the opportunity to edit your pre- vious command. For Vi Users: Put set -o vi in your .variables.ksh. Then when you enter (the escape key on your keyboard) followed by the letter k, the most recent command you have executed will appear on the command line. Repeating the letter k will present each command in the .history file in the order from the most recent. You are going up in the file. By typing the letter j , you can go down in the file, provided you are not at the most recent command. The letter h moves the cursor one character to the left on the command line; the letter l moves the cur- sor one character to the right. The arrow keys do not work. For JOVE Users: Put set -o emacs in your .variables.ksh file. (NOTE: jove is not recognized as a command-line editor.) To retrieve com- mands, use CTRL-P to bring back the most recently executed command. After you have brought back at least one command, you can use CTRL-N to get the next command, CTLR-F to go to the right and CTRL-B to go to the left. For either editor: Once you have found the command you want to exe- cute, you can edit it using some of the standard commands for the edi- tor you use. See the ksh man page for a complete list of command-line editor commands. When you have finished editing, enter a Return to ex- ecute the command. JOB CONTROL Background Jobs To run any UNIX command in the background so that you can continue oth- er work at your terminal, append an ampersand (&) to the command. You will immediately be returned to the system prompt so that you can issue other commands. The command jobs will show you the status of your background jobs. If you log out before the process has finished, it will be killed. To avoid this, precede the command with nohup (no hangup). The syntax for the complete command is nohup command and arguments& If your command has a pipe (|) in it, issuing the command above will not work. Put the command into a file, make the file executable using chmod, then run it by typing the name of the file. To lower the priority of your background jobs, use the nice command described in the table below. You can also specify a time to run your job using the at command. See the man pages on nice and at for more information and usage examples. Finally, on the RS/6000 and Sun computers, if you forget to put a lengthy job in the background, enter CTRL-Z to suspend the job. Then enter bg to put the job in the background; you will then get the system prompt so that you can do other work on the computer. Similarly, if one of your back- ground jobs seems to be running excessively and you suspect it has gone awry, issue the jobs command to get the job number, then regain control of it by putting it into the foreground with fg %job_number. Then you can ter- minate the job with CTRL-C if you want. U-002 Introduction to the UNIX Operating System 17 Job Control Commands ____________________________________________________________________________ | Job Control Commands Result | |___________________________________________________________________________| | at time [command_file] run command_file at specified time | | atq list all at jobs belonging to user | | atrm remove all at jobs belonging to user | | bg [%job_number] put job_number in the background; default is | | job that has been suspended with CTRL-Z | | CTRL-Z Suspend current job | | fg %job_number put job_number in the foreground | | jobs list background jobs | | kill -9 processID terminates process number processID, which is | | determined by issuing ps command | | nice command run command at lower priority; use for CPU- | | intensive programs | | nohup command no hang-up; use to keep a background job from | | terminating at logout | | ps [-eflux] lists running processes | | e show all processes (RS) | | f full listing (RS) | | l long listing | | u show user ID (Sun) | | x show processes with no controlling ter- | | minal | |___________________________________________________________________________| Terminating Runaway Processes Occasionally you may lose keyboard control of your terminal. If this happens, go to another terminal and log on to the same computer you were logged on to when you lost control. Issue the command: ps -fu login_id (RS) or ps -ux | grep login_id (Sun) The screen (on an RS) for user abc3f with a runaway session might look simi- lar to the figure shown below. UID PID PPID C STIME TTY TIME CMD abc3f 34983 23462 0 May 08 pts/28 0:00 -ksh abc3f 43708 41403 0 15:51:47 pts/24 0:00 -ksh abc3f 54257 43708 40 16:07:52 pts/24 0:00 ps -fu abc3f Each login session can be identified by a line ending in ``-ksh.'' The current session will be the one with the higher process number (PID 43708 in the listing above); therefore, the runaway session above has PID 34983. Terminate the session by issuing the command kill -9 34983 HOW TO GET HELP The best sources of information (in addition to this document, of course) are: o On the RS/6000 computers, there is a menu-driven help command providing information on how to get both on-line and off-line assistance. U-002 Introduction to the UNIX Operating System 18 o Call 982-4720 between 8:30 A.M. and 5:00 P.M. to talk to a UNIX consul- tant. o Send electronic mail to consult@virginia.edu to ask a question by mail or to suggest@virginia.edu to make a suggestion. o U-001, ``UNIX Resource List,'' which contains information on where to get help (both on-line and written) as well as a list of available software. o The command accnews provides some on-line information about Academic Computing and the services it provides. o The command hints accesses the /help/hints directory that is described below. o The directory /help has up-to-date information on the operating system, documentation and software. The subdirectories of /help are: /docs which contains all of the locally written UNIX documentation for on-line referral. Printed copies of these documents are available from the public microcomputer facilities and ITC in the basement of Gilmer Hall. /hints which contains files and directories with hints for using various software packages that are installed on the UNIX systems. See the file software.status for a list of software and the machines on which it is installed. o Standard UNIX on-line documentation is available for all commands using the man command. See Appendix B for a description of the command. On the RS/6000s, there is an InfoExplorer program from which documenta- tion and other help can be obtained. The InfoExplorer was designed to work best within the X Window System and is cumbersome when accessed outside X. If you are on a terminal that runs the X Window System, issue the following commands from an X window: xhost full-RS/6000-name rlogin full-RS/6000-name Complete the login process on the remote RS/6000. Then enter: TERM=xterm DISPLAY=full-name-of-machine-running-X:0 To begin the InfoExplorer, enter the command: info There is help on how to use the InfoExplorer within the program. U-002 Introduction to the UNIX Operating System 19 Appendix A: Printing Commands The following chart includes some of the ways to send your output to a printer. As for most UNIX commands, output from a command can be sent directly to a printer by using the ``pipe'' to redirect the output, bypass- ing the need to place output into a file before printing it. For example, you could send the output from the ls command directly to a printer with the command: ls | lpr ____________________________________________________________________________ | Printing Commands Result | |___________________________________________________________________________| | enscript filename send to Apple LaserWriter printer; some for- | | matting options available. | | | | lpq -Pprinter list print jobs for printer. | | | | lpr -Pprinter send files to printer from Sun or RS comput- | | er. On RS, specify printer by setting the | | PRINTER shell variable in your .profile with | | PRINTER=printer-name. | | | | lprm job_id cancel print job job_id which is obtained | | from the lpq command. | | | | manpage command send a copy of the manual page to default | | printer; printer can be specified with | | -Pprinter_name | | | | man printers return names and locations of public printers | | on UVa's network. | | | |___________________________________________________________________________| U-002 Introduction to the UNIX Operating System 20 Appendix B: Some Utility Commands ____________________________________________________________________________ | Utility Commands Result | |___________________________________________________________________________| | cal month year return a calendar for month (digit 1-12) and | | year (4 digits) | | | | calendar read a file named ``calendar'' in your HOME | | directory containing dates and events; system | | sends daily reminders for current dates via | | electronic mail | | (-clist | | cut |-flist filename return list of columns or fields from | | ( filename | | | | date return date and time of day | | | | df disk free; return available disk space in ki- | | lobytes (Sun) or i-nodes and kilobytes (RS) | | | | du directory disk usage; return number of blocks used by | | directory | | | | file filenames Show the type of a file (e.g., ascii, direc- | | tory, data, C program, etc.) | | | | finger return information on machine users | | | | man [-k] command return a copy of the manual page for command; | | with -k, does a keyword search | | | | paste file1 file2 Concatenate corresponding lines of files by | | joining them with a tab character | | | | namtest machine return IP address of machine | | | | rlogin machine log in to remote UNIX machine | | | | sort file sort file in ascending order; many options | | available | | | | spell filename return misspelled words | | | | stty return terminal status; can be used to modify | | terminal options | | w return who is doing what on the system | | | | whence command list full path to command, provided that path | | specified in the PATH shell variable | | | | who list who is logged on to the system | | | | whois searc_string return information from UVa's database | |___________________________________________________________________________| U-002 Introduction to the UNIX Operating System 21 Appendix C: Setting File Permissions with Access Control Lists On the RS/6000 computers only, there is an additional method for set- ting file permissions using an Access Control List. This method is useful to give file permissions to a specified group of users. For example, if a research project leader (user ``abc3f'') has a file named ``research.part1'' to which he wants several others to have write per- mission, he could follow these steps: Step 1: Take away all permissions on ``research.part1'' from other users by issuing the following command: chmod og-rwx research.part1 Step 2: Give the list of research collaborators read and write permission on the file by issuing the command: acledit research.part1 The acledit command uses the default editor for the system, or reads the value of the EDITOR shell variable set by the user. A screen similar to the one below will appear: attributes: base permissions owner(abc3f): rw- group(usr): --- others: --- extended permissions disabled Using editor commands, change the word under extended permissions from disabled to enabled and then add lines to make the file similar to the one below: attributes: base permissions owner(abc3f): rw- group(usr): --- others: --- extended permissions enabled permit rw- u:login_1 permit rw- u:login_2 permit rw- u:login_3 where the actual login IDs for the research collaborators appear where login_1, login_2 and login_3 appear above. Exit the editor in the usual way. Step 3: The acledit command will prompt with Should the modified ACL be applied? (y) Answer with y or n as appropriate and the process is complete. Now the three collaborators can access the file. Step 4: To give the same access control list to another file, say ``research.part2,'' issue the following command: aclget research.part1 | aclput research.part2 and all the permissions that are on ``research.part1'' will be U-002 Introduction to the UNIX Operating System 22 copied to the file ``research.part2.'' For more information, see page 364ff of AIX General Concepts and Pro- cedures for the IBM RISC System/6000 and the man pages for the commands acledit, aclget and aclput.