Unix Basics.

Slides:



Advertisements
Similar presentations
UNIX Chapter 12 Redirection and Piping Mr. Mohammad Smirat.
Advertisements

1 © 2001 John Urrutia. All rights reserved. Chapter 5 The Shell Overview.
CHAPTER 2 THE UNIX SHELLS by U ğ ur Halıcı. layers in a unix system 1 Users Standard utility programs (shell, editors, compilers, etc.) Standard utility.
Linux+ Guide to Linux Certification, Second Edition
Shell Basics CS465 - Unix. Shell Basics Shells provide: –Command interpretation –Multiple commands on a single line –Expansion of wildcard filenames –Redirection.
Operating Systems - Introduction S H Srinivasan
Guide To UNIX Using Linux Third Edition
CMPE 151: Network Administration Spring Class Description Focus: system and network administration. Sequence of exercises. E.g., installing/configuring.
Introduction to Linux/UNIX. History UNIX beginnings in 1969 (Linus Torvalds is born!) AT & T Bell Laboratories (Ken Thompson & Dennis Richie) Working.
Shell Script Examples.
What is Unix Prepared by Dr. Bahjat Qazzaz. What is Unix UNIX is a computer operating system. An operating system is the program that – controls all the.
Introduction A computer system consists of hardware system programs application programs.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
CIT 140: Introduction to ITSlide #1 CSC 140: Introduction to IT I/O Redirection.
Guide To UNIX Using Linux Fourth Edition
The UNIX Shell. The Shell Program that constantly runs at terminal after a user has logged in. Prompts the user and waits for user input. Interprets command.
Shells. A program that is an interface between a user at a terminal and the computers resouces ▫The terminal may be real or an emulator The shell is.
The Shell Chapter 7. Overview The Command Line Standard IO Redirection Pipes Running a Program in the Background Killing (a process!)
Linux+ Guide to Linux Certification, Third Edition
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
1 Homework / Exam HW7 is due next class Starting Glass chapter 4 and parts of 7 Exam 3 – Class 26 –Open Book / Open Notes –Up through End of K&R Chapter.
CS465 - UNIX The Bourne Shell.
LINUX programming 1. INDEX UNIT-III PPT SLIDES Srl. No. Module as per Session planner Lecture No. PPT Slide No. 1.Problem solving approaches in Unix,Using.
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
CSCI 330 T HE UNIX S YSTEM C Shell. C S HELL SPECIFICS Startup and initialization Shell variables Prompt Alias Redirections and pipe 2 CSCI The.
1 Operating Systems Lecture 2 UNIX and Shell Scripts.
Lesson 2 1.Commands 2.Filename Substitution 3.I/O Redirection 4.Command Grouping 5.Shell Responisibilites Review of the Basics.
Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will.
I/O and Redirection. Standard I/O u Standard Output (stdout) –default place to which programs write u Standard Input (stdin) –default place from which.
Univ. of TehranDistributed Operating Systems1 Advanced Operating Systems University of Tehran Dept. of EE and Computer Engineering By: Dr. Nasser Yazdani.
Lecture 24CS311 – Operating Systems 1 1 CS311 – Lecture 24 Outline Final Exam Study Guide Note: These lecture notes are not intended replace your notes.
Chapter Four I/O Redirection1 System Programming Shell Operators.
40 Years and Still Rocking the Terminal!
UNIX shell environments CS 2204 Class meeting 4 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
Introduction to Programming Using C An Introduction to Operating Systems.
1 © 2000 John Urrutia. All rights reserved. Session 5 The Bourne Shell.
Week 9 - Nov 7, Week 9 Agenda I/O redirection I/O redirection pipe pipe tee tee.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Basic UNIX Concepts. Why We Need an Operating System (OS) OS interacts with hardware and manages programs. A safe environment for programs to run is required.
Linux+ Guide to Linux Certification, Second Edition
Agenda The Bourne Shell – Part I Redirection ( >, >>,
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
Lesson 8-Specifying Instructions to the Shell. Overview An overview of shell. Execution of commands in a shell. Shell command-line expansion. Customizing.
Operating Systems and Using Linux Courtesy of John Y. Park 1.
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Linux Administration Working with the BASH Shell.
Implementation of a simple shell, xssh
Shell Features CSCI N321 – System and Network Administration
Implementation of a simple shell, xssh (Section 1 version)
Andy Wang Object Oriented Programming in C++ COP 3330
Implementation of a simple shell, xssh
CSE 374 Programming Concepts & Tools
The Linux Operating System
Introduction to Operating System (OS)
CSE 303 Concepts and Tools for Software Development
Sarah Diesburg Operating Systems CS 3430
Operating Systems and Using Linux
An Introduction to UNIX System --- Cosc513 Presentation
John Carelli, Instructor Kutztown University
Introduction to Linux/UNIX
Shells, Help, and Paths.
Operating Systems and Using Linux
Chapter Four UNIX File Processing.
Linux Shell Script Programming
Operating Systems and Using Linux
Chapter 3 The UNIX Shells
Presentation transcript:

Unix Basics

Outline OS Basics Shell Basics Process I/O, Redirection & Pipe

What is Operating System? People Word processor Web browser etc. } Application Operating System Compilers Shell etc. } System Programs Physical devices Micro-architecture Machine language } Hardware

OS Concepts OS: protected library of useful functions OS Functions: Standard library: provide standard facilities (abstractions) that everyone needs. Coordinator: allow several things to work together in efficient and fair ways (resource management).

UNIX UNIX is a multiprogrammed, timeshared operating system Multi-programmed: OS runs multiple processes simultaneously Process: running program Timeshared: multiple users share the system simultaneously

OS Families Unix Microsoft Windows MacOS And many many more … AT&T: System V Berkeley: BSD Sun: Solaris, SunOS IBM: AIX etc. Microsoft Windows Win2000, WinNT, WinXP MacOS And many many more …

Unix & C Programming Language Unix is written in C C is a programming language on Unix Who comes first? Programming languages .vs. Human Languages

Outline OS Basics Shell Basics Process I/O, Redirection & Pipe

Shell What is “Shell”? What shells are there in UNIX? Command-line interface to the OS Interpreter Environment A separate program, and not part of the OS What shells are there in UNIX? C Shell Bourne Shell bash tcsh etc.

C-Shell Invented by Bill Joy Commands Built-in commands Programs Parent Process Child Process Invented by Bill Joy Commands Built-in commands Programs Executables Shell scripts Wait for the command from the user Execute the command Wait for the command to finish Command finished Command finished

Command format command [command args] [shell args] Example: Command can be a built-in or a file name For a file name, where to find the file? PATH Example: ls /home/yao cat schedule > mysched

Command Helpers “which” command will tell you where the command is found in the path. “man” command can get the information about commands and standard C library functions. “command -h” or “command —help” to get brief summary of the usage of “command” in GNU release

Multiple Commands cmd_1; cmd_2; …; cmd_n Example: Execute sequentially Prompt returns when the last one finishes No waiting among commands Appropriate for a set of commands that forms a logical group Example: mkdir proposal; cd proposal; ls cd utils; cc –o gets gets.c; cd ..

Command Groups (cmd_1; cmd_2; …; cmd_n) Executing without affecting the current environment Environment: the set of characteristics describing a user’s working area Creating a subshell Example: (cd utils; cc –o gets gets.c)

Environment Variables User environment: special information, e.g. login directory, your mailbox, your terminal type, etc. Environment variables: maintains the special environment information mentioned above Can be passed to programs executed from the shell and affect the programs’ behavior, e.g. default printer, mailbox, TERM in vi

Environment Variables (cont.) setenv VARNAME string unsetenv VARNAME Use: $VARNAME Show all variables: env (or printenv) Conventionally all cap Examples: PATH HOME

Shell Variables Internal to the shell set name = value unset name Use: $name Show all variables: set Examples: path: kept sync by shell noclobber: prevents redirection from overwriting an existing file. (wc foo.c >! /tmp/out) status

Outline OS Basics Shell Basics Process I/O, Redirection & Pipe

Unix Process Basics Process Process tree Running program Run the same program twice? Process tree ps: ps aux pstree Init login csh pine gcc login httpd sshd orphans csh Proc_1 pine Proc_2 Proc_3

Standard I/O for Each Process Standard I/O connections (file descriptors) stdin: standard input (e.g. terminal keyboard) stdout: standard output (e.g. terminal screen) stderr: standard error (e.g. terminal screen) A typical UNIX process reads its input from stdin, writes its output to stdout, and any error messages to stderr.

Standard I/O for Each Process (cont.) Inherited from the parent Shell can control the file descriptors of its children (redirection) This is a very powerful feature of UNIX, as it means the shell can make a process read/write different things without modifying the program, e.g. files, devices, another process.

Process Return Value A UNIX process can return a status value to its parent when it exits Zero: OK Non-zero: Error The parent uses the value to decide what to do next. The C-shell stores this value in a variable called status.

Outline OS Basics Shell Basics Process I/O, Redirection & Pipe

Why redirection or pipe? You want to store the result in a file instead of print them out on the screen You want to prepare the input in a file instead of typing them every time the program is run You want to connect several UNIX tools in a chain to finish a more complex work. The data flow through those tools. The output of a previous tool will be the input of the next.

Redirection Default standard I/O: the same as the shell Shell arguments in the command line can specify the change of the standard I/O Examples: Write stdout to a file: wc foo.c > /tmp/foo Append stdout to a file: wc foo.c >> /tmp/foo Write stdout & stderr to a file: wc foo.c >& /tmp/foo Ignore stdout: wc foo.c > /dev/null Read stdin from a file: wc < foo.c Read stdin from a device: wc < /dev/null

Output Redirection Summary Create/truncate and write Append Stdout > >> Stdout+stderr >& >>&

Pipe cmd_1 | cmd_2 | … | cmd_3 Connect a program’s standard output with another program’s standard input Example: who > temp; wc –l < temp; rm temp who | wc –l cat dict1 dict2 dict3 | sort +1 | pr | lpr cc pcman.c |& more cc pcman.c |& pr | lpr

Pipe (cont.) What commands can be connected with pipes? Example: Command on the left must write to the standard output Command on the write must read from the standard input Example: ls | rm Result: Broken pipe line

Acknowledgement Shilong Yao John H. Hartman, Classnotes for Csc352-Spring03, CS Dept., University of Arizona, 2003 Gail Anderson, Paul Anderson, The Unix C Shell Field Guide, Prentice Hall, 1986 Andrew S. Tanenbaum, Modern Operating Systems (2nd Ed.), Prentice Hall, 2001