Unix and Vi, Very Short Intros

 A few shell commands (some are specific to tcsh), a few
 utility programs, and a brief vi intro.

========================================
Syntax (of this document)

C-z	: hold down the [ctrl] key and press the ["z"] key, and so forth.
S-C-z	: [shift][control]["z"]
SP	: [space bar]
SP|l	: [space bar] or ["l"] key
RET	: ["enter"] or ["return"] key
Esc	: ["escape"] key
TAB	: ["tab"] key
%> 	: the shell prompt, whatever it might actually be.

=======================================
The Shell ( mostly bash, but similar for sh, csh, tcsh, ... )
=======================================

--------------
Regular expressions, use in command arguments
--------------
*		any string in current directory
abc*def		any string starting "abc" and ending "def"
TAB             command line completion

------------
Job control
--------------
C-z	: put the current job to sleep, return to shell.
%> jobs	: see which jobs are asleep.
%> %1	: wake up job [1].
%> fg	: wake up most recently stopped job.
%> foo &: execute foo without waiting for it to exit (background job).
ps	see status of processes
kill	send signal to process (-9 = end process)
exit	send terminate signal to this process

-------------
Shell variables, aliases
-------------
set               see all shell variables and their contents.
echo $PWD	  see contents of PWD, your "current working directory" shell variable. 
echo ${PWD}       alternate syntax specifies exactly what the "$" applies to.
pwd               see your "current working directory".
echo $PATH        see the paths your shell uses to find executables.
echo $MANPATH     see man pages search path
echo $INFOPATH	  see info pages search path
myvar=abc         set (and create) a shell variable "myvar" to "abc"
export MYVAR      make variable "MYVAR" an "environment" variable (inherited by child processes).
unset myvar       uncreate shell varilable "myvar", name "myvar" becomes undefined.
set myvar         create shell varilable "myvar" w/ null string content.
alias             see all commandline string replacements
alias l='ls -F'   set "l" to be replaced w/ "ls -F" on commandline.
which foo         show full path name of executable program "foo" (if found)

---------------
Directories and Files
---------------
cd foo           change current directory to "${PWD}/foo"
cd ..            move up to parent directory
.                alias for your current directory
~                alias for your home directory, same as $HOME
cd               alias for "cd ~"
ls               show contents of current dir
ls -a            show .* files, too
ls -l            show permissions, creation date, etc.
mkdir foo        make a new directory
rmdir foo        delete directory (must be empty)
rm foo           delet file "foo"
rm -r foo        delete (recursive) directory and all contents
rm -f foo        delete even if protected.
rm -r foo        remove all files recursively from directory foo, and foo, too
~/.bashrc        shell commands read by new bash shell
~/.bash_profile  shell commands read by login bash shell

-------------
manuals
-------------
man man         see manual page on how to use the "man" command
man intro	see manual intro page
man 1 intro	see intro page for section 1
man foo         see man page for "foo"
man -k foo      see list of man pages w/ keyword "foo"
man -f /etc/passwd      get list of man pages related to file
man -M dir foo          see man page for "foo" in dir/man1
info            similar to man, but sometimes more complete.
info info       like man man

