The Shell Chapter 7. Overview The Command Line Standard IO Redirection Pipes Running a Program in the Background Killing (a process!)

Slides:



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

CIS 118 – Intro to UNIX Shells 1. 2 What is a shell? Bourne shell – Developed by Steve Bourne at AT&T Korn shell – Developed by David Korn at AT&T C-shell.
EMT 2390L Lecture 4 Dr. Reyes Reference: The Linux Command Line, W.E. Shotts.
A Practical Guide to Fedora and Red Hat Enterprise Linux Unit 4: More Command Line Interface (CLI) Chapter 7: The Linux Shell By Fred R. McClurg Linux.
Processes and Job Control. Foreground and Background (1)  Unix is a multi-tasking operating system –some of these tasks are being done by other users.
A Practical Guide to Red Hat ® Linux ®, Third Edition. © 2007 Mark G. Sobell, Prentice Hall,
1 © 2001 John Urrutia. All rights reserved. Chapter 5 The Shell Overview.
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need.
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.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
Introducing the Command Line CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes.
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.
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
CS 497C – Introduction to UNIX Lecture 20: - The Shell Chin-Chih Chang
Information Networking Security and Assurance Lab National Chung Cheng University 1 What Linux is? Free Unix Like Open Source Network operating system.
More Shell Basics CS465 - Unix. Unix shells User’s default shell - specified in /etc/passwd file To show which shell you are currently using: $ echo $SHELL.
The Unix Shell. Operating System shell The shell is a command interpreter It forms the interface between a user and the operating system When you log.
Guide To UNIX Using Linux Third Edition
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need.
Lesson 1. PC vs. Multi-user System  Personal Computer – each user gets his/her own processor (or multicore processor).  Multi-user system – The processor,
Lesson 11-Locating, Printing, and Archiving User 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.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell The Shell The agency that.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Guide To UNIX Using Linux Fourth Edition
Unix Shells Based on Glass & Abels’ Book CS240 Computer Science II.
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 8 Shell.
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.
CS 2061 Shells Also known as: Unix Command Interpreter.
Linux+ Guide to Linux Certification, Third Edition
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
Guide to Linux Installation and Administration, 2e1 Chapter 7 The Role of the System Administrator.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
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.
Adv. UNIX: Shell/21 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information about the Shell
Lesson 2-Touring Essential Programs. Overview Development of UNIX and Linux. Commands to execute utilities. Communicating instructions to the shell. Navigating.
1 Unix Seminar #1 T.J. Borrelli Lecturer for CS and NSSA February 6th, 2009.
Chapter Four I/O Redirection1 System Programming Shell Operators.
1 Lecture 6 Introduction to Process Management COP 3353 Introduction to UNIX.
Week 9 - Nov 7, Week 9 Agenda I/O redirection I/O redirection pipe pipe tee tee.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: which, passwd, date, ps / kill Working with Files: file, touch, cat, more, less, grep,
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Linux Commands C151 Multi-User Operating Systems.
Chapter 5: The Shell The Man in the Middle. In this chapter … The command line Input, output, and redirection Process management Wildcards and expansion.
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
Linux+ Guide to Linux Certification, Second Edition
Lecture 1: Introduction, Basic UNIX Advanced Programming Techniques.
Agenda Managing Processes (Jobs) Command Grouping Running jobs in background (bg) Bringing jobs to foreground (fg), Background job status (jobs) Suspending.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
Lesson 8-Specifying Instructions to the Shell. Overview An overview of shell. Execution of commands in a shell. Shell command-line expansion. Customizing.
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
IT244 - Introduction to Linux / Unix Instructor: Bo Sheng
Introduction to Shells
Part 1: Basic Commands/Utilities
C151 Multi-User Operating Systems
Basic UNIX OLC Training.
The Linux Command Line Chapter 6
Chapter Four UNIX File Processing.
Linux Shell Script Programming
Chapter 3 The UNIX Shells
CSC 4630 Meeting 4 January 29, 2007.
Lecture 6 Introduction to Process Management
LPI Linux Certification
Presentation transcript:

The Shell Chapter 7

Overview The Command Line Standard IO Redirection Pipes Running a Program in the Background Killing (a process!)

The Command Line The shell executes a program when you give it a command The line that contains the command, including any arguments, is called the command line

The Command Line Syntax Dictates the ordering and separation of the elements on a command line e.g. command [arg1] [arg2] … [argn] Not all commands require arguments Some commands do not allow arguments Some commands require specific arguments

The Command Line Syntax (cont.) Arguments A sequence of nonblank characters is called a token or word An argument is a token, such as a filename, that a command acts upon e.g. $ cp temp tempcpy temp is arg1 tempcpy is arg2

The Command Line Syntax (cont.) Options an argument that modifies the effects of a command more than one option typically be specified options are specific to and interpreted by the program (command), not the shell most utilities allow the grouping of options after a single hyphen (-) help option  Many utilities display a help message when the -help option is used  All GNU Project utilities accept --help

The Command Line Syntax (cont.) Options (cont.) Remember! The command must be in the search path, or a path must be supplied on the command line

The Command Line Executing the command line When a command is issued, the shell starts a new process The process is the execution of a command While the command is executing, the shell waits for the process to finish. At this point, the shell is in an inactive state called sleep

Standard Input and Output Output & Input Standard Output A place that a program can send output, such as text The program never “knows” where the output it sends to standard output is going  Could be a printer  Could be an ordinary file  Could be the screen (default) Standard Input A place that a program gets input from  Could be another program  Could be the keyboard (default)

Standard Input and Output Output & Input Standard Error A place that a program can send error messages to

Standard Input and Output The Screen as a File Besides ordinary files, directory files, hard links, and soft links, Linux has an additional type of file - device files Device files reside in the Linux file structure (usually under /dev) Represent a peripheral device

Standard Input and Output The Screen as a File (cont.) The device name that the who utility displays after your username is the filename of your screen e.g. /dev/pts/4 When working with multiple windows, each window will have its own device name You can read from and write to this device file as though it were a text file

Standard Input and Output The Screen as a File (cont.) e.g. Using the keyboard and screen as standard input and standard output

Standard Input and Output Redirection Allows you to alter where standard input comes from Allows you to alter where standard output goes to Redirecting Standard Output (>) redirect standard output - instructs the shell to redirect the output of a command to the specified file instead of the screen e.g. ls -l > dirlisting.txt

Standard Input and Output Redirection (cont.)

Standard Input and Output Redirection (cont.) Redirecting Standard Input (<) redirect standard input - instructs the shell to redirect a command’s input to come from the specified file instead of from the keyboard

Standard Input and Output Redirection (cont.) Appending standard output to a file (>>) - append output - causes the shell to add new information to the end of a file, leaving any existing information intact. e.g. $ cat orange this is orange $ cat pear >> orange $ cat orange this is orange this is pear

Standard Input and Output Redirection (cont.)

Standard Input and Output Pipes The shell uses a pipe to connect the standard output of one command directly to the standard input of another command The symbol for a pipe is a vertical bar (|) e.g. command_a [args] | command_b [args] is the same as: command_a > temp command_b < temp rm temp

Standard Input and Output Pipes (cont.) Filters A filter is a command that processes an input stream of data to produce an output stream of data e.g. sort

Running a program in the background So far, all commands and utilities used have been running in the foreground When a command is run in the foreground, the shell waits for it to finish before giving you another prompt When a command is run in the background, you do not have to wait for the command to finish before running another command

Running a program in the background JOBS A series of one or more commands that can be connected by pipes Only one foreground job allowed in a window or on a screen Many background jobs are allowed Running many jobs at a time utilizes multitasking

Running a program in the background JOBS (cont.) To run a job in the background, type an ampersand (&) just before [RETURN] The shell will assign a small number to the job (job number) and displays it between brackets Following the job number, the shell displays the process id (PID) number E.g. $ ls –l | lpr & [1] $ … [1]+ Donels –l | lpr

Running a program in the background Moving a job from the foreground to the background CONTROL-Z Suspends a job Shell stops the process and disconnects standard input from the keyboard bg Command to send a job to the background E.g. move job 1 to background $ bg 1

Running a program in the background Moving a job from the foreground to the background (cont.) fg Brings a job from the background to the foreground Only the foreground job can accept input from the keyboard E.g. $ fg 1

Running a program in the background Killing a job kill Aborts a background job Uses the PID or job number as an argument E.g. $tail –f outfile & [1] $ ps | grep tail pts/400:00:00 tail $ kill [1]+ Terminatedtail –f outfile

Running a program in the background Killing a job (cont.) E.g. $tail –f outfile & [1] $ bigjob & [2] $ jobs [1]- Runningtail –f outfile & [2]+ Runningbigjob & $ kill %1 $ RETURN [1]- Terminatedtail –f outfile

Filename generation/Pathname expansion When you give the shell abbreviated filenames that contain special characters (metacharacters or wildcards), the shell can generate filenames that match the names of existing files Filenames that contain these characters are called ambiguous file references The process the shell performs on these filenames is called pathname expansion or globbing

Filename generation/Pathname expansion The ? Special character Matches any single character in the name of an existing file E.g. $ lpr memo? E.g. $ ls mem memo12memo9memoalex newmemo5 memomemo5memoamemos $ ls memo? memo5 memo9 memoa memos

Filename generation/Pathname expansion The * special character Matches any number of characters, including zero characters, in a filename E.g. $ ls amemomemomemoalx.0620memosallyuser.memo memmemo.0612memoalx.keepsallymemo memalxmemoamemorandumtypescript $ echo memo* memomemo.0612memoamemoalx.0620 memoalx.keepmemorandummemosally $ echo *me amemomemosallymemouser.memo $ echo *alx* memalxmemoalx.0620memoalx.keep

Filename generation/Pathname expansion The [] special characters Causes the shell to match filenames containing the individual characters surrounded by the brackets or a range of characters E.g. $ lpr part0 part1 part2 part3 part5 $ lpr part[01235] $ lpr part[1-35] E.g. print 39 files $ lpr part[0-9] part[12][0-9] part3[0-8]

Hands On Time See ftp site for lab file: BAI517 – Ch 6-7 Utils and Shell Exercise.doc