Introduction to Unix

Patricia J Riddle [email protected] Computer Science 215 Semester 1 2007

Special Thanks to Jasvir Nagra (who thinks he is God ……. or Denny Crane) for his lecture notes 210 and 215

• "Students are encouraged to enroll in COMPSCI 210 before or concurrently with COMPSCI 215.”

• "Students ignoring this advice are unlikely to pass COMPSCI 215." Overall Aim Informal Objective

• To understand the nitty-gritty stuff about how a computer does its thing. Objectives of the Course

• Operating Systems – Know what an operating system is. – Learn how these hardware components operate. • Architecture – Understand what hardware a computer requires. – Learn how these hardware components operate. • Data Communication – Learn how multiple computers communicate – Understand the layers used in data communication protocols. Big Picture

• Appreciate how complex systems can be built using mostly independent layers. Overview of Part 1

• Understand what an operating system is. • Learn how an OS abstracts and interacts with hardware. • Appreciate how we can hide complexity by building in layers. UNIX

• We will use UNIX as a concrete example of an OS to illustrate (and play with) ideas. UNIX in Part I

• Basic understanding of UNIX Simple commands, file redirection, pipes, filename patterns

• Familiarity with common UNIX shell commands: ls, cd, mkdir, rm, more, less, cut, find, grep,...

• Ability to find additional information Using commands like man, info and help UNIX Continued….

• Understand notions of files, directories and permissions

• Be able to write and debug shell scripts for simple tasks: Shell variables, shell control statements and arithmetic What’s in it for you?

• Get to pass Compsci 215

• Get to do complier and OS papers in 3rd year More in it for you!

• Write better programs because you understand the limitations and features of the underlying machine.

• Troubleshoot problems quicker because you are familiar with more than one level of abstraction.

• Its fun! Unix is Born

• Created – Initial development: 1969 – Ken Thompson and Dennis Ritchie at Bell Labs • Motivation – A need for a “convenient interactive computing service”. – The story goes that... Ken wanted something to run his “Space Travel” game, and there was this unused PDP-7 sitting in the corner. . . Unix is named

• Unix stands for UNiplexed Information and Computing System. (It was originally spelled "Unics.")

• Coined in 1969 to describe a specific computer operating system, the term "Unix" now covers a whole host of variations, including , FreeBSD, and Solaris. What’s in a name?

• The name was intended as a pun on an earlier system called "Multics" (Multiplexed Information and Computing Service).

• Multics was a large multi-user operating system that was being developed at Bell Labs shortly before Unix was created in the early '70s.

• Brian Kernighan is credited with the name. Unix spread

• Whole system was re-written in “C” in 1973, and Bell Labs started to give it away (they were constrained by monopoly laws from selling software).

• Universities took it up, and graduates took it with them into industry. Unix is adopted

• The standard computing interface reputedly looked like this: OS/360 JCL / / B A T C H J O B J O B (‘1 2 3 4 5‘), M S G C L A S S = H, M S G L E V E L = (1,1), N O T I F Y = M E, / / U S E R = M E , R E G I O N = 4 0 0 K / / S T E P 1 E X E C P G M = H E L L O / / S T E P L I B D D D I S P = S H R , D S N = M Y.L O A D.L I B R A R Y / / S Y S P R I N T D D S Y S O U T = * • In this environment UNIX was a revelation: UNIX

[computer-science-dept-university-of-aucklands-computer:~] pat$ HELLO Why Study Unix?

Unix Windows - Open design - Closed Design - Modular - Monolithic - Programmer-centric - User-centric - Popular on servers. - Popular. They may appear different, but all operating system must ultimately provide the user the same utility - abstract away hardware so that users do not have to worry about it. User Interfaces

Two fundamental types of user interfaces:

GUI CLI (Command Line Interface) • Easier to learn • Expressive • Aesthetics • Modular • Obvious multi-tasking • Quicker • Remote access The Matrix “Hack” What is an Operating System?

• ??1 Definition • An operating system manages the hardware and software resources of the computer system. It provides a stable, consistent way for applications to deal with the hardware without having to know all the details of the hardware. Characteristics • Safe • Efficient • Abstract The Shell

Unix provides user-level access to its features through a “command interpreter”, or “shell”.

1. Write a prompt (e.g. prid013@chaos:~$ or [pat]$ ) 2. Read a line of input 3. The first word is the command; the rest are strings to pass to that command 4. Find an executable file matching the command “in the usual places” and run it 5. Wait for the command to finish; when it does, go back to step 1. Using University UNIX account • Connect from Windows using Putty • File → New Connection • Under-grad server is chaos.cs.auckland.ac.nz • Put the mouse away! Fun Unix Commands

• echo print a string • ls list the files and directories • cd change directory • DEMO Alert • cat displays the – Using each of these commands contents of a file • who see who else is online • write write to other people • mesg do not disturb • man Your most useful companion man and apropos

• man Online manual • DEMO Alert • apropos Search – man mesg manual – How to read sections of man Apropos means suitable ie. search for something – apropos clock suitable. Instead of – man oclock apropos you can also – oclock use man -k – man xclock For tomorrow…

• Try logging on to chaos – I will give away a free chocolate egg tomorrow to the 10th person who logs in to chaos.

• What is the command I will use to figure out the 10th person to log in to chaos? – I will give away a chocolate egg tomorrow to the person who emails me the best answer about how they figured out the command. Resources

• Bruce Hutton’s notes on using UNIX http://www.cs.auckland.ac.nz/~bruceh/lectures/210UNIX/UNIXLectures.pdf

• Check out http://www.cs.auckland.ac.nz/references/Unixhelp/

• There are literally hundreds of books in the library on Unix. Look for ones with a phrase like “beginners” or “dummies”. Best Way

• Most of all, you will learn by trying things out while seated at a terminal. • You can expect lots of sad things to happen when you start using Unix, but it gradually gets easier. • The silly little names for commands are the most annoying part. • Try to look “under the surface” at the technical achievements of Unix, rather that getting into a panic trying to memorize commands. Using UNIX at Home

• If you are feeling brave: – Try running – Boots off a CD - no installation required – Very friendly graphical interface to UNIX • If you are feeling braver still: – Try installing Linux – Needs a 486 or better, a free partition and a free weekend – Lots of online support Using UNIX at Home • If you want to use UNIX at home: – Install CYGWIN – Runs a UNIX emulator on MS Dos/MS Windows – No way to send mouse events to UNIX through Cygwin – Put the mouse away! Using University UNIX Account

• Ugrad UNIX server is called chaos.cs.auckland.ac.nz • Login using your UPI and NetAccount passwd

[pat]$ ssh [email protected] Password: chaos> prid013@chaos:~$

……… prid013@chaos:~$ exit exit chaos> logout Connection to chaos.cs.auckland.ac.nz closed. [pat]$