--------------
Tools
--------------
echo $PATH > foo      output redirection: echo's stdout goes to (new) file "foo"
echo $PWD >> fooe     echo's stdout goes to file "foo", appended to end of file
cp foo bar            copy foo's contents to bar (creates new file "bar", if needed) 
mv foo bar            change name of foo to bar
chmod 754 foo         set foo's file permissions to 111101100 = rwxr_xr__ (owner, group, other)
umask                 see default permissions mask (= NOT(permissions' bits))
ln foo bar            create new directory entry "bar", points to same thing as foo
ln -s foo bar         enter text "bar" as alias for foo in directory
cat foo bar           dump files foo and bar, in order
less fb               dump file fg a page at a time
cat foo bar | less    dump foo and bar, see page at a time.
prog < fb             change stdin for prog to be file "fb"
grep abc *.txt        search for text string "abc" in all .txt files
diff foo bar          show text line differences between file contents
cmp foo bar           report byte differences
tar -cvf f.tar foobar    pack all foobar's files and subdirs into f.tar 
tar -xvf f.tar           unpack f.tar
gzip foo                 compress file foo to foo.gz
gunzip foo               uncompress foo.gz to foo
zcat foo.gz              uncompress, send to stdout
zcat foo | tar -xvf -    uncompress, send to tar (which is set to read stdin)

--------------------
Looking around for executables, typical tools to read about
--------------------
/bin
/usr/bin
/usr/local/bin

sed, awk, perl, find, finger, who
gdb, gawk, gcc, cc, passwd, 
gmake, make, touch, hexdump, od, tr
wc, whereis, whatis, whoami, emacs, jpico, vi

======================================
VI(vim)
======================================

Starting
-----------------
%> vi foo       edit file foo
%> vi *.txt     sequently edit each file in list of all files ending ".txt"
:n              go to next file in list

Getting Help
------------------
%> vimtutor    vim commandline tutorial program
:h             editing session help (only works for vim). 

Command Mode, moving around
-----------
SP    move forward one char (also: l)
h     hop back one char
w     jump forward one word
b     jump backward one word
^     to beginning of line
$     to end of line

j      jump down one line (also: RET)
k      kick (jump up) one line

C-f    forward several lines
C-b    back up several lines

:10    go to line 10
10G    go to line 10
:$     go to last line

/foo[RET]   search for "foo" (can use regular expressions)
/[RET]      search again

Command Mode, start editing text
-----------
i    go to insert mode (before cursor) (I: at beginning of line)
a    go to insert mode (after cursor) (A: at end of line)
O    Open insert mode (on new line before cursor)
o    open insert mode (on new line after cursor)

Insert Mode, editing commands
------------
[most keys]    add new text to document
[del]          erase ([backspace], or C-h)
Esc            leave insert mode

Command Mode, editing
-----------
x        excise a char at cursor (8x: excise 8 chars)
dw       delete word at cursor
dd       delete entire line at cursor
:u       undo most recent change

Y       yank line to cut-paste buffer (8Y: yank 8 lines)
p       paste line(s) from cut-paste buffer
J       join current and next line down

:        start EX mode
:f       show default file name
:ESC     leave EX mode
:vi      get back to VI command mode

ma            mark current line with tag "a"
'a            go to line marked "a"
:10,20 m .    move block of lines 10-20 to current cursor location
:'a,'b m .    move block of lines 'a to 'b to current cursor 
:'a,'b c .    copy block
:'a,'b d      delete block
:g /abc/s/abc/bac/g    globally replace "abc" with "bac" (see SED)

Command Mode, file operations
---------------
:w      write edit buffer to default file
:w foo	write edit buffer to file "foo"
:r foo	read from file "foo" into edit buffer at cursor
:q      quit VI
:q!     quit w/o writing edit buffer back to file.

Misc
-------------
C-l	redraw screen

================================
Note on text formatting

#; Plain text files contain various white space characters. In particular,
#; an explicit RET appears in this text at the end of each line.
#; The RET is expanded into a single ascii character known as an
#; end-of-line chararcter (aka, eoln, $, LF, "\n", 0x0A).  
#; In the MS/DOS/WINDOWS world, the plain text end-of-line is two 
#; characters, 0x0A and 0x0D (aka, CR, "\r", ^M). MS Windows type of
#; displays, for instance, MS Word, wrap long lines on the screen even
#; if no eoln characters appear.  Some things, like browsers, might not.
#; See also, "cat -v", "od -t x1", and "tr" commands for more info on 
#; non-printing characters. By the way, eoln isn't always 0x0A and so
#; forth, there are other codes as well. You will see notation like "^M"
#; which is a shorthand for 0x0D, for instance. The "^" notation for
#; codes works like this: ^[char], where char is the N-th letter of
#; the alphabet, represents 0xN where N is in hex notation.
#;