Unix Basics - Feb 8th 2005

General info:
-Unix is based on the idea of making things efficient if you use them a lot.  
Thus, names are short ('rm' instead of remove, /usr instead of /user), and
things are not necessarily easy to find the first time.  
-Everything is modular.  The OS is a "library of protected functions"
(Hartman); the windowing system is a separate module that runs on top of
that, and the shell is a separate module still.  Many command-line operations
are going to be made up by putting little parts together.
-Linux is a collection of many small programs written by many different
people, with no centralized guidance or organization.  There is some effort
at standardization, but standards are not necessarily followed.  Thus, there
are many flavors of Linux/Unix/BSD, and each one does things differently.

Finding information
          man, info
                 man pages are in sections; on some systems, 'man man' will
                 tell you what the sections are
                        1 - command-line commands
                        2 - system functions in C
                        3 - general functions in C
                        5 - config file descriptions
                        8 - administrative commands
                 man getopt
                 man -S 3 getopt
                 (the syntax for getting to different sections seems
                 different on every system; check the man page :) )
          man -k / apropos (k for keyword)
                man -k latex
          The Linux Documentation Project
                http://www.tldp.org/ (esp useful: HOWTOs)
          google
                try queries starting with 'linux' if you're getting a lot of
                non-computer-related item
          newsgroups - usually just found in general search, but good if you're
                         interested in a particular topic
          books
                O'Reilly

Logging in: be sure to look at the 'session' menu, and choose a good starting
desktop, like Gnome or KDE.

Choice of shells:
         csh/tcsh - academic
         bash - industry, open source - this is what I'll be showing
         -> you can change which one you log into by default on the apply page

Basic commands:
        ls [options] [file(s)/directories]
          ls -Shrl
          ls -a
        tab completion
        cd [directory] (defaults to home)
        cp old new
        mv old new
        rm [-r] name
        mkdir dirname
        rmdir dirname
        pwd
        . (this directory)
        .. (parent directory)
        more/less, cat, tac, touch, wc [-l|-w|-c], head, tail
        diff
        alias
          alias ..='cd ..'
          alias asdf='loadeys /lib/kbd/keymaps/i386/dvorak/dvorak.map.gz'
          alias cpu='grep name /proc/cpuinfo; grep MHz /proc/cpuinfo'
          alias use='du --max-depth=2 /net/sal/home/platt | sort -n'
        chmod, chgrp, chown - things must be executable (x) to run them
          chmod o-x *
          chgrp -R platt .
        grep, find
          find . -iname makefile
          grep -n LD */Makefile
          grep pizza `find .`
          find / 2> /dev/null | xargs grep comment
        gawk - more advanced text/regex manipulation
        sort, cut
          ls -l | sort -n -k 5 | cut -c 38-42
        which, whereis
          which gawk
          whereis latex
        whoami, groups
        finger name
        regexes, variable expansion, $, ~, *, ', ", `, eval, \
          ls -ltr *[cC]??5*.png
          x=hello; y=world
          echo $x $y
          less ~/.bashrc
          echo '~'
        ssh, scp, ping, traceroute, dig
          ssh platt@lectura.cs.arizona.edu:
          scp * platt@rosewood:src/projects/curvature
        links, symlinks
          ln -s /cs/extra/platt extra  
        pushd, popd, dirs [-v]
          alias 1='pushd +1'
          alias pu='pushd'
          alias d='dirs -v'
          pu ../extra; d          
        at, date    
        dd
        mount

Getting around on the command line
        history, .bash_history
        up (C-p), down (C-n), forward (C-f), backward (C-b)
        !-n
        !$ - last word on previous line
        !m:n - m commands back, nth word on line

Pipes, redirection
        file descriptors
          0 - stdin
          1 - stdout
          2 - stderr
        redirect standard in of command from file:
          command < file
        redirect standard out of command to file:    
          command > file
          echo "hello world" > foo
        redirect both to nowhere (throw output away):
          command &> /dev/null

Processes and job control
     backgrounding - &
        sleep 5 &
     fg, bg, C-z
     kill
          kill -9 12345
          kill %2
     pkill -U platt
     ps [aeux]
     pstree
     top

Editors: emacs, vi(m), kate

Building and running programs
            javac, java
              javac *.java; java Main
            tar, gcc, make, Makefiles
              tar xzf foo.tar.gz
              tar cjf foo.tar.bz2 foo/
              make; make install

misc. useful:
        browsers: mozilla, opera, konqueror, firefox
        pdf/ps: acroread, gv
        pictures: kuickshow, xv
        chat: gaim, ayttm
        music/video: xmms, kscd, mplayer (it plays everything...)
        printing:  lpr/lpq/lprm/lpstat
        Office/Word/Excel/PowerPoint: look in menus for OpenOffice
        alt-f2: run command
        try the menus

Scripting
               Script files start with
             #!
             This is not just a comment (although # is a comment in scripts)
             Config files: .login, .bashrc, .logout
             Environment variables
               env
               export
               PATH - where the shell looks for commands to run
                PS1 - the prompt

General info on how Unix is set up
          Where things are in the Unix hierarchy
                  /bin - executables (binaries)
                  /sbin - administrative (superuser) binaries
                  /man - manual pages
                  /lib - libraries, linkable
                  /include - headers
                  /etc - system configuration files
                  /mnt - things that are removable, like cdrom
                         mount /mnt/cdrom
                  /home - user directories
                  /var - variable information for running processes
                  /tmp - temporary
                  /usr - another tree of most of these to keep / from
                         getting cluttered
                  /usr/local - programs installed only on this machine, as
                         opposed to the whole network
                  /usr/X11R6 - everything for the xserver
                  /boot - files to start the system; usu. just kernel images
                          and system maps
                  /proc - much useful info, weird tree
                        ls -l /proc/bus/usb/
                        less /proc/bus/usb/devices