AAnn IInnttrroodduuccttiioonn ttoo UUnniixx _L_a_s_t _E_d_i_t _M_a_r_c_h _2_4_, _1_9_9_2 Reg Quinton, Weimei Shyr, and Lori Corrin Computing and Communications Services The University of Western Ontario London, Ontario N6A 5B7 Canada CCoonntteennttss (1) History and Goals (2) Command Line Interpretors (Shells) (3) Customizing the Csh Environment (4) Help -- where to find it (5) The Unix File System (6) Basic Unix Utilities (7) Communications Utilities (8) Editors (ed, ex, vi, emacs) (9) Advanced Topics: Redirection, Pipes, Job Control 11 UUWWOO//UUnniixx 11.. HHiissttoorryy aanndd GGooaallss Unix is a word play on MULTICS and owes much: (1) The filesystem and interface to it. (2) Command line interpretors are user processes. MULTICS tried to be all things to all people. Unix has more modest goals -- to be a programmer's environment for getting things done. Unix is over 20 years old and still developing (eg. threads, Mach, C++, X11, Plan 9, etc.). First version at Bell Labs in 1969 by Ken Thompson on a PDP-7, later joined by Dennis Ritchie (the authors of C). Developed as a "word processor" -- a feint to avoid the bad taste left by MULTICS. First public version released in 1971 (time on Unix starts at Jan 1, 1970, 00:00 GMT; see ccttiimmee((33))). Unix Time Sharing System, Sixth Ed. (aka V6) first widely available in 1976. Seventh Ed. (aka V7 and UNIX/32V) 1978 designed as a portable system to run on a variety of plat- forms. Early releases from Bell Labs _g_i_v_e_n to other researchers in source form! Berkeley Software Distribution (BSD) started with UNIX/32V. Development on 32 bit machines with virtual memory made it possible to do lots! At about 1985 ATT was split up (anti-trust laws, Reagan's notion of free enterprise). This allowed for the first com- mercialization of Unix by ATT. Two important Unix streams are ATT System V (Release 4, not to be confused with 5th Ed.) and BSD (Release 4.3 Reno). UUWWOO//UUnniixx 22 Political streams are Open Software Foundation (OSF includes IBM, Dec, etc.) and Unix International (Sun and ATT). Both streams have a common source and owe much to one another. Lately a third party, ACE (the Advanced Computing Environ- ment). Today Unix runs on a very wide set of platforms -- AT through 386/486 class PC's, Motorola, Dec VAX, IBM main- frames, etc. The principal virtue of Unix is that it is open and avail- able on all these machines. The last system you'll ever need to learn or know! 33 UUWWOO//UUnniixx 22.. CCoommmmaanndd LLiinnee IInntteerrpprreettoorrss ((SShheellllss)) A shell is a command line interpretor that provides an interface to the Unix operating system. A shell is just another process on Unix. This means the Unix kernel needs to be concerned with very few things -- managing I/O, scheduling jobs, IPC. The usual shells are //bbiinn//sshh (the Bourne shell) and //bbiinn//ccsshh (the C shell). Most people use the Csh, system admins pro- gram with sh. The C shell is very common these days (a BSD development). The notion of jjoobb ccoonnttrrooll came with BSD Unix and the C shell, now very common under SysV and Bourne shell. Common extensions are //bbiinn//kksshh (the Korn shell) and //bbiinn//ttccsshh (Tenex shell). Both provide command recall and editting, CCS supports the Tenex shell (it's a free ware extension to Csh and works!). All shells take keyboard input, parse it into an argument list, and invoke utilities. In this course we'll only talk about the Csh. UUWWOO//UUnniixx 44 22..11.. LLooggiinn aanndd LLooggoouutt Users login to a shell. You supply your user identifier and password. EP/IX (julian.uwo.ca) login: rreeggggeerrss Password: Last login: Fri Aug 30 13:15:59 from xchange.ccs.uwo. julian.uwo.ca, EP/IX Version 1.4.1 All Suns are now YP integrated. Passwd and group files are shared. reggers TERM = (vt100) <> [8:36am julian] wwhhooaammii<> reggers [8:38am julian] ppwwdd<> /usr/people/guru/reggers [8:39am julian] llooggoouutt<> shove off reggers One of the first things new users should do is change their password to something memorable but hard for others to guess, see ppaasssswwdd((11)): [8:39am julian] ppaasssswwdd rreeggggeerrss<> 55 UUWWOO//UUnniixx 22..22.. LLooggiinn EEnnvviirroonnmmeenntt When you login you have a current working directory (ie. location in the filing system), a controlling terminal (//ddeevv//ttttyy), and are running a shell (usually //bbiinn//ccsshh or some other if you've changed your shell). [11:48am julian] ppwwdd /usr/people/guru/reggers [11:48am julian] eecchhoo $$SSHHEELLLL /bin/tcsh The C shell, //bbiinn//ccsshh, (and C shell derivatives like tcsh) will execute commands stored in ..ccsshhrrcc and ..llooggiinn. At CCS these files are supplied and you shouldn't need to touch them (but you should read them, become familiar with what they do). These are available in the area /usr/doc/proto And available by anonymous ftp from julian.uwo.ca:~ftp/doc/proto The directory //uussrr//ddoocc is a link to //uussrr//ffttpp//ddoocc. ~~ffttpp is the login directory for user ffttpp (for anonymous ftp). UUWWOO//UUnniixx 66 22..33.. LLooggiinn//LLooggoouutt PPrroobblleemmss TTyyppee ccaassee -- Unix is case sensitive. User "RREEGGGGEERRSS" is not the same as user "rreeggggeerrss". Likewise for passwords. UUppppeerr ccaassee -- If you login as RREEGGGGEERRSS instead of rreeggggeerrss Unix assumes you have an upper case only terminal. All input is translated to lower case, all output to upper case. AAccccoouunntt oovveerrddrraawwnn -- talk to the accounting office. PPaarriittyy -- Some shells are fussy about parity. While the default is eevveenn there have been shells which require nnoonnee (early versions of ttccsshh). TThheerree aarree ssttooppppeedd jjoobbss -- You've left some jobs running and can't logout. Type ffgg to bring these jobs to the foreground. llooggoouutt:: nnoott aa llooggiinn sshheellll -- You're running in a subshell, type eexxiitt to get out. 77 UUWWOO//UUnniixx 22..44.. CCsshh ccoommmmaanndd lliinnee iinnppuutt The shell prompts and you give commands [10:54am julian] llss Makefile RCS README paper sizing slides title Commands look like _v_e_r_b _[ _a_r_g_u_m_e_n_t_s _] The shell executes the verb (or command) by (1) construct an argument vector aarrggvv from the command line (after expanding meta characters) (2) sets up ssttddiinn, ssttddoouutt, and ssttddeerrrr (for input and out- put to the command) for the child. (3) runs the appropriate child process (ffoorrkk((22)) and eexxeecc((22))) with the argument and environment vectors (aarrggvv and aarrggpp). (4) waits for child process to terminate (wwaaiitt((22))). UUWWOO//UUnniixx 88 22..55.. CCsshh mmeettaa cchhaarraacctteerrss The Csh expands meta characters into file names, for example [10:59am julian] eecchhoo ** Makefile RCS README paper sizing slides title Note that Csh expands the wild card character when it con- structs the argument vector. _I_t _i_s_n_'_t _t_h_e _c_o_m_m_a_n_d _t_h_a_t _d_o_e_s _t_h_a_t! Unlike Vax/VMS. ** matches any string (in a file name) ?? matches one character (in a file name) [[aabbcc]] matches any of the characters specified [[aa--zz]] matches any in the range specified ~~uusseerr the home directory of the specified user (or your home home directory if none mentioned). 99 UUWWOO//UUnniixx 33.. CCuussttoommiizziinngg tthhee CCsshh EEnnvviirroonnmmeenntt The Csh environment can be customized to suit your needs. You can customize the environment by instructing the Csh from ..llooggiinn and ..ccsshhrrcc. Our intention at CCS is to provide you with a fully func- tional environment where you _c_a_n customize your environment if you need to. However, we're trying to give you an envi- ronment that you _d_o_n_'_t _n_e_e_d to customize. It is difficult, if not impossible, to support many differ- ent environments. Consultants often find that users have problems because they have deviated from the standard envi- ronment (and no longer have a good search path, or the right variables set, or etc.). BBeewwaarree:: IInn sshhoorrtt,, ddoonn''tt ccuussttoommiizzee yyoouurr eennvviirroonnmmeenntt uunnlleessss yyoouu kknnooww wwhhaatt yyoouu''rree ddooiinngg!! UUWWOO//UUnniixx 1100 33..11.. CCsshh CCuussttoommiizziinngg CCoommmmaannddss 33..11..11.. aalliiaass _v_e_r_b _v_a_l_u_e AAlliiaass is a bbuuiillttiinn command. You can alias new commands to existing ones. For example, [2:19pm julian] aalliiaass bye exit cp cp -i delete rm dir ls ed emacs ls ls -lasFC !* | more mv mv -i rename mv plotq lpq -Pplotter; lpq -Pgplotter; lpq -Psplotter type more unshar sed "1,/^#/d" !* | sh [2:19pm julian] aalliiaass pprriinntt llpprr Commands like ccpp, mmvv and rrmm take a flag to help protect you from making mistakes. [2:19pm julian] aalliiaass ccpp ccpp --ii [10:28am julian] ccpp ffoooo22 ffoooo overwrite foo? yy 1111 UUWWOO//UUnniixx 33..11..22.. sseett _v_a_r_i_a_b_l_e_[_=_v_a_l_u_e_] SSeett is a bbuuiillttiinn command. C shell variables control the behaviour of the Csh (eg. "history" defines the number of commands kept in the history stack). Usually these vari- ables are set in .cshrc. [12:33pm julian] sseett ..._e_t_c_. cwd /usr/people/guru/reggers edit emacs history 40 home /usr/people/guru/reggers noclobber notify path (/usr/people/guru/reggers/bin ... _e_t_c_. prompt [%S%t%s %m] term xterm ..._e_t_c_. [12:46pm julian] sseett pprroommpptt==""%% "" % eecchhoo $$tteerrmm xterm The nnoocclloobbbbeerr prevents me from wiping out files with redi- rection, nnoottiiffyy tells me when background jobs are done, hhiiss-- ttoorryy to maintain a history of what's been done. Note: you refer to variable values with the dollar notation. UUWWOO//UUnniixx 1122 33..11..33.. sseetteennvv _v_a_r_i_a_b_l_e_[_=_v_a_l_u_e_] SSeetteennvv is a bbuuiillttiinn command. Environment variables are dif- ferent from C shell variables. These are passed on to all children (ie. commands) which may use them (eg. lpr honors the PPRRIINNTTEERR environment variable). C shell variables are specific to the C shell and cannot be passed on to children. By convention environment variables are usually upper case, C shell variables are usually lower case. [12:44pm julian] pprriinntteennvv ..._e_t_c_. EDITOR=emacs HOME=/usr/people/guru/reggers HOST=julian.uwo.ca MANPATH=/ccs/export/man PATH=/usr/people/guru/reggers/bin:... _e_t_c_. PRINTER=draft SHELL=/usr/local/tcsh TERM=xterm TZ=EST5EDT USER=reggers TERMCAP=xterm|... _e_t_c_. [12:46pm julian] sseetteennvv PPRRIINNTTEERR aappppllee 1133 UUWWOO//UUnniixx 33..11..44.. TThhee UUnniixx PPrroocceessss EEnnvviirroonnmmeenntt All processes (or jobs) have environment variables (_f_u_n_d_a_- _m_e_n_t_a_l to Unix). Csh lets you define the environment you pass on to the jobs you run. C programs always have this fragment: main(argc,argv,argp) int argc; /* argument count */ char *argv[]; /* argument vector */ char *argp[]; /* environment vector */ You refer to environment variables with the dollar notation. [12:46pm julian] eecchhoo $$PPRRIINNTTEERR apple Csh variables are not passed on to processes (or jobs) that are run from the Csh. Hence, the file ..ccsshhrrcc which is executed for each instance of the Csh. That's how you share Csh variables, aliases, etc. UUWWOO//UUnniixx 1144 33..11..55.. TThhee CCsshh SSeeaarrcchh ppaatthh The command line you type, eg. [10:41am julian] llss --ll ..llooggiinn 5 -rw-r--r-- 1 reggers 4223 Apr 16 13:58 .login is parsed by the shell into a vector of strings _v_e_r_b _[ _a_r_g_u_m_e_n_t _[ _a_r_g_u_m_e_n_t _._._. _] _] The vveerrbb you've indicated will either correspond to a Csh bbuuiillttiinn command (ie. the shell does it) or to some exe- cutable program within your _s_e_a_r_c_h _p_a_t_h. [10:41am julian] wwhhiicchh pprriinntteennvv /usr/ucb/printenv [10:44am julian] wwhhiicchh sseetteennvv setenv: shell built-in command. The Csh ppaatthh variable is the _s_e_a_r_c_h _p_a_t_h. This is stored internally in a hhaasshh table (and explains the rreehhaasshh builtin). 1155 UUWWOO//UUnniixx 33..11..66.. BBeewwaarree:: SSeeaarrcchh PPaatthh At CCS we support a search path that gives a BSD rather than SysV feel. Changing the search path can radically change your environment; eg. [10:49am julian] uunnsseett ppaatthh [10:49am julian] wwhhiicchh pprriinntteennvv printenv: Command not found. [10:49am julian] llooggoouutt Or, compare the behaviour of BSD stty to SysV stty. Note that setting your Csh ppaatthh variable will have the side effect of also setting the PPAATTHH environment variable. Many are tightly coupled -- but not all. BBEEWWAARREE:: DDoonn''tt cchhaannggee yyoouurr sseeaarrcchh ppaatthh uunnlleessss yyoouu kknnooww wwhhaatt yyoouu''rree ddooiinngg!!. UUWWOO//UUnniixx 1166 33..11..77.. uummaasskk _n_n_n UUmmaasskk is a bbuuiillttiinn command used to set a file creation mask. A fundamental notion to Unix (all jobs have a file creation mask, just as all jobs have a set of environment variables). The umask is usually set in ..llooggiinn. Note: it's a mask to define what should _n_o_t be allowed. [10:59am julian] uummaasskk 002277 The number is 3 digit octal. The first digit is for the uusseerr((uu)), the second for the ggrroouupp((gg)), and the last for ootthh-- eerrss((oo)). rreeaadd((rr)) access is 4, wwrriittee((ww)) is 2, and eexxeeccuuttee((xx)) is 1. [10:59am julian] uummaasskk 27 [10:59am julian] ttoouucchh ffoooo [10:59am julian] llss --ll ffoooo 0 -rw-r----- 1 reggers 0 May 9 10:59 foo [10:59am julian] uummaasskk 7777 [11:00am julian] ttoouucchh ggoooo [11:00am julian] llss --ll ggoooo 0 -rw------- 1 reggers 0 May 9 11:00 goo Umask 027 (the default at CCS) lets the owner do everything (none of rrwwxx is denied), the group can only read/execute (ww is denied), and others have no access. 1177 UUWWOO//UUnniixx 33..11..88.. ccdd _d_i_r_e_c_t_o_r_y CCdd is a bbuuiillttiinn command. All jobs have a current working directory (where am I in the Unix file system? what does an unqualified file name mean?). This is a fundamental notion of Unix. Two commands for manipulating and displaying your working directory are ccdd to change directory and ppwwdd to print the working directory. [11:08am julian] ppwwdd /usr/people/guru/reggers [11:08am julian] ttoouucchh ffoooo [11:08am julian] llss --ll ffoooo 0 -rw-r----- 1 reggers 0 May 9 11:08 foo [11:08am julian] ccdd //eettcc [11:08am julian] ppwwdd /etc [11:08am julian] ttoouucchh ffoooo touch: could not create foo: Permission denied I cannot create a file in /etc because the directory is pro- tected against me (and others). Your home directory should be protected so you can create files, other directories likely aren't (and shouldn't be). UUWWOO//UUnniixx 1188 33..11..99.. ssttttyy The ssttttyy command defines terminal characteristics (eg. what character does a rubout?). This is usually done once in ..llooggiinn. [12:53pm julian] ssttttyy eevveerryytthhiinngg new tty, speed 9600 baud, 70 rows, 80 columns even odd -raw -nl echo -lcase -tandem -tabs -cbreak crt: (crtbs crterase crtkill ctlecho) -tostop -tilde -flusho -mdmbuf -litout pass8 -nohang -pendin -decctlq -noflsh erase kill werase rprnt flush lnext susp ... _e_t_c_. ^? ^U ^W ^R ^O ^V ^Z/^Y ... _e_t_c_. [12:53pm julian] ssttttyy eerraassee ^^HH Note the control characters ^^CC for interrupt, ^^DD for end of file, ^^?? for delete character, ^^UU for delete line, ^^RR for retype, ^^SS,,^^QQ for gag, ^^OO for stop output. These are very familiar to Digital users (eg. Vax/VMS). One important character is ^^ZZ for suspend process (_n_o _i_t _d_o_e_s_n_'_t _m_e_a_n _e_n_d _o_f _f_i_l_e_!). Unlike Vax/VMS. 1199 UUWWOO//UUnniixx 33..11..1100.. ttsseett The other terminal manipulation command is ttsseett -- this is what prompts you for your terminal type at login: TERM = (vt100) Tset does some setup and, with some work, defines the envi- ronment variable TERM which is required for full screen applications like vi and emacs -- they have to know the ter- minal type. From .login eval `tset -s -Q -I '?'$TERM` BBEEWWAARREE:: DDoonn''tt mmuucckk wwiitthh tthhee ssttttyy aanndd ttsseett iinn yyoouurr ..llooggiinn;; yyoouu ccaann ggeett iinn sseerriioouuss ttrroouubbllee!!. UUWWOO//UUnniixx 2200 33..22.. CCoonnffiigguurraattiioonn FFiilleess By convention, startup and customization files are found in the user's login directory and hidden as "dot" files. Within CCS we provide new users with most of these. ..ccsshhrrcc each instance of /bin/csh will execute the commands in .cshrc. This means that they're executed when you login, also when you start up Csh (eg. from within Mail). Put sseett commands here. ..llooggiinn executed once at login after .cshrc. Set some environ- ment variables, and terminal hassles. Put sseetteennvv com- mands, ssttttyy, and ttsseett commands here. ..llooggoouutt executed at logout. For example, [12:10pm julian] ppaaggee ..llooggoouutt echo shove off $user ..aalliiaasseess Within CCS the supported .cshrc will source the com- mands in .aliases. This makes it possible for users to customize their environment while preserving all of .login and .cshrc. ..ffoorrwwaarrdd direct your mail to some other site. For example, [12:11pm chaplin] ppaaggee ..ffoorrwwaarrdd reggers@uwovax ..mmaaiillrrcc customize your mail environment. Define mailing lists, editors, etc. 2211 UUWWOO//UUnniixx ..rrhhoossttss specify other systems where the same user can rlogin (rsh and rcp) without going through Password: prompt- ing. For example, [12:10pm julian] ppaaggee ..rrhhoossttss grafxa.uwo.ca reggers grafxb.uwo.ca reggers julian.uwo.ca reggers shadow.ccs.uwo.ca reggers myst.ccs.uwo.ca reggers hadrian.ccs.uwo.ca reggers icarus.ccs.uwo.ca reggers hydra.uwo.ca reggers NNoottee:: there are some security problems with this file (eg. don't let anyone write to it!). UUWWOO//UUnniixx 2222 44.. HHeellpp ---- wwhheerree ttoo ffiinndd iitt Most Unix systems usually have a full set of on line manuals organized in sections as: 1. User Commands (eg. mail) 2. System Calls (eg. getuid) 3. Library Routines (eg. sqrt) 4. Devices/Special Files (eg. tty) 5. File Formats (eg. a.out) 6. Games (eg. banner) 7. Miscellaneous (eg. filesystem) 8. Systems Administration (eg. fsck) These correspond to the directories /usr/man/man{1-8} and /usr/man/cat{1-8} (source and output of manuals). But watch out for System V machines. As well, people often store locally developed software into a local manual section -- section ll. 2233 UUWWOO//UUnniixx 44..11.. HHeellpp CCoommmmaannddss hheellpp some Unix systems have an on line help system (espe- cially System V machines). On BSD system this is usu- ally just a hint to read the manuals. mmaann _e_n_t_r_y display the manual page entry for some entry. mmaann --kk _t_o_p_i_c what manual pages are about a particular topic? Ie. look up this topic in the index. The command aapprrooppooss, if it exists, does the same thing. wwhheerreeiiss _f_i_l_e show locations of a file (actually this only searches a few places, not the entire file system). wwhhiicchh _c_o_m_m_a_n_d when I type a command which one am I using? UUWWOO//UUnniixx 2244 mmaaiill _p_o_s_t_m_a_s_t_e_r_, _u_s_e_n_e_t_, _c_c_s_, _t_h_u_g_s You can usually get help by E-mail. The ppoossttmmaasstteerr answers questions about mail, uusseenneett for news, ccccss should get help from the consultants desk, and tthhuuggss is the Unix group. PPnneewwss Post gripes, questions, etc. to uuwwoo..ccccss..ttaallkk or uuwwoo..ccoommpp..uunniixx. Alternatively, try ppoossttnneewwss. You can even mmaaiill to uuwwoo..ccccss..ttaallkk -- your mail will be posted to the group. ccdd //uussrr//ddoocc On line documentation is stored here. Start with the README. ccdd //uussrr//ddoocc//FFAAQQ On line Frequently Asked Questions (or FAQ's) are stored here. Start with the README and the files in uunniixx--ffaaqq. 2255 UUWWOO//UUnniixx 55.. TThhee UUnniixx FFiillee SSyysstteemm The Unix file system is a rooted tree of directories and files. A directory is a special file that will contain links (or pointers) to other files and directories. 55..11.. FFuunnddaammeennttaallss Files are allocated space (called iinnooddeess) on the disk. aattttrriibbuutteess Inodes have _a_t_t_r_i_b_u_t_e_s -- size, date, owner, group, protection, etc. nnuummbbeerrss Inodes are nnuummbbeerreedd. There is no name or place in the directory tree as an attribute of the inode. ccoonntteennttss Inodes have _c_o_n_t_e_n_t_s or data. lliinnkkss Inodes are _l_i_n_k_e_d into directories. The directory entry contains the _f_i_l_e _n_a_m_e and a pointer (or _l_i_n_k) to the inode number. UUWWOO//UUnniixx 2266 55..22.. LLiinnkkss aanndd NNaammeess Note, the _n_a_m_e is not an attribute of the file! When you create a file (eg. by ttoouucchh((11))) you (1) allocate an inode for the file contents and attributes. (2) create a link in a directory to give a file name to the inode. An inode can have several links. An inode is removed (in the sense of disk space retrieved) when the link count is zero. The rrmm((11)) command doesn't remove files, it unlinks them. [9:42am julian] llss --ll ffoooo 1 -rw-r----- 1 reggers 33 May 10 09:42 foo [9:43am julian] llnn ffoooo ggoooo [9:43am julian] llss --ll ggoooo 1 -rw-r----- 2 reggers 33 May 10 09:42 goo [9:43am julian] rrmm ffoooo [9:48am julian] llss --ll ggoooo 1 -rw-r----- 1 reggers 33 May 10 09:42 goo The mmvv((11)) command doesn't move files, it links and then unlinks them. 2277 UUWWOO//UUnniixx 55..33.. TThhee CCuurrrreenntt WWoorrkkiinngg DDiirreeccttoorryy File specifications are either fully qualified or rely on the notion of the _c_u_r_r_e_n_t _w_o_r_k_i_n_g _d_i_r_e_c_t_o_r_y. This is _f_u_n_d_a_- _m_e_n_t_a_l to Unix and applies to _a_l_l processes (eg. your shell or the cchhmmoodd((11)) command). The login process sets your current working directory to your login directory (as specified in //eettcc//ppaasssswwdd). [11:19am julian] ppwwdd /usr/people/guru/reggers [11:19am julian] eecchhoo $$ccwwdd /usr/people/guru/reggers [11:19am julian] ttoouucchh ffoooo [11:28am julian] llss --ll ffoooo 0 -rw-r----- 1 reggers 0 May 9 11:28 foo [11:28am julian] llss --ll //uussrr//ppeeooppllee//gguurruu//rreeggggeerrss//ffoooo 0 -rw-r----- 1 reggers 0 May 9 11:28 /usr/people... In the first case the current working directory is assumed, in the second none is assumed. It's Unix, not the shell, that takes care of resolving file names. UUWWOO//UUnniixx 2288 55..44.. DDoott ddiirreeccttoorriieess Each directory has two special subdirectories -- "." is a link to the directory, ".." is a link to the parent of the directory. These redundant links help to hold the file sys- tem together (so that it can be recovered when a link is broken). They also help for walking around within the tree. [11:28am julian] ppwwdd /usr/people/guru/reggers [11:29pm julian] llss --ll total 561 3 drwxr-xr-x 17 reggers 3072 May 8 15:04 ./ 1 drwxrwxr-x 10 root 512 Apr 26 13:50 ../ ..._e_t_c_. [11:35am julian] ccdd .... [11:35am julian] ppwwdd /usr/people/guru [11:35am julian] ccdd .. [11:35am julian] ppwwdd /usr/people/guru [11:35am julian] ccdd ..//rreeggggeerrss [11:36am julian] ppwwdd /usr/people/guru/reggers 2299 UUWWOO//UUnniixx 55..55.. DDoott iiss aa rreeaall ffiillee A lot of people think that "." and ".." are meta syntactic notions of the Csh -- they are real files in the filing sys- tem. Compare with the Csh notion "~_u_s_e_r" -- the home directory of a particular user. [11:22am julian] eecchhoo .... .. [11:22am julian] eecchhoo ~~ /usr/people/guru/reggers Dot directories are a fundamental notion of the Unix filing system, and processes can use them; they're really there! There is no file called ~~rreeggggeerrss; that's only a notion of the shell. Compare with ..llooggiinn. UUWWOO//UUnniixx 3300 55..66.. DDiirreeccttoorryy DDeelliimmiitteerrss Unix file names are arbitrary strings of characters -- watch out for the file called "*". The character "/" is _r_e_s_e_r_v_e_d as a delimiter for directories. Compare foo/bar with foo.bar foo/bar The file named bbaarr within the directory called ffoooo within the current working directory. foo.bar The file named ffoooo..bbaarr in the current working direc- tory. In the first case you have two files, in the second only one. Note you can have files with lots of dots in the them; eg. .login.old. Compare with some systems where there is a notion of a file-name and file-extension. The _o_n_l_y special character is the directory delimiter. But watch out for shell meta characters when specifying a file name! eg. you can have a file called ~~rreeggggeerrss but it is hard to talk about with the Csh. 3311 UUWWOO//UUnniixx 55..77.. RRoooott The root of the Unix file system is the directory "/". A fully qualified file specification starts at the root of the tree. The current working directory is always a fully quali- fied directory specification. [11:36am julian] ppwwdd /usr/people/guru/reggers [11:36am julian] ccdd // [11:37am julian] llss --lldd uussrr 1 drwxr-xr-x 29 bin 1024 Apr 30 10:20 usr/ [11:38am julian] ccdd uussrr [11:39am julian] llss --lldd ppeeooppllee 1 drwxr-xr-x 75 bin 1024 Apr 30 10:20 people/ [11:40am julian] ccdd ppeeooppllee [11:40am julian] llss --lldd gguurruu 1 drwxr-xr-x 39 bin 1024 Apr 30 10:20 guru/ [11:41am julian] ccdd gguurruu [11:50am julian] llss --lldd rreeggggeerrss 1 drwxr-xr-x 24 bin 1024 Apr 30 10:20 guru/ [11:54am julian] ccdd rreeggggeerrss [11:54am julian] ppwwdd /usr/people/guru/reggers UUWWOO//UUnniixx 3322 55..88.. AA QQuuiicckk TToouurr ooff tthhee UUnniixx FFiilliinngg SSyysstteemm Some important directories in the Unix file system (for more detail see the manual page hhiieerr((77))) / The root of the tree. All file specifications start here. This is usually the login directory for the user called rroooott. An important file is vvmmuunniixx -- the Unix kernel! /bin, /usr/bin, /usr/ucb Binaries, eg. cchhmmoodd. These are executeable program areas. Watch out for /bin/mail, /usr/bin/mail, and /usr/ucb/mail. Different programs all with the same name. /dev Devices, eg. ttttyy. This area is only important to the system admin. The Unix filing system is _m_o_u_n_t_e_d on devices. /etc, /usr/etc Various administration files, eg. ppaasssswwdd and ggrroouupp. /lib, /usr/lib Library information, eg. lliibbcc..aa and tteerrmmiinnffoo. /tmp, /usr/tmp Temporary files, eg. while editting, compiling, etc. /usr/local, /usr/local/bin, ... A tree for locally developed tools utilities, etc. /usr/doc Documentation, eg iinnttrroouunniixx..ttxxtt. /usr/man Manuals, eg. ccaatt11//llss..11 and mmaann11//llss..11 (the BSD organiza- tion has manual sources on line). 3333 UUWWOO//UUnniixx /usr/people, /usr/people/guru, /usr/people/guru/reggers The user area, where people are located. /usr/spool For files that are spooled for service. eg. llppdd for the line printer daemon, nneewwss and mmaaiill. /usr/src The Unix tradition is to have sources on line, eg. uussrr..llooccaall is our tree of local software sources. UUWWOO//UUnniixx 3344 55..99.. FFiillee pprrootteeccttiioonnss File protection codes are attached to each file (fundamental to the Unix Filing System). These control rreeaadd((rr)), wwrriittee((ww)), and eexxeeccuuttee((xx)) access to the files. Each of these can be specified for the uusseerr((uu)), ggrroouupp((gg)), and ootthheerrss((oo)). [12:29pm julian] llss --llgg ppaappeerr 74 -rw-r----- 1 reggers guru 75742 May 9 12:17 paper The file belongs to user rreeggggeerrss and group gguurruu. The various protections are: User: rw- The user can read and write the file. It isn't exe- cutable. Group: r-- Anyone in group gguurruu can read the file. They cannot write, they cannot execute. Others: --- Others have no access at all. NNoottee:: to delete a file you have to write into the directory (to create a link). 3355 UUWWOO//UUnniixx 55..1100.. CChhaannggiinngg pprrootteeccttiioonnss Changing file protections is done with cchhmmoodd((11)) and you can only do this to your files. [12:31pm julian] cchhmmoodd oo++rr ppaappeerr [12:34pm julian] llss --llgg ppaappeerr 74 -rw-r--r-- 1 reggers guru 75742 May 9 12:17 paper Your default protection mask can be changed with uummaasskk. [2:53pm julian] uummaasskk 002277 [2:53pm julian] ttoouucchh ffoooo [2:53pm julian] llss --ll ffoooo 0 -rw-r----- 1 reggers 0 Dec 31 1969 foo [2:53pm julian] uummaasskk 007777 [2:54pm julian] ttoouucchh ggoooo [2:54pm julian] llss --ll ggoooo 0 -rw------- 1 reggers 0 May 9 14:54 goo [2:55pm julian] uummaasskk 077 The default uummaasskk supplied by CCS is 002277 -- this gives the group some access, but other no access. UUWWOO//UUnniixx 3366 66.. BBaassiicc UUnniixx UUttiilliittiieess 66..11.. AAcccceessss ttoo SSyysstteemm llooggiinn [[_u_s_e_r]] login to system, this terminates current session. ssuu [[_u_s_e_r]] substitute user id. Temporarily become specified user. If no user id given, then become rroooott. A Password: prompt, of course. llooggoouutt terminate login session. eexxiitt terminate shell, if this is the login shell then logout. 3377 UUWWOO//UUnniixx 66..22.. DDiirreeccttoorryy CCoommmmaannddss llss [[_d_i_r]] list contents of directory. If none specified then list current working directory. ccdd [[_d_i_r]] change current working directory. To $$hhoommee if none specified. ppwwdd print current working directory (where am I?). mmkkddiirr _d_i_r make a directory. rrmmddiirr _d_i_r remove a directory (it has to be empty). mmvv _f_i_l_e _[ _f_i_l_e _._._._] _d_i_r move file(s) into directory. llnn _f_i_l_e_1 _f_i_l_e_2 make a directory entry _f_i_l_e_2 -- a link to _f_i_l_e_1. UUWWOO//UUnniixx 3388 66..33.. UUsseerr pprrooffiillee ppaasssswwdd [[_u_s_e_r]] change password for user (usually just for yourself). See also yyppppaasssswwdd((11)) on YP/NIS environments. cchhsshh [[_u_s_e_r]] change login shell for user (usually just for your- self). eg. to change to ttccsshh. Same as ppaasssswwdd --ss. cchhffnn [[_u_s_e_r]] change personal information (name, phone number, etc.). Same as ppaasssswwdd --ff. ffiinnggeerr _u_s_e_r_[_@_d_o_m_a_i_n_] display personal information (name, phone number, etc.). wwhhoo who is logged in, what are they doing? 3399 UUWWOO//UUnniixx 66..44.. FFiillee DDiissppllaayy To display a file on your terminal there are several com- mands ccaatt _f_i_l_e display file, no pagination. Useless on a fast termi- nal. mmoorree _f_i_l_e display a file a page at a time. Required for fast ter- minals. Interfaces to vvii((11)). There are several variations on mmoorree. PPaaggee is usually the same command (a link). lleessss and ppgg are SysV varia- tions that do the same. pprr _f_i_l_e display file with date, title, page number, etc. This doesn't paginate, pretty useless. But nice for list- ings. UUWWOO//UUnniixx 4400 66..55.. FFiillee MMaanniippuullaattiioonn llss _f_i_l_e list file, the --ll flag will give a long listing with size, date, link count, etc. cchhmmoodd _m_o_d_e _f_i_l_e change the file mode (ie. protection). ccpp _f_i_l_e_2 _f_i_l_e_2 copy file _f_i_l_e_1 to _f_i_l_e_2. mmvv _f_i_l_e_2 _f_i_l_e_2 move (ie. rename) file _f_i_l_e_1 to _f_i_l_e_2. (Or move into directory _f_i_l_e_2). rrmm _f_i_l_e remove (ie. delete) file _f_i_l_e. llnn _f_i_l_e_1 _f_i_l_e_2 make a directory entry _f_i_l_e_2 -- a link to _f_i_l_e_1. (Or link into directory _f_i_l_e_2). ffiillee _f_i_l_e what kind of file is _f_i_l_e? 4411 UUWWOO//UUnniixx 66..66.. FFiillee ttoooollss ggrreepp _s_t_r_i_n_g _f_i_l_e search for string _s_t_r_i_n_g in file _f_i_l_e. The history of this name is the eedd command "gg//_r_e//pp_"_. ddiiffff _f_f_i_l_e_1 _f_i_l_e_2 report differences between files _f_i_l_e_2 and _f_i_l_e_2. hheeaadd _f_i_l_e display head of file _f_i_l_e. ttaaiill _f_i_l_e display tail of file _f_i_l_e (the --ff flag means follow the file). wwcc _f_i_l_e count characters, words and lines in _f_i_l_e. ffiinndd _d_i_r_e_c_t_o_r_y --nnaammee _n_a_m_e --pprriinntt search the entire directory structure looking for a file, print out what you find. Powerful, but a bit cum- bersome. UUWWOO//UUnniixx 4422 66..77.. PPrriinntteerr ccoommmmaannddss There are two different printer systems -- System V and BSD. On CCS systems we support BSD printing (this is by far the most common on campus). Common commands are: llpprr _[ _-_P _p_r_i_n_t_e_r _] _[ _f_i_l_e _] print file on line printer (historically pprr is a pro- gram to create paginated output with titles, etc. and llpprr used pprr to display listings). llppqq _[ _-_P _p_r_i_n_t_e_r _] display contents of printer queue llpprrmm _[ _-_P _p_r_i_n_t_e_r _] _j_o_b delete job number _j_o_b from queue llppcc _[ _-_P _p_r_i_n_t_e_r _] _[ _c_o_m_m_a_n_d _] Line printer control. For the system administrators. 4433 UUWWOO//UUnniixx 66..88.. CCoommppiilleerrss aanndd llaanngguuaaggeess 66..88..11.. CC C programs are stored as files ending in ".c" C compiler is cccc. The mmaakkee((11)) command knows all about building programs from C source: [5:30pm julian] ls test.c test.c [5:30pm julian] make test cc test.c -o test [5:30pm julian] ./test 66..88..22.. FFoorrttrraann Fortran programs are stored as files ending in ".f". For- tran compiler is ff7777. Again, mmaakkee((11)) knows how. [5:31pm julian] ls fort.f fort.f [5:31pm julian] make fort f77 fort.f -o fort [5:31pm julian] ./fort UUWWOO//UUnniixx 4444 66..88..33.. OOtthheerr llaanngguuaaggeess There are lots of programming languags: Shell programming -- system admins often program using //bbiinn//sshh and write scripts. Don't use //bbiinn//ccsshh for writing scripts -- not recom- mended. Yacc -- yet another compiler compiler. Lex -- lexical analysis front end for yacc. Awk, sed -- string manipulation languages. C++, Objective C, Perl, and lots more! 4455 UUWWOO//UUnniixx 66..99.. EEddiittoorrss ((eedd,, vvii,, eexx)) There are a number of editors on Unix (1) eedd//sseedd//eexx//eeddiitt, simple line based editors. (2) vvii, full screen (built on eexx). (3) eemmaaccss, full screen (recommended). To fully describe any editor is a course in itself. Will briefly describe each. See attached quick intro documents. UUWWOO//UUnniixx 4466 66..1100.. eedd//sseedd//eexx//eeddiitt These are line based, easy to use, pretty much the same, and worth knowing. If you can handle eeddlliinn on that other envi- ronment you can handle these. Each runs in command mode. Commands look like _[_<_r_a_n_g_e_>_]_<_c_o_m_m_a_n_d_>_[_<_a_r_g_u_m_e_n_t_s_>_] Commands are usually single characters, eg. dd for delete, pp for print. The range specifies which lines to apply the command, with none given the current line is used. Use line numbers. Special meta characters are available for specifying lines, eg. $$ for last line, .. for current line, and ^^ for first line (cf. meta characters for MMaaiill((11))). 4477 UUWWOO//UUnniixx 66..1111.. EEdd,, aann eexxaammppllee EEdd((11)) is the original line based editor. Some find it irri- tating that it doesn't prompt for commands (Unix is terse). [9:53am julian] eedd ffoooo ?foo _._._. _f_o_o _d_o_e_s_n_'_t _e_x_i_s_t aa _._._. _a_p_p_e_n_d _t_e_x_t ssoommee tteexxtt,, lliinnee 11 mmoorree tteexxtt,, lliinnee 22 . You append text to an empty file (or insert in an existing file) and terminate with a dot. [9:53am julian] eedd ffoooo 11,,$$pp _._._. _p_r_i_n_t _a_l_l _l_i_n_e_s some text, line 1 more text, line 2 11ss//ssoommee//ffiirrsstt// _._._. _s_u_b_s_t_i_t_u_t_e _o_n _f_i_r_s_t _l_i_n_e pp _._._. _p_r_i_n_t _c_u_r_r_e_n_t _l_i_n_e first text, line 1 ww _._._. _w_r_i_t_e 37 qq _._._. _q_u_i_t [9:54am julian] UUWWOO//UUnniixx 4488 66..1122.. vvii Vi was one of the first full screen editors. It's built on eexx so if you can handle that, you can handle vi. But, these days you likely don't know the line editor. Vi operates in one of three modes. CCoommmmaanndd MMooddee In command mode vi is ready to accept commands from the keyboard. Commands are printable characters, usually single characters. In command mode vi will beep at you if you enter a bad command (eg. you mean to enter text but have not instructed vi to do so). EExx MMooddee In Ex Mode (eg. from the ":" command) you can enter any valid eexx command. The command ::wwqq will write your file and terminate yoursession. IInnsseerrtt MMooddee In insert mode (eg. from the "i" command) you enter text and terminate with an _e_s_c_a_p_e character. 66..1122..11.. SSoommee vvii ccoommmmaannddss hh,,jj,,kk,,ll historical commands for left, down, up, right (arrows should work on most terminals). ii,,aa insert and append text. Text is entered and terminated with EEsscc. oo,,OO open a new line after (before) this line. rr,,ccww,,cccc replace single character, word, line. xx,,ddww,,dddd delete character, word, line. 4499 UUWWOO//UUnniixx //_s_t_r_i_n_g search forward for string. ::_c_o_m_m_a_n_d talk to eexx((11)) to execute commands, eg. ::wwqq to write and quit. ZZZZ to write and quit, same as ::wwqq UUWWOO//UUnniixx 5500 66..1133.. EEmmaaccss EEmmaaccss((ll)) is the latest and greatest full screen editors. It's built on a lliisspp interpretor and is very powerful. Vari- ations are jjoovvee (Jonathon's own visual editor) and micro versions. Emacs is freeware and the cornerstone of the GNU project. 66..1133..11.. IInnsseerrtt MMooddee Unlike vvii emacs is _a_l_w_a_y_s in insert mode, any text you type will be inserted into the file. To instruct emacs to do something else requires some effort. Most people find this design better. 66..1133..22.. CCoommmmaannddss Commands are always at least two key strokes and will always require either the ccoonnttrrooll or mmeettaa characters (on most key- boards the meta character is the escape character but X11 terminals have extra characters like meta and alt). The command to exit emacs is cc--xx cc--cc (type control X fol- lowed by control C). Emacs has a builtin help system, start with cc--hh and follow the instructions (easier said than done). 5511 UUWWOO//UUnniixx 66..1133..33.. SSoommee eemmaaccss ccoommmmaannddss cc--xx cc--cc write file and leave emacs. cc--hh get help. cc--hh tt for the emacs tutorial (learn by doing). cc--pp,,cc--nn,,cc--bb,,cc--ff Control sequences for previous/next line, back/forward character (also arrow keys). cc--ss,,cc--rr Search forward, search backwards (not that control S is often the gag character). cc--vv,, mm--vv scroll forward, back. cc--dd,, mm--dd,, cc--kk,, mm--kk Delete character, word, line, sentence. cc--yy yank text, eg. delete and yank to move text. Emacs can support multiple edit sessions, very powerful. UUWWOO//UUnniixx 5522 77.. CCoommmmuunniiccaattiioonnss UUttiilliittiieess 77..11.. SSeennddiinngg MMaaiill To send mail you need to know the person's address. ffiinnggeerr is a useful tool but the best is the telephone. [10:46am julian] mmaaiill ppuurrppllee Subject: just a test Hello how are you today? . Cc: To send mail you supply the address and the mail utility prompts you for a subject and message. For help on address- ing conventions see mmaaiillaaddddrr((ll)). In brief, remote addresses (ie. for people at other sites not on this machine) look like: _u_s_e_r@@_d_o_._m_a_._i_n For example, rreeggggeerrss@@uuwwoovvaaxx..uuwwoo..ccaa. During message composition the dot signals end of the mes- sage (so would ^^DD). It's important not to start a line in the message with a dot. 5533 UUWWOO//UUnniixx 77..22.. RReecceeiivviinngg mmaaiill Csh is usually configured to watch your mail box. At login, or when mail arrives, you'll see: You have new mail To read your mail try the MMaaiill((11)) command (actually there are tons of mail readers, even one within emacs!). [10:47am julian] mmaaiill Mail version 5.3 2/18/88. Type ? for help. "/usr/spool/mail/reggers": 1 messages 1 new >N 1 purple@julian. Fri May 10 09:14 18/760 "ria" & For help on the various mail commands type hheellpp (or look at the manual page). Mail should be easy to use (especially if you've used mail on our Vax/VMS service). UUWWOO//UUnniixx 5544 77..33.. CChhaattttiinngg See ttaallkk((11)) and wwrriittee((11)). The first sets up a split screen where you type in one half, your colleague in the other. 77..44.. FFiillee ttrraannssffeerr See ffttpp((11)) and rrccpp((11)). The first is available on most machines, rcp is restricted to Unix machines under the same management (ie. /etc/hosts.equiv). 77..55.. RReemmoottee llooggiinn See tteellnneett((11)) and rrllooggiinn((11)). The first is available on most machines, rlogin is specific to Unix. 5555 UUWWOO//UUnniixx 77..66.. NNeewwss News or Usenet is a facility for talking to other people about subjects. The other people can be anywhere in the world, and the subjects can be pretty well anything. Usenet is traditionally organized with a tree structure organized by function. One tree for Computer topics, another for Recreational topics, etc. For example ccoommpp: Topics of interest to both computer professionals and hobbyists, including topics in computer science, software source, and information on hardware and soft- ware systems. uuwwoo: The "uwo" news tree is for newsgroups local to the campus of the University of Western Ontario. See espe- cially uuwwoo..ggeenneerraall. The complete set of newsgroups is alt, bionet, bit, can, comp, gnu, misc, news, ont, rec, sci, soc, talk, uwo, and vmsnet. In total there are over 1000 different newsgroups. UUWWOO//UUnniixx 5566 Each newsgroup is a hierarchy of subgroups. For a complete listing and for for information on the groups see _L_i_s_t _o_f _A_c_t_i_v_e _N_e_w_s_g_r_o_u_p_s posted each month to news.announce.newusers, news.lists, news.groups. For example, some groups in the comp.sources tree: comp.sources.amiga Source code-only postings for the Amiga. comp.sources.apple2 Source code and discussion for the Apple2. comp.sources.atari.st Source code-only postings for the Atari ST. And, of course, lots of comp.sources groups for Unix! 5577 UUWWOO//UUnniixx 77..66..11.. RRnn ((RReeaadd NNeewwss)) RRnn is a good news utility. It will setup a history file (..nneewwssrrcc) and subscribe you to all groups. In your first session unsubscribe from many groups. [11:13am julian] rrnn Trying to set up a .newsrc file--running newsetup... Creating .newsrc in /usr/people/guru/purple to be used by news programs. Done. If you have never used the news system before, you may find the articles in nneewwss..aannnnoouunnccee..nneewwuusseerrss to be helpful. See rrnn((ll)) for more information. UUWWOO//UUnniixx 5588 88.. AAddvvaanncceedd TTooppiiccss Some of these topics are fundamental, others advanced. 88..11.. II//OO rreeddiirreeccttiioonn All jobs under Unix should have three I/O units set up -- ssttddiinn (standard input), ssttddoouutt (standard output), and ssttddeerrrr (standard error). These are usually attached to your termi- nal (when you login your shell has these attached to your terminal). When you direct the shell to run a command it sets up ssttddiinn, ssttddoouutt, and ssttddeerrrr for the command and then runs the com- mand. Csh can redirect ssttddiinn, ssttddoouutt, and ssttddeerrrr to files just as easily as to the terminal. [1:11pm julian] ssoorrtt <>nnaammeess..ssoorrtteedd 5599 UUWWOO//UUnniixx 88..22.. RReeddiirreeccttiioonn SSuummmmaarryy _c_o_m_m_a_n_d <_f_i_l_e Run the command with input from file rather than the terminal. _c_o_m_m_a_n_d >_f_i_l_e Run the command with output to file rather than the terminal. _c_o_m_m_a_n_d >>_f_i_l_e Run the command with output to end of file rather than the terminal. _c_o_m_m_a_n_d >&_f_i_l_e Run the command with output and error to file rather than the terminal. The nnoocclloobbbbeerr setting will prevent you from directing output to files that already exist. _c_o_m_m_a_n_d >!_f_i_l_e Run the command with clobber output to file rather than the terminal. UUWWOO//UUnniixx 6600 88..33.. PPiippiinngg The novice might say [1:01pm julian] mmaakkee >>mmaakkee..lloogg [1:02pm julian] llpprr mmaakkee..lloogg But Csh can be instructed to run several commands at once or, more importantly, to run several commands in sequence with output from one as input to the next. This is called piping. The piping operator, to connect commands, is the vertical bar, "||". In general the format is _c_o_m_m_a_n_d _[ _| _c_o_m_m_a_n_d _._._._] This instructs Csh to connect ssttddoouutt of one command to ssttddiinn of another. For example [1:02pm julian] mmaakkee || llpprr 6611 UUWWOO//UUnniixx 88..44.. MMoorree PPiippiinngg The operator "||&&" will connect ssttddoouutt _a_n_d ssttddeerrrr to ssttddiinn. For example [1:01pm julian] mmaakkee ||&& llpprr The command "tteeee" (see tteeee((11))) is useful for seeing what is happening in a pipeline. For example [1:01pm julian] mmaakkee ||&& tteeee //ddeevv//ttttyy || llpprr This will push ssttddeerrrr and ssttddoouutt to your terminal (that's always //ddeevv//ttttyy) as well as to the line printer. UUWWOO//UUnniixx 6622 88..55.. JJoobb CCoonnttrrooll Unix is a multi tasking environment. Users can control jobs. This is a powerful _f_e_a_t_u_r_e (which new users may find annoy- ing). [2:12pm julian] llooggoouutt There are stopped jobs. _._._. _c_a_n_n_o_t _l_o_g_o_u_t _u_n_t_i_l _y_o_u _d_e_a_l _w_i_t_h _t_h_e_m_! To see some of the processes you have use ppss((11)) or the Csh builtin jjoobbss. For example: [8:21am julian] ppss PID TT STAT TIME COMMAND 1885 q2 S 0:12 emacs slides 1285 q2 S 0:01 tcsh 2513 q2 R 0:00 ps Or, alternatively, print out the job table your shell knows about: [8:36am julian] jjoobbss [1] + Running emacs slides [8:36am julian] 6633 UUWWOO//UUnniixx 88..55..11.. FFoorree//BBaacckkggrroouunndd JJoobbss Usually a job is run in the foreground -- Csh stands back and lets the job communicate with you through the terminal. You can instruct Csh to run jobs in the background, so that you can do other things while your job is working. Back- ground jobs will be ssttooppppeedd when they require keyboard input. The ampersand at the end of line is an instruction to run in the _b_a_c_k_g_r_o_u_n_d. Only one job can run in the _f_o_r_e_g_r_o_u_n_d, lots in the background. [1:30pm julian] dduu >>uussaaggee && [1] 9491 _j_o_b _n_u_m_b_e_r _a_n_d _p_r_o_c_e_s_s _i_d [1:30pm julian] _w_o_r_k_, _w_o_r_k_, _._._. _e_t_c_. When your job is done, if you have sseett nnoottiiffyy, you'll get a message: [1:38pm julian] [1] - Done du >usage UUWWOO//UUnniixx 6644 88..55..22.. SSuussppeennddiinngg aa jjoobb You can ssuussppeenndd any job. The keyboard input ^^ZZ sends an interrupt signal to suspend a the current job. [1:30pm julian] dduu >>uussaaggee _._._. _w_o_r_k_i_n_g_, _w_o_r_k_i_n_g_, ... ^^ZZ Stopped (tty input) [1:33pm julian] A job that has been suspended can be resumed in the fore- ground or background. It's often nice to be able to suspend a job, go off and do something else, then come back and resume what you were doing. Alternatively, to stop what you're doing and run it in the background [1:53pm julian] bbgg [1] du >& /tmp/usage & [1:53pm julian] _._._. _j_o_b _r_u_n_s _i_n _b_a_c_k_g_r_o_u_n_d Use the command ffgg to bring a suspended job to the fore- ground. 6655 UUWWOO//UUnniixx To resume a stopped job in the foreground [1:13pm julian] mmaaiill ppuurrppllee Subject: jjuusstt aa tteesstt II''mm ggooiinngg ttoo ssuussppeenndd aanndd rreessuummee tthhiiss jjoobb ^^ZZ Suspended [1:31pm julian] ffgg mail purple _._._. _t_h_e _c_o_m_m_a_n_d _r_e_s_u_m_e_d (continue) ~~qq [1:31pm julian] Vax/VMS users often type ^^ZZ (as end of file) when they mean to type ^^DD.. BBEEWWAARREE:: Don't make this mistake; or, if you do, remember how to control the jobs you suspend! UUWWOO//UUnniixx 6666 88..55..33.. CCoonnttrrooll CCoommmmaannddss Since you can have many jobs running in the background (some stopped waiting for keyboard input) you need tools to con- trol them. The command jjoobbss lists your current jobs (with the --ll flag you also get the process id). [1:50pm julian] jjoobbss [1] Running du >usage [2] - Stopped (tty input) emacs [3] + Stopped (tty input) mail Jobs are referenced with a %% notation -- %%nn (for job number n), and %%ccoommmmaanndd (for the job running that command). When no job is mentioned, the current job is assumed. 6677 UUWWOO//UUnniixx 88..55..44.. CCoonnttrrooll bbuuiillttiinnss The Csh builtins for job control are ssttoopp to stop (or suspend) a job. A stopped job can be restarted. All background jobs will stop when they need terminal input. kkiillll to kill a job. This sends the SIGKILL signal. bbgg to put a job in the background. eg. after a ^Z. ffgg to bring a job to the foreground. eg. when keyboard input is requred. For example: [1:51pm julian] ssttoopp [1:51pm julian] kkiillll %%11 [1:51pm julian] ffgg %%11 [1:51pm julian] bbgg %%dduu UUWWOO//UUnniixx 6688 88..55..55.. TTeenneexx CCsshh The Tenex version of the Csh has a number of important extensions to the Csh. It's distributed as a patch set for BSD Csh. Some important features are: eemmaaccss lliinnee eeddiittttiinngg With cc--pp (previous), cc--nn (next), cc--bb (back), cc--ff (for- ward) you can recall previous commands, make correc- tions and execute them. ssppeelllleerr With mm--ss you can have typos corrected, eg. [2:06pm julian] ls /user/spool/lpd /user/spool/lpd not found [2:06pm julian] cc--ppls /user/spool/lpdmm--ss [2:06pm julian] ls /usr/spool/lpd To change your default shell to //bbiinn//ttccsshh [2:09pm julian] cchhsshh rreeggggeerrss Old shell: /bin/csh New shell: //bbiinn//ttccsshh This will be effective the next time you login. 6699 UUWWOO//UUnniixx