Unix Environment What we learn this time



Yüklə 454 b.
tarix08.10.2017
ölçüsü454 b.
#3733


Unix Environment

  • What we learn this time:

    • Big figure of Unix environments
    • basic concepts and design principles of Unix
    • Shells
    • File structures, naming, permissions
    • Scripting

What about Unix

  • Designed by programmers for programmers (i.e. hackers)

  • a.k.a PWB (programmer’s work bench)

  • Who wrote Unix and where?

    • Ken Thompson and Dennis Ritchie
    • AT&T Bell Labs
    • Add-on utilities/programs designed by independent programmers


Power

  • The Unix philosophy “is the idea that the power of a system comes from the relationships among programs than from the programs themselves”

  • Interface is minimal, but allows programs to be strung together

  • Teaches programming

  • Teaches “hacking”, the ability to build a tool when one doesn’t exist



Unix Core

  • The core of the Unix OS is called the kernel

  • Variety of Unix flavors:

    • FreeBSD
    • Linux
    • Darwin (Mac OS X)
  • Most functionality is the same between implementation

    • vi, cd, man
  • Built-in commands and utilities behavior might differ

    • FreeBSD make vs. GNU make
  • POSIX (Portable Operating System Interface)

    • IEEE standard that tries to work toward apps interoperability
    • System V vs. Darwin
      • are much different


Communication with Unix

  • A user never “talks” directly to a Unix OS

  • What do these programs use to talk to the OS?

    • System calls
  • Three programs that are used to communicate with the OS are:

    • shell
      • a command interpreter
    • Interactive command
      • runs inside a tty (teletype) and reads your typing
      • Text editor (i.e. vi)
    • GUI
      • implemented with a set of running programs


Tools working together

  • The Unix programs are tools

    • specific in function
    • multi-purpose
  • To make them general-purpose:

    • Must be data independent
      • Output of any program should be input for another
      • Info needed by a program should be contained in a data stream passed to it or passed at command prompt
      • If no arguments are passed to a program, read stdin(keyboard) and print stdout(screen)
  • Programs meeting the above criteria are called filters

    • Pipe – take output from program on left and feed to input of program on right
      • E.g. cat /etc/passwd | grep –i anyusername


Shells

  • What is a shell?

    • A command interpreter
    • “protects you from the kernel”
    • It really protects the kernel from you


Many Shells

  • Bourne shell (sh)

    • Creator Steve Bourne in the early 80’s
    • First shell Used for shell programming
  • C shell (csh)

    • Created at UCB their Unix implementation in the early 80’s
    • Users wanted more familiar syntax
    • More features (for interactive uses) than sh (e.g. job control and history)


Many Shells

  • Korn shell (ksh)

    • Created by David Korn in the mid 80’s
    • Compatible with sh but having most features of csh
    • Features history editing (a.k.a. command-line editing)
    • Was available on System V
    • Public-domain version is pdksh
  • T-shell (tcsh)

    • has all csh features and less bugs
  • Bourne-again shell (bash)

    • Offered by FSF (free software foundation)
    • Similar to ksh and csh
    • Command-line editing


Many Shells

  • Z shell (zsh)

    • hybrid
  • Plan 9

    • Created by Bell Labs
  • Tcl (tclsh), wish



What’s my shell?

  • Check your prompt

    • Usually bash uses $
    • Usually csh uses %
    • Usually tcsh uses >
    • Superuser “root” usually is #
  • grep yourusername /etc/passwd

  • echo $SHELL



Programming the Shell

  • The shell is a complete programming language

  • Easy

    • As simple as a single complex command saved in a file
    • Look at the example used in the text mac2unix


Converting a MAC file to Unix



Internal and External Commands

  • Internal commands

    • built into the shell
    • the shell performs the command
      • E.g. chdir or cd
  • External commands

    • Require the shell to fork and exec and a subprocess will start
      • E.g. ls


Internal & External Commands

  • Shell checks what type of command the user is trying to run

    • Check if built-in
    • Else check if absolute path
    • Else check alias (except bash)
    • Check for executable in search path
      • Search path is a list of dir that the shell must check
      • An environment variable PATH lists these dir
        • Look at an example
      • Search path is specified in the shell start up files


Kernel and Daemons

  • Unix is a multi-user OS

  • The kernel is the main program or the heart

    • Assigns memory to programs running
    • Partitions time fairly
    • Handles the I/O, etc.
    • Think of it as a traffic cop or a manager
  • Daemons

    • Group of “helper” programs
    • help the system with mail, network comm, tracking time, etc


Kernel and Daemons

  • ps command

    • prints information about active processes
  • shutdown command



Unix Filenames

  • Filenames can be made up of any character set except a slash ( / )

    • Case sensitive
    • Underscores are handled for word separation
    • Periods are used by some programs to separate filenames from file extensions
    • Filenames beginning with a dot (.) are treated differently by the shells
  • No concept of file version

  • Deleted file is gone forever.



File Extensions

  • MS files are filename.extension

  • Unix has no specific rules about file extensions

    • Some programs such as the C compiler will look for file extensions


Wildcards

  • * - matches any character

  • ? – matches any single character

  • filename.[character-set]

    • To match a particular group of characters, say all files that end with an F or P
      • E.g. filename.[FP]
  • One exception

    • slash (/), no matches can be made against it


Hierarchical File System



Home dir

  • /home/username – your own place

  • Store any file you like



Pathnames

  • Locate files

  • Current directory – currently working directory

  • Absolute vs. relative paths

    • pwd vs. cd
    • . Current dir
    • .. Parent dir
    • ~ your home dir
    • ~username username’s home dir


File Permissions

  • UID – user ID

  • Every user belongs to a group

    • groups
  • When a file is first created, its owner is the user that created and the primary group in which they belong to.

  • chgrp – change group

  • chown – change owner

  • chmod – change permissions on file(s)



Superuser (root)

  • Do we need to say more?



Unix Files

  • Unix is file oriented

  • Everything is treated as a file

  • File is a stream of bytes with no special structure, but it is defined by the programs that use it

  • Files use newline character instead of carriage return



Scripting

  • Scripting languages and apps differ from compiled languages, but how?

    • Interpreted as run
  • Perl

    • Practical Extraction and Report Language
    • Created by Larry Wall
  • Python

    • More structured and verbose than Perl


Networking and comm

  • ssh

  • sftp

  • scp

  • telnet

  • rsh

  • ftp

  • write

  • talk



X Windows

  • X Consortium and XFree86 Project

  • A system that divides up the large scale screen of a workstation into multiple virtual terminal or windows

  • Runs on many different kinds of hardware

  • Let’s you run a program on a remote computer while the program’s windows are displayed on your local terminal



Yüklə 454 b.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©www.genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə