*** 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"
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, 

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.

	 Debian (Ian Murdock, Purdue University) - The Debian Manifesto
	 first community based distro
	 Mark Richard Shuttleworth (2004) Ubuntu
	 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.



*** Please log on; first to the workstation using the generic machine account;
get a terminal window and ssh into pegasus.


Operating system, 
	Shell - sh, bash
	many programs run as "commands"
Development tools,
	programs which "know" about the operating system

	other programs, windowing system, X11, GNOME or KDE


Command Line and Files

_command_ _switches_ _arguments_

	* 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
	* globbing
	* use "echo" to see how the globbed arguments expand
	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

	* 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
		[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

	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
		[brosenberg@u03 ~]$ echo $I
		[brosenberg@u03 ~]$ bash
		[brosenberg@u03 ~]$ echo $I
		[brosenberg@u03 ~]$ exit
		[brosenberg@u03 ~]$ export I
		[brosenberg@u03 ~]$ bash
		[brosenberg@u03 ~]$ echo $I
		[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

	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

	for I in `ls` ; do cp -i $I $I.bak ; done

	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
	dd, x, r, D, u, J, /string, (return) to re-search

	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
	uses ed commands on a stream
	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

	ps ; ps -auwx #switch incompatibility
		[brosenberg@u01 ~]$ cat 
		X=1 ; while [ $X -le 50 ]  ; do echo $X ; X=$(($X+1)) ; sleep 3 ; done
	chmod a+x
	./ # note path, security issue
	./s.shv& ; ps #theory of forks
	jobs ; %1 ; ^C #reattaching, "current job"
	./ ^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
	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 pegasus:
	pegasus: cat >> .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
		IdentityFile ~/.ssh/id_rsa
	df and du are heavy tools, but of some use


Desktop Integration

	'nix: textwrangler, jext, fugu, .ssh/config, 
	windows: putty, puttygen, pscp, and cygwin



    * 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 
    *Advanced Bash-scripting guide, Mendel Cooper, The Linux Documentation Project