Mini-course in Unix and HPC
Department of Computer Science
University of Miami
course date: May 4 and 6, 2010
last update: 23 aug 2019
Document:
Outline
===================================================== History *** NOTE: what I call forks are actually just the opposite. They are re-writes from scratch, to avoid property issues. So here are the three great "un-forks" of Unix .. *** AT&T fork (a.k.a. SVR4, a.k.a. original unix) The Operating System from New Jersey. Unix, 1969. Ken Thompson, Dennis Ritchie, Brian Kernighan, and others, at Bell Labs. Unix-time: January 1, 1970 number of seconds, not counting leap seconds (so differs from UTC) various "editions" http://www.bell-labs.com/history/unix/versions.html then "systems" Unix System V, Release 1 1983 AT&T Unix Support Group Bach's book Release 4, SVR4, around 1988, 1990. Sun and AT&T; Sun subforked Solaris (abandoning a BSD heritage); Also AIX subforked SVR4 later SCO/Novell took over Unix International, the AT&T spinoff for Unix. *** Berkeley Fork, a.k.a. BSD 1977 Bill Joy, 1BSD, Unix 6-th edition branch a Berkeley University product. "strings" on the Microsoft operating system will often reveal "Copywrite regents of California", this is 4.3BSD code in the Microsoft OS Windows 7, \Windows\System32\finger.exe Licensing uncertainties, gave rise to FreeBSD FreeBSD Jordan Hubbard November 1, 1993, from BSD4.3 2001 Apple hires Jordan Hubbard for OSX Sub fork, Ultrix, which turned into OSF/1, except with a Mach kernel (like OSX), which turned in to Tru64 (Compact) *** Linux Fork GNU 1983, Stallman, from MIT. Free Software Foundation in 85. Free as in freedom, not beer. Linus created a kernel to GNU Op Sys in 1991, ending the Hurd project. GNU/Linux, but generally called (mis-named) Linux (much discussion of this) The creation of the "distro" idea, with it's own lineage. Mainly package managment, however also distribution and packaging, and also sysadminitration/management. Selection of ports/packages. Distros: Debian(1993)/Ubuntu Debian (Ian Murdock, Purdue University) - The Debian Manifesto first community based distro Mark Richard Shuttleworth (2004) Ubuntu Slackware(1993)/S.u.S.E. Slackware (Patrick Volkerding) was first to box the linux kernel and GNU utilities into an install procedure Software und System-Entwicklung 1994 Novel acquires SuSE 2004 RedHat/Fedora (2003)/Centos Marc Ewing 1994 (CMU) and Bob Young Fedora, community based Centos (2004) ===================================================== The unix heritage: "What you think is going on, is going on." - Joe Condon Doug McIlroy: "Write programs that do one thing and do it well. Write programs to work together. Write programs that handle text streams, because that is a universal interface." Influenced by server based, multi-user programming, a natural for many sorts of computing because it has a long heritage. Certainly the original heritage is text based, with server machines. C language. "Bad is better", moving the design compromises towards simplest implementation. ===================================================== Architecture: *** Please log on; first to the workstation using the generic machine account; get a terminal window and ssh into pegasus. Kernel Operating system, Shell - sh, bash many programs run as "commands" Development tools, programs which "know" about the operating system Applications other programs, windowing system, X11, GNOME or KDE ===================================================== Command Line and Files _command_ _switches_ _arguments_ command: * a program in PATH * an alias * a builtin (some are both builtin and program) - use "type" to find out if an builtin, and "which", if a program, to get full pathname - use "builtin cmd" to force the builtin version - builtin is necessary when change is to the shell's environment, e.g. cd switches (options): * traditional -letter or -letter value. can be combined * -- ends switches * new --long-option-name argument: * globbing * use "echo" to see how the globbed arguments expand examples: ls -l ; ls -- -l ls -l -i -n; ls -lin ls /etc/a* /etc/c*; ls /e*/f* ls -la * hidden files and directories * meaning of various -l data * touch, chmod, rm; mkdir and rmdir, cd, pwd, id * -rwx for directories. * . and .. * users and root examples: * demonstrate r,w,x on a test file * demonstrate r,w,x on a test directory [brosenberg@u03 ~]$ more a [brosenberg@u03 ~]$ chmod a-rwx a [brosenberg@u03 ~]$ more a a: Permission denied [brosenberg@u03 ~]$ chmod u+wx a [brosenberg@u03 ~]$ more a a: Permission denied [brosenberg@u03 ~]$ chmod u=rx a [brosenberg@u03 ~]$ more a [brosenberg@u03 ~]$ echo hi > a -bash: a: Permission denied [brosenberg@u03 ~]$ chmod u+w a [brosenberg@u03 ~]$ echo hi > a [brosenberg@u03 ~]$ chmod a-rwx d [brosenberg@u03 ~]$ ls d ls: d: Permission denied [brosenberg@u03 ~]$ chmod a+r d [brosenberg@u03 ~]$ ls d a [brosenberg@u03 ~]$ cd d -bash: cd: d: Permission denied [brosenberg@u03 ~]$ chmod u=x d [brosenberg@u03 ~]$ ls d ls: d: Permission denied [brosenberg@u03 ~]$ cd d [brosenberg@u03 d]$ ls ls: .: Permission denied %then clean up standard unix hierarchy ===================================================== Shell Startup, Customization, terminal woes programmable, scripts, including startup scripts * login shell: /etc/profile (global) * login shell: afterwards, first file found among * ~/.bash_profile * ~/.bash_login * ~/.profile * on logon: ~/.bash_logout * subshell: ~/.bashrc (rc means "run command") * note ~ convention, and ~burt (http url's) * note: our .bash_profile reads ~/.bashrc and our ./bashrc reads /etc/bashrc environment variables and aliases * alias * environment variables * export variables examples: name= value unset name #builtin unalias rm ; alias rm='rm -i' #builtin echo $HOME #parameter expansion echo ~ ; echo ~root #tilde expansion echo * ; #pathname expansion printenv ; [brosenberg@u03 ~]$ I=eye [brosenberg@u03 ~]$ echo I I [brosenberg@u03 ~]$ echo $I eye [brosenberg@u03 ~]$ bash [brosenberg@u03 ~]$ echo $I [brosenberg@u03 ~]$ exit exit [brosenberg@u03 ~]$ export I [brosenberg@u03 ~]$ bash [brosenberg@u03 ~]$ echo $I eye [brosenberg@u03 ~]$ unset I [brosenberg@u03 ~]$ echo $I [brosenberg@u03 ~]$ [brosenberg@u03 ~]$ alias rm alias rm='rm -i' [brosenberg@u03 ~]$ unalias rm [brosenberg@u03 ~]$ alias rm bash: alias: rm: not found [brosenberg@u03 ~]$ alias rm='rm -i' [brosenberg@u03 ~]$ alias alias l.='ls -d .* --color=tty' alias ll='ls -l --color=tty' alias ls='ls --color=tty' alias vi='vim' alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde' [brosenberg@u03 ~]$ environment continued * PATH, which * MANPATH, man * reset, TERM=xterm or TERM=vt100 * generally in .bashrc * nano to edit our files and source them * history and TAB completion ===================================================== Pipes and redirection As much about unix as about the shell. Connecting together programs. Redirecting out to a file, input from a file Appending output to a file examples: how many files are in /bin? ls /bin | wc same wc filename, cat filename | wc cat f1 f2 f3 > fo cat f1 > fo ; cat f2>> fo ; cat f3 >> fo ; while true ; do echo -n $X >>f ; X=$((X+1)) ; sleep 5 ; done tail -f f # in another window while true ; do echo -n $X| tee -a f ; X=$((X+1)) ; sleep 5 ; done unset X cat /etc/passwd | sort ===================================================== Text Manpulation More file manipulastion: cp mv ln (ln hard and ln soft) command line expansion in the shell example: for I in `ls` ; do cp -i $I $I.bak ; done vi: written by Bill Joy. Built on ed and ex. Earliest "visual" editor. mode: text mode and edit mode. ex: ":" character. typical "i" to enter text mode with curser at insertion point, esc to return to edit modes :q, :q!, :wq .,.+5s/this/that/g dd, x, r, D, u, J, /string, (return) to re-search grep: searchs for a match string matches chracters literally, . matches any charcter but a new line, .*, .?, .{n}, .{n,m}, then [a-z]; \s \S \d \D are also useful. ^, and $ match beginning and end of line sed: uses ed commands on a stream examples: ls | grep ^...$ | wc list all commands in your path that begin with "l" $ echo $PATH | sed "s/:/ /g" | xargs ls | grep ^l | wc maybe wrong due to sym links :-) X11R6 -> X11 ... commands, continued locate lsof # i used with | grep nohup to find my run-away process find . -print | xargs -n1 grep -H dogs md5 or md5sum diff, cmp ===================================================== more about scripts. forking, parent child, inherit environment, user privileges ps, #!, kill, fg, bg, jobs examples ps ; ps -auwx #switch incompatibility [brosenberg@u01 ~]$ cat s.sh #!/bin/bash X=1 ; while [ $X -le 50 ] ; do echo $X ; X=$(($X+1)) ; sleep 3 ; done chmod a+x s.sh ./s.sh # note path, security issue ./s.shv& ; ps #theory of forks jobs ; %1 ; ^C #reattaching, "current job" ./s.sh ^Z bg / fg ^C # alternate kill -kill PID ; # signals, this is the control-C options topics: top, system initialization, perl, make ===================================================== Logging in hostname, whoami, date, uname, tar, scp, ftp, ssh-keygen, wget, df, du example: tar cvf fn.tar dir ; tar xvf fn.tar # can add "z" or "j" to compress; best to tar a subdir workstation: ssh-keygen [-f altkeyfilename] workstation: scp id_rsa.pub pegasus: pegasus: cat id_rsa.pub >> .ssh/authorized_keys workstation: chmod u=r .ssh/id_rsa # important! else ssh silently fails workstation: (optionally edit .ssh/config) cat >> .ssh/config Host pegasus Hostname pegasus.ccs.miami.edu IdentityFile ~/.ssh/id_rsa ^D df and du are heavy tools, but of some use ===================================================== Desktop Integration 'nix: textwrangler, jext, fugu, .ssh/config, windows: putty, puttygen, pscp, and cygwin ===================================================== References * Design of the Unix OS, M. Bach * Harbison and Steele (C reference manual) * Design and Implementation of the FreeBSD OS, McKusick et al. * Linux Kernel Development, R. Love * John Lions, (historical) *Bash guide for beginners Machtelt Garrels The Linux Documentation Project http://tldp.org/LDP/Bash-Beginners-Guide/html/index.html *Advanced Bash-scripting guide, Mendel Cooper, The Linux Documentation Project http://tldp.org/LDP/abs/html/index.html