Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unix. Unix Intro. We use the Unix labs for CSCI213 Your backgrounds and knowledge vary, some of you are: –already Unix proficient, :-) –just starting.

Similar presentations


Presentation on theme: "Unix. Unix Intro. We use the Unix labs for CSCI213 Your backgrounds and knowledge vary, some of you are: –already Unix proficient, :-) –just starting."— Presentation transcript:

1 Unix

2 Unix Intro. We use the Unix labs for CSCI213 Your backgrounds and knowledge vary, some of you are: –already Unix proficient, :-) –just starting Unix in CSCI204 where you will study it in some detail, :-| –only using Unix for CSCI213, :-( So, a minimal intro to Unix Operating System

3 Unix –origins –organization kernel, libraries, tools and utilities, shell –shell command interpreter, shell scripting language, commands start other programs, some standard program libraries, extensibility –time-share system controls on users

4 Unix origins 1960s “time shared” computer systems –pioneered at MIT, 1960-1962 first useful system developed, –multiple users logged on via terminals systems offers facilities for editing files, compiling code, and running small programs system allocates small amount of time (0.1 second to each user); when time is up, user’s code and data “swapped out” of memory onto fast disk storage allowing another user to run

5 Unix origins By late 1960s, much more elaborate systems were under construction - with features like shareable code and data segments, multiple levels of security and access control, … Multics project involved work by MIT, GE- Honeywell, ATT labs,...

6 Unix origins Multics - too costly, too slow, and basically around 1969/1970 it still didn’t work. ATT group split off from Multics They ( Thompson & Ritchie ) wanted a system –run on readily available small machines –specifically intended for small groups of software developers working together on interrelated projects

7 Unix origins ATT guys idea: –a small core to Operating System (OS) that provides essential facilities –additional functionality to be provided by libraries, –users (all accomplished professional programmers) to provide additional components and tools –want a means to build complex programs by combining simple components

8 Unix origins ATT approach was novel at the time –write all the OS in a high level language –small, well defined core of essential facilities as “system calls” –make things uniform - same code to work for I/O to disk file, terminal, … –

9 Unix: first implementations Around 1969/1971, ATT guys did some prototyping on a PDP7 ( 8K words - approx. 20 Kbytes - main memory, small disk ~64Kbytes, Dectapes, single terminal ) using BCPL, B, and early dialects of C. First real implementation for DEC PDP11 computer using C; published around 1973.

10 Unix –origins –organization kernel, libraries, tools and utilities, shell –shell command interpreter, shell scripting language, commands start other programs, some standard programs, extensibility –time-share system controls on users

11 Unix: core (kernel) Twenty or so “system calls” –read, write, create, open, link“file” access –fork, exec, exit, brkprocess (program) control –signal, kill, pipe, dupinterprocess communication –… Rather more than 20 now. “chapter 2 of ‘man’ (manual) pages”

12 Unix libraries stdio –C’s I/O library ( can be used from C++, but iostreams preferred ) makes use of read, write, open, create etc systems calls provides programmer with much higher level facilities - formatted I/O of numbers, strings etc; efficient buffering of I/O,...

13 Unix libraries stdlib –an assortment! random numbers, malloc and free (the C free storage, “heap”, management functions, can involve OS system calls like brk - request to expand heap) math string See “chapter 3 of ‘man’ pages”

14 Unix: tools and utilities Little programs –fgrep and grep - programs that search files for occurrences of particular words or patterns of characters –diff - a program to report difference in text files –wc - a program to count number of characters, words, and lines in a text file –In “chapter 1 of ‘man’ pages” along with details of ‘shell’ facilities

15 Unix shell It is the “shell” that accepts and acts on the commands of a Unix user. When people say they “know how to use Unix” what they usually mean is that they know how to make simple use of a Unix shell ( there are several “shells” that differ slightly, each is someone’s favorite - you will use “sh” by default, many students change this to “bash”, other quite popular shells are “ksh” and “csh” )

16 Unix shell Shell? Well, it went around the lower levels of Unix –shielding users from low level kernel –shielding low level kernel from users

17 Unix –origins –organization kernel, libraries, tools and utilities, shell –shell command interpreter, shell scripting language, commands start other programs, some standard program libraries, extensibility –time-share system controls on users

18 Unix ‘shell’ When working interactively, you have to be able to tell the operating system what program you want to run, and what data it is to use. Original (1960s) time-share systems had simple “command line interpreters” –commands defined by keyword (e.g. EDIT, COMPILE, PRINT, RUN) and took arguments COMPILE CODE=MYPROG OPTIMIZE=3 RUN TIME=20 INPUT=MYDATA OUTPUT=PRINT

19 Unix ‘shell’ Unix developers wanted something much more sophisticated –handle repetitive tasks (e.g. run program XXX for each data file in a given directory) –use output from one program as input to next –run program X1, if successful continue with program Y1, otherwise print message and run program Z1, –...

20 Unix shell Unix guys decided that what they basically needed was an interpreter for a slightly simplified “programming language” (based on C) variables (“environment variables”) –loop and test constructs –mechanisms for starting programs and passing “command line arguments” ( this part much the same as commands in earlier operating systems ) –mechanism for putting programs together so output from a program could go to terminal, or to a file, or be used as input for another program

21 Unix shell The “shell” is an interpreter program. –prompts the user for input –reads the inputs that the user types at a terminal –identifies commands, sorts out arguments and starts appropriate programs –deals with any of the more complex looping and selection constructs available in the shell language

22 Unix shell Typical use is: –enter a single command ( with arguments as needed ) –wait for shell to process it But: –can set environment variables –can type in a little “shell code” and then have the shell interpret it immediately –write “shell scripts” ( programs in shell language ) and store these in files, these scripts can then be used as extra commands

23 Unix shell A small number of commands are actually built into the shell interpreter program itself. Most require “shell” to start another program –the programs that you can start with shell commands are mainly kept in a few standard file directories (folders)

24 Unix shell Command repertoire is easily extended. All those little utilities - grep, wc, … - become commands by simply moving the programs into the standard directories used by shell. You can add your own programs as commands (compiled C, C++, Java, or ‘shell scripts’) - ( you have to note, in an environment variable, details of where you store your extra programs so shell knows where to find them )

25 Unix shell You can build up special purpose “commands” by using the shell’s facilities to combine simpler commands –e.g. you need to count the number of calls to some function Foo() in a file so you use grep to find the lines with calls to Foo() pass the output from grep to wc which will count the number of lines

26 Unix –origins –organization kernel, libraries, tools and utilities, shell –shell command interpreter, shell scripting language, commands start other programs, some standard program libraries, extensibility –time-share system controls on users

27 Unix as a time-share system Unix is intended to be a multi-user system –multiple terminals can be connected –computers have sufficient memory to keep many users’ programs in main memory, ( but some code and data are still “swapped” to/from disk ) –time-slicing applied your program may get up to 0.1 seconds of CPU time, then CPU switches to another user

28 Unix as a time-shared system All time-shared systems have to have controls on users –users identify themselves (password controlled login) –system keeps track of user-id determines which files can be accessed determines how many programs can be run (you can have several running at same time) determines limits on number of files and total storage used

29 Unix users Two levels of user: –“root” the system’s administrator (or “guru”) who controls all aspects of Unix use (including users’ passwords, files, programs,..) –everyone else subject to restrictions

30 Unix users and “groups” Unix also defines “groups” ( remember, Unix meant to help groups of cooperating programmers ) –Individual users can be members of more than one group ( a command changes your effective group ) –Groups members can be given shared access to certain files. –You have a default group ( all undergraduates in same group ). –You may be allocated to extra groups for subjects like CSCI205, CSCI311 and CSCI321,

31 Unix users Controls on users (and groups) are tied in with the way Unix organizes files. Recorded with every file are details of –owner (user) –group Controls on access to files distinguish user, group, and other (“root” has unrestricted access to all files )

32 Unix –time-share system controls on users –file system

33 File system The Unix file system is a little more elaborate than the systems that you are used to on Macs and PCs. There you have: –disk folders on disks –files in folders –folders in folders etc

34 Unix file system The Unix file system has a similar hierarchical arrangement; –rather than files and folders on disks, its described in terms of a tree structured hierarchy Differences? –Unix file system integrates everything! all mounted disks form part of single hierarchy all devices represented by files,...

35 / /tmp /dev/bin/packages/usr/pub Some directories tmp a place for temporary files dev “files” for devices like terminals, disks, etc bin directory where many of simple command programs are kept (‘ binary’ ) packages directory for Sun’s compilers etc pub public files (some general info. etc) usr /usr/bin more shell commands /usr/include “header” files for libraries

36 Unix file system Each individual user has own directory ( traditionally, individual directories were subtrees of /usr, but more likely your directories will be located in another part of the file system ). Files and directory access –read( for directory this means you can get a list of files it contains ) –write ( change contents of file, add/remove files from directory ) –execute ( access subdirectories, run a file if it’s a program )

37 Access to files and directories Directory access settings will keep you out of those parts of the file system that you shouldn’t see - most of file hierarchy is actually accessible as Unix traditionally let users explore. Your own directory will have access controls keeping others from seeing your files; files that you create will be created so that only you can read and change them.

38 Unix –time-share system controls on users –file system –using Unix

39 You and Unix On Unix, you are represented by –your “home directory” and its subdirectory –entries in a number of system files /etc/password –your user id (e.g. ds01), a unique identifier number used by the system (e.g. 1745), your default group number, your actual name, your “shell”, (but not your password) –When you login, Unix checks your password, notes details of user and group, starts a shell with current directory set to your home directory

40 Customisation of Environment You can “customise” your Unix environment, –setting things like prompt string –changing directories where shell will look for programs (will have to make some change here relating to use of Java) –… You do this by defining any special features that you want, the definitions go in a file in your home directory named.profile

41 Communicating with Unix Traditionally, Unix is “text oriented” –all communication in terms of typed commands and textual responses Desktop environments for graphics terminals? –Available, similar to Mac/Windows but usually less complete and less integrated –Generally, have to revert to command line operation for some tasks anyway

42 Default Unix environment Unix lab has graphics X-terminals –can use “desktop” style environments –default is “FVM2” windowing environment multiple windows –command window (“xterm” window) –textedit (or dtpad) simple unsophisticated editor –…. Popup menu in background, lets you create more of these windows Each xterm window is associated with a running “shell” program accepting commands

43 xterm $ pwd /home/cs_ug/ds01 $ ls A1 note test.cc $ mkdir JavaStuff $ cd JavaStuff

44 Not an Xterminal? If you use anything other than a graphics Xterminal (Mac, PC, old text-only terminal, dial-in line, …) –much the same as working with a single “xterm” session on an Xterminal –no access to other programs like textedit

45 Unix commands You will have to learn at least: –some basic commands commands for moving around file system, copying and moving files commands to display or print files … –use of one (or more) editor programs –use of (limited) on line help facilities on Unix

46 File system commands directories pwd“print working directory” cdchange directory lslist names of files and subdirectories option -l details of size and access controls for files option -a all files (files starting with “.” not normally shown) … mkdir“new folder”

47 File system commands files cp copy mv move rm remove (delete) pg page ( display contents of text file one “page” at a time ) cat can be used to display contents of file (like pg) or copy files (like cp) or copy several files into a single output file lp send (text) file to line printer

48 Information man display manual page for specified topic xman another version of man, may not have information on as many topics, uses a separate window to display details of topics that it knows about netscape (some of Sun documentation as files that you can display using netscape, there is a link from departmental home page to these Sun documents; most of Java documentation is in files best read via netscape)

49 Editors textedit easy to use, similar to Mac/PC-Windows editor, mouse actions, cut and paste (only works on Xterminals) ed, vi, sed standards for Unix environment, available everywhere (ed and sed are for “hackers”, too cryptic for average user) jove popular editor pico ? Learn jove or textedit for use in labs; if log in remotely, you will need to learn vi, pico, or ed as well

50 Starting Unix? Login Use commands like pwd, cd ( specify source as one of directories with subject information, e.g. /share/cs- pub/121 ), ls, … Create subdirectories in own home directory (cd, mkdir) Copy some example files into own directory (cp) Print a file (lp)

51 Starting Unix Look up info on a simple command (e.g. diff, fgrep, time, date, du, …) using man ( some programs don’t have entries in the manual ) Try “elm” (Unix mail system) –“w” and “finger” give information about other users so that you can mail them Try “nn” (news reader) Try “netscape”

52 Starting Unix Editors –textedit should have no difficulties –jove there is a special program “teachjove” that takes you through a tutorial on the use of this editor –others? Buy a book on Unix!

53 Working with Unix Plan on a hierarchy of subdirectories –one for each subject, 204, 212, 213, etc –within each subject directory have a subdirectory for each assignment In lab, use multiple xterm sessions –run netscape (viewing Java documentation) –textedit and an xterm window for compiles of Java code –you can close (iconise) windows to clear up screen space


Download ppt "Unix. Unix Intro. We use the Unix labs for CSCI213 Your backgrounds and knowledge vary, some of you are: –already Unix proficient, :-) –just starting."

Similar presentations


Ads by Google