I. SELECTED PRIMARY UNIX COMMANDS: ---------------------------------------------------------------------- COMMAND SYNTAX: command_name -options files_or_objects redirection(< > >> |) elements of the command are separated by whitespace options for a command are typically specified by a string starting with a "-" redirection allowed for both standard input and standard output and standard error COMMANDS: exit - exit from the shell (the command interpreter); ctrl-C - abort a command; the panic button man - print manual pages apropos - lookup of commands according to match of keywords to brief descriptions; not all commands included pwd - working directory name; tells where you are in the directory hierarchy cd - change directory ls - list contents of directory; use ls -opts for more informative directory displays; create mnemonic aliases for easy use ls -CF - directory listing, sorted and in several columns with directories and commands identified by "/" and "*", respectively; ls -il - long form of directory listing, showing file sizes, distinguishing directories, etc ls -RCF - recursive directory listing ls -adCF .* [!a-z]* - list dotfiles and files starting with upper case cp - copy mv - move or rename files rm - remove files or directories; this command is DANGEROUS -- you may delete too much; consider creating an alias to a safer command rmdir - remove a directory that is empty mkdir - make a directory cat - concatenate and print files; a quick way to display a short file more - browse or page through a text file vi - screen oriented (visual) display editor based on ex pr - print files in a pleasant format; default is 56 lines/66 line page, with header giving file name, date last modified and page number lp or lpr - line printer spooler; netmail - send and receive mail; netscape version script - make typescript of terminal session II. SELECTED OTHER UNIX COMMANDS ---------------------------------------------------------------------- netscape - a Motif based World Wide Web browser diff - differential file comparator grep, egrep, fgrep - search a file for a pattern; very useful to pull information from text file head - print first few lines of file tail - deliver the last part of a file whatis - describe what a command is; like apropos, but user commands only whereis - locate source, binary, and or manual for program; which - which command in $PATH is executed find - find files; traverse directory hierarchy rfind - remote find paths - give full pathname for all commands satisfying regex showps - Adobe Systems PostScript language document previewer ghostview - View PostScript documents using ghostscript (gs) one or both of the above should be available date - display date and time spell - find spelling errors areacode - display state and region for area code cal - print calendar talk - talk to another user; units - conversion program nawk - pattern-directed scanning and processing language sed - stream editor sort - sort and/or merge files tr - translate characters fmt - simple text formatter; useful from within vi cut - cut out selected fields of each line of a file expand, unexpand - expand tabs to spaces, and vice versa fold - fold long lines for finite width output device join - relational database operator paste - merge same lines of several files or subsequent lines ll - line length pad - pad lines to given length rev - reverse lines of a file tac - concatenate and print files in reverse kill - terminate a process ps - process status who (or) w - display who is logged in (and a bit more) III. Use of the vi editor. Basic vi editing commands (many more commands are not listed here): (commands marked "*" are a very minimum set) * :w save the file without quitting * :q! quit without saving changes in the file * u undo the effects of the last command that changed the text * h,j,k,l move cursor left, down, up, and right * w,e move cursor to beginning,end of word right * ctrl-F,-B scroll forward, back by a window * i change to insert mode; characters typed are inserted before cursor until end entry with ESC * a as above but characters appended after cursor * o open line after line with cursor characters typed are entered into new line(s) * ESC exit from insert, append or any text entry mode, to return to command mode; abort partial command in command mode * x delete character under cursor into save buffer * dd delete line holding cursor into save buffer * dw as above, but from cursor though word right ctrl-D,-U scroll forward, back by half a window ctrl-L refresh the screen b move cursor to beginning of word left f move cursor within line to first occurrence right of character typed after "f" / search command = move cursor to start of next occurrence in text of string = regular exprn n repeat last search command ZZ save the file and quit 3l move cursor 3 characters right d3d as for dd above, but for three lines d3l as above, but 3 characters right d$ as above, but to end of line yy,etc as for dd, etc, but _copy_ into save buffer cc,etc as for dd, etc, but _change_ lines, etc, to text typed until terminate with ESC s substitute for character under cursor the text typed until terminate with ESC r change character under cursor to single character typed after "r" R overwrite the current text with text typed until terminate with ESC p insert contents of save buffer after cursor (or as line(s) after cursor line if save buffer has one or more whole lines) P as above, except before cursor or cursor line J join the next line to the cursor line . repeat the last command that changed text G go to end of file 1G go to start of file Comments: The save buffer, cutting, and pasting: delete (d..) and yank (y..) commands put text into a save buffer; the buffer holds only the result of the last delete or yank command; to cut and past, delete or yank into the buffer, then move the cursor and put from the buffer, with "p" or "P". vi has two modes: Command mode: anything typed is taken as an editing command; ESC cancels a partial command; if you are unsure of what is happening, type ESC until the bell rings. Insert (or text entry) mode: anything typed is entered as new text; change to insert mode with i a o c s R (or I A O C S, not described above); terminate insert mode and exit to command mode with ESC. Counts: Generally, a number typed before a command produces "number" executions of the command. For more information, including a vi tutorial, a vi quick reference sheet that contains more commands than given above, and a full command reference, see the files in .../help/vi. Hard copy of these files should be available. vi is the standard UNIX editor and is available on all systems. There are other editors: emacs is widely found, wordperfect is not unknown, and some systems even have wordstar look-alikes. Editor preference is a religious subject. Having used emacs, wordstar, etc, I prefer vi to the extent I have an MS-DOS version I carry around for use when a UNIX system is unavailable to me. Thus I commend vi to you. IV. General remarks on UNIX shells -- globbing, redirection, history, etc. A shell interprets and executes commands entered from the terminal or reads and executes commands in a file (a shell script). At the system prompt you may type in one or more commands. The prompt is typically "$" for the Korn shell, which is the default for accounts on some machines. The prompt can be modified, e.g. followed by a string ending in ">" and giving the user name and working directory. Separate multiple commands on a single line with semicolons. UNIX allows the use of wildcard-characters in filenames: * any string of characters ? any single character [] any character included among the characters found in [-] any character within the range of characters, from to , inclusive [!-] any character _not_ matching or range ~ your account home directory ~rupley home directory of account "rupley"; use as in: cd ~rupley The command "rm *" is dangerous because "*" matches (expands to) all files in the directory. UNIX allows redirection of input and output. The following commands are essentially equivalent: pg file "pg" reads "file" pg /dev/null 2>/dev/null # pretty stupid (:-) The UNIX command shells have a builtin programming language. It is used to construct shell scripts that are programs controlling the execution of other programs; it is convenient also for constructing one-liners that are entered from the terminal and that save repetitive typing of commands, etc.. Familiarity with the shell language is worth the time taken to acquire it. Ksh and its look-alikes differ from csh and its look-alikes. For a trivial example of a one liner, in ksh or a look-alike, try: for i in * ; do echo $i ; done | pr -4 -t Some UNIX command shells (e.g., ksh, but not the Bourne shell sh) allow retrieval of past command lines and the editing of a command line, for correction, repetition, etc.: h - display recent history h n m - display history from command number "n" through "m" r (or) r n - rerun last command, or command number "n" ESC - edit history file, with vi editor h j k l w b e etc x dw db p P etc iESC a.. c.. etc / f etc 1G etc * expands wild characters end editing and run edited command with ctrl-C - abort Other shell capabilities include: the definition of aliases and shell functions: to list aliases: alias to list functions: functions | grep function the setting of environment parameters: to set and use a parameter: MSSG="hello, world"; echo $MSSG to display environment parameters: set job control (backgrounding and multiple tasks): to run a job in the background: end command with "&" (output should be redirected to a file) to background a running job: ctrl-Z to foreground a background job: fg [%job_number] to display jobs with pid: ps or jobs to kill a job: kill -9 job_pid_list special facilities for searching for a directory or a command environment variables PATH and CDPATH and many other goodies. To learn everything about a shell, e.g., the Korn shell, ksh, read word by word the man page -- very long, very detailed, but very good. For selected information on shells, consult the FAQ for comp.unix.questions (stored as unix-faq or Unix_-*). There are excellent books on shells, e.g., one by David Korn and Morris Bolsky for the Korn shell.