CS132: Programming in C and Guide to the Unix System - PowerPoint PPT Presentation

1 / 42
About This Presentation
Title:

CS132: Programming in C and Guide to the Unix System

Description:

3. In this tree only 2 entities exist: directories and files ... b. in different directories (on different paths) are not the same file ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 43
Provided by: jie5
Category:

less

Transcript and Presenter's Notes

Title: CS132: Programming in C and Guide to the Unix System


1
CS132 Programming in Cand Guide to the Unix
System
  • Instructor Anandha Gopalan
  • TA Jie Xu
  • Yuqiang Huang
  • Course Web Page http//www.cs.pitt.edu/axgopala/
    cs132/cs132.html

2
Lecture 1 Unix History and Background
  • Homework
  • Read Chapters 12 of Sarwar

3
  • A. History of UNIX
  • 1. Developed in period 1969-73 by K. Thompson et
    al. at Bell Labs
  • 2. First written in assembler then converted to C
    when C was running well
  • 3. Today, all but kernel in C along with almost
    all UNIX apps and the C compiler itself
  • 4. Originally written on and for a DEC PDP-7, 8K
    mem, paper tape storage

4
  • 5. Developers wanted an easy to use portable OS
    w/applications. None/few apps existed so
    computers werent much fun. Keypunch and
    tapepunch created program decks tapes.
  • 6. With its success, was rewritten to power a DEC
    PDP-11, 24K mem (16sys, 8prg), 512K HD
  • 7. From 1973-1980 was rewritten for other
    operating platforms
  • 8. DOS was partly based upon UNIX

5
  • B. What is UNIX
  • You don't need an OS to run applications. The OS
    itself is a standalone program not running
    "under" some other OS. But, their existence
    simplified the use of computers and the creation
    of all other software to such an extent that a
    long time ago the die was cast that has given us
    OS's probably forever...

6
  • 1. Operating System
  • a. Programs/software that allow a user to run an
    application
  • b. Provides standardized and generalized
    interfaces to hardware affording the programmer
    more flexibility and less work in writing
    programs
  • c. Provides a user friendly interface to the
    system making it easier for a user to do less
    work and remember fewer commands when interacting
    with the system

7
  • d. Is a central and unique repository for all the
    code that controls the hardware (DOS wasn't so
    you could bypass it and cause problems). When the
    OS is the unique location for system interface
    then the app writer doesn't have to concern
    himself with changes in the hardware, only the OS
    writer does that and he tries to make the impact
    of the change transparent to the app writer

8
  • e. Provides an intangible skin or protective
    layer around the "computing system" to reduce the
    risk that a user or application causes a
    catastrophic fault and to mitigate the
    consequences of any fault. Catastrophic includes
  • loss of some or all user data
  • corruption of OS data or files causing the
    "system" to operate improperly (lockups, crashes,
    diskdrives won't shutdown)

9
  • damage to system hardware (overdriving monitor
    scan frequencies, etc.)
  • security breach allowing access to private
    data/files on a secure system

10
  • 2. Functional Organization
  • a. Hardware
  • Motherboard
  • CPU
  • RAM Memory
  • Storage media (HDD, FDD, CD, Mag tape, etc)
  • b. Kernel
  • task scheduler
  • storage manager
  • hardware interface

11
  • c. Shell
  • command interpreter
  • retrieves initiates execution of stored
    programs
  • creates and executes shell scripts
  • admin capability command aliases, command
    history, auto-completion, etc
  • provides the immediate user environment
  • d. Utilities Applications

12
  • 3. Distinguishing Features
  • a. Multiuser Multitasking
  • b. Portable OS's are machine/hardware dependent.
    Win, Linux, BeOS run on intel processors while
    MAC OS runs on Motorola processors.
  • c. Character User Interface (CUI) or command
    consol interface (not GUI)

13
  • d. Case sensitive (DOS wasnt, Windows isn't)
  • e. Provides the user and the hardware, security
    thru access control and storage media
    partitioning
  • f. Device independent I/O (all devices appear to
    be files)
  • g. Multiple Shells
  • h. Files are just bytes not txt, exe, jpg,
    etcetera

14
  • 4. Unix in today's world
  • a. Dominant OS in world
  • In the range of 62-75 of all commercial
    installations use Unix
  • b. Proliferation of distributions
  • About 20 different active versions for ex
    HP-UX, System V, Free BSD, Net BSD, Linux,
    Solaris etc.

15
  • c. Standardized but
  • Distributions may or may not support all
    features, support features differently
  • Many shells each one different from the other
    and offer different commands
  • d. Some features and commands won't be addressed
    here

16
Lecture 2 UNIX Fundamentals
  • Homework
  • Read Chapters 3, 6, 7 of Sarwar

17
  • A. Find an access point
  • LAN computer
  • dedicated terminal
  • telnet via internet
  • B. Login or Get on the system
  • login gt Same as e-mail name
  • Password gt System gives default, change to your
    own
  • Daily Message
  • System prompt , ----gtsh, ksh, csh, tcsh, bash
    (Bourne, Korn, C, TC, Bourne Again)
  • If telneting, be sure telnet configured terminal
    vt100, port telnet, host unixs2.cis.pitt.edu
    (or other host)

18
  • C. Logout
  • logout exit Ctrl-D
  • D. Change password
  • passwd
  • Old password
  • New password (RETURN to abort)
  • Retype new password
  • password changed.
  • E. Change shell for session
  • sh csh tcsh ksh bash
  • Exit from shell exit (terminates logon session
    if in uppermost shell)
  • Shells to use for this class are csh or tcsh

19
  • When we look around what do we see?
  • Once logged onto a system the next thing you do
    is file manipulation in one form or another,
    otherwise you arent doing anything but looking
  • A. Directory Tree Structure
  • 1. All OSs implement a file control system
  • 2. UNIX and most, if not all, others use a
    directory tree structure
  • 3. In this tree only 2 entities exist
    directories and files
  • 4. Files are organized in/under directories

20
  • 5. UNIXs tree is relatively standardized
  • Root directory is named "/" (explain
    frontslash)
  • First level directories shown below
  • Subdirectories of higher directories
  • All standard directory names use small letters

21
  • unixs2.cis.pitt.edu bert.cs.pitt.edu
  • Unix System V Release 4.0 Digital Unix v4.0B (Rev
    564)
  • / /
  • afs/ afs/
  • cdrom/ cdrom/
  • dev/ dev/
  • devices/
  • etc/ etc/
  • export/
  • home/ home/
  • kernel/
  • lostfound/
  • mdec/
  • mnt/ mnt/
  • net/
  • opt/ opt/

22
  • platform/
  • paging/
  • proc/ proc/
  • ris/
  • sbin/ sbin/
  • shlib/
  • subsys/
  • sys/
  • tftpboot/
  • tmp/
  • tmp.old/
  • tmp_mnt/
  • usr/ usr/
  • var/ var/
  • vol/
  • xfn/

23
  • B. At Home on Login
  • 1. By default/design we always log into (start up
    in) our home directory, login directory. This is
    where you are after the system welcomes you
    onboard
  • 2. Home directory name is, by default/design,
    same as initial e-mail account name!
  • 3. Which is somewhere under the "/" (root)
    directory, usually under "home/". Location is
    system dependent.

24
  • C. Terminology is Important in Programming
  • 1. All programs are files but, all files are not
    programs
  • Files gt data, programs
  • Programs gt executable instructions, binary
    images, script/macro, "run on their own", etc.
  • Data gt text, databases, graphics, audio, etc.

25
  • D. Good Programming Habits
  • 1. Learn to move through the directories!
  • 2. Create directories with meaningful names to
    you!
  • 3. Always put files in a meaningful directory.
  • 4. Dont put all files in the same place.

26
  • Pathnames and Filenames
  • A. Pathname or Path
  • 1. A sequence of directory names leading to a
    final directory or file
  • 2. Two flavors
  • a. Absolute path is always referenced from the
    root (/afs/cs.pitt.edu/usr0/johng/public/assignmen
    ts)
  • b. Relative path always referenced from the
    working/current directory (public/assignments)
  • 3. The directory youre currently in is
    "working/current directory"
  • 4. The system root directory is ALWAYS "/"
  • a. Its name is "/"
  • b. Its name IS NOT root

27
  • B. Filenames
  • 1. Determined by user
  • 2. All alphanumeric characters acceptable except
    _at_'ltgt!\/"?() may cause problems
  • 3. Piece after last period called "extension"
  • 4. Maximum length of 255 characters including any
    extension and intervening periods

28
  • 5. Files w/same name
  • a. in same directory (on same path) are the same
    file
  • b. in different directories (on different paths)
    are not the same file
  • 6. UNIX is case sensitive MY_FILE.TXT is not the
    same as mY_FILE.TXT or My_file.txt
  • 7. Any filename beginning with a period (.) is
    invisible/hidden

29
  • C. Good Programming Habits
  • 1. Use meaningful names
  • 2. Use _ instead of space. Fewer problems
    w/commands which cant see spaces.
  • 3. Establish your own naming convention small
    letters for directories, caps for files,
    whatever...

30
  • Directory Utilities
  • A. Where are you
  • Path to Working Directory
  • pwd
  • /afs/cs.pitt.edu/usr0/johng/public

31
  • B. What is in the directory
  • List
  • ls -alF... file1 file2 file3...
  • No argument lists current directory, w/argument
    lists directory on path
  • Great Options (GOs)
  • a - list all files including hidden
  • l - long form indicates types, permissions,
    links, owner, size, create time
  • F - indicate file type as suffix (dir, nonexe,
    exe, symlink gt /, nada, , _at_)

32
  • C. Create a directory
  • Make Directory
  • mkdir -mp path/name
  • No path creates in working directory
  • . - Current directory
  • .. - Parent directory
  • / - System root directory
  • - Path to users login directory
  • GOs
  • m mode - set access mode (ugo/-/rwx)
  • p - create entire path, must have permission to
    write

33
  • D. Delete a directory
  • Remove Directory
  • rmdir -p path/name
  • No path removes from working directory
  • GOs
  • p - remove entire path as long as directories are
    empty, must have permission to write
  • E. Change to another directory
  • Change Directory
  • cd path
  • No argument goes HOME, and space required after cd

34
  • File Utilities
  • A. What kind of file is it
  • Filetype
  • file file1
  • Looks at name and first several lines of file to
    determine the type. Not always correct.

35
  • B. What is in the file, and 2 becomes 1
  • Catenate
  • cat -n... file1 file2 file3...
  • Single argument lists file contents, multiple
    arguments concatenates to stdout
  • GOs
  • n - line numbers on output

36
  • C. Copy the file
  • Copy
  • cp -i... source destination
  • copies contents of source onto destination, if
    destination exists then overwritten but name
    remains destination
  • GOs
  • i - prompt to overwrite

37
  • D. Move Rename a file
  • Move
  • mv -i source destination
  • move file from source path to destination path,
    same path w/different names simply renames file
  • GOs
  • i - prompt to overwrite

38
  • E. Delete a file
  • Remove
  • rm -i... path/name
  • delete file from specified path, filename only
    implies current/working directory
  • GOs
  • i - prompt to remove

39
  • E-Mail With Pine
  • A. Features of Pine
  • 1. Fullscreen e-mail client
  • 2. Onscreen main menu
  • 3. Command mode runs in parallel with other modes
  • 5. Supports attachments
  • 6. Easy for beginners but powerful if advanced
  • 7. Available context commands displayed at bottom
    of screen
  • 8. Execute most commands w/o ENTER saves time,
    less hassle

40
  • B. Getting in and Getting out
  • 1. To start gt pine ... address
  • w/ address, message is automatically addressed
    to recipient
  • w/o you start in To location
  • w/ -i option immediately enters inbox
  • 2. To exit pine gt q

41
  • C. Significant main menu commands
  • 1. C - compose new message, arrive in To
    location, arrow keys to other lines
  • 2. I - inbox messages displayed, arrive at first
    message in list, ENTER to read
  • 3. L - list available message folders, select
    with arrow keys, ENTER to open
  • 4. S - setup personal preferences
  • 5. Q - quit pine

42
  • D. Composing messages
  • 1. Arrow keys move cursor
  • 2. DELETE removes to left of cursor, Ctrl-d
    removes at and to right of cursor
  • 3. Attachments are added at any time w/Ctrl-j, or
    Ctrl-t if in Attachment position
  • 4. Cancel message creation w/Ctrl-c
  • 5. Send completed message w/Ctrl-x
Write a Comment
User Comments (0)
About PowerShow.com