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.

Slides:



Advertisements
Similar presentations
Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Advertisements

UNIX Chapter 12 Redirection and Piping Mr. Mohammad Smirat.
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.
Introduction to UNIX CSE 2031 Fall May 2015.
Lesson 10-Controlling User Processes. Overview Managing and processing processes. Managing jobs. Exiting/quitting when jobs have been stopped.
LINUX System : Lecture 3 (English-Only Lecture) Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University Acknowledgement.
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.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
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.
Guide To UNIX Using Linux Third Edition
LINUX COMMAND LINE INTERFACE Lab 3 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
1 UNIX essentials (hands-on) the directory tree running programs the shell (using the T-shell) → command line processing → special characters → command.
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need.
Shell - Introduction & Commands Chapter III / Part II.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
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.
Agenda Basic Shell Operations Standard Input / Output / Error Redirection of Standard Input / Output / Error ( >, >>,
Guide To UNIX Using Linux Fourth Edition
BIF703 stdin, stdout, stderr Redirection. stdin, stdout, stderr Recall the Unix philosophy “do one thing well”. Unix has over one thousand commands (utilities)
Unix Talk #2 (sed). 2 You have learned…  Regular expressions, grep, & egrep  grep & egrep are tools used to search for text in a file  AWK -- powerful.
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.
Command Line Variations Selected Readings in Chapters 3, 5, 6 u Project 1 kickoff u Streams & Redirection: Sections 5.2, 5.3 u Pipes and Tees: Sections.
Chapter 4 UNIX Common Shells Commands By C. Shing ITEC Dept Radford University.
The Shell Chapter 7. Overview The Command Line Standard IO Redirection Pipes Running a Program in the Background Killing (a process!)
1 UNIX essentials (hands-on) the directory tree running programs the shell → command line processing → special characters → command types → shell variables.
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
Module 6 – Redirections, Pipes and Power Tools.. STDin 0 STDout 1 STDerr 2 Redirections.
1 Operating Systems and Using Linux Topics What is an Operating System? Linux Overview Frequently Used Linux Commands Some content in this lecture added.
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
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.
I/O Redirection and Regular Expressions February 9 th, 2004 Class Meeting 4.
Chapter Four I/O Redirection1 System Programming Shell Operators.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: whereis, which, whoami, finger, passwd, cal, date Working with Files: cat, more, less.
40 Years and Still Rocking the Terminal!
Week 9 - Nov 7, Week 9 Agenda I/O redirection I/O redirection pipe pipe tee tee.
Manipulating Files Refresher. The touch Command touch is used to create a new, empty file. If the file already exists, touch updates the time and date.
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.
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
Lecture 1: Introduction, Basic UNIX Advanced Programming Techniques.
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.
Operating Systems and Using Linux Courtesy of John Y. Park 1.
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.
Learning Unix/Linux Based on slides from: Eric Bishop.
Linux Administration Working with the BASH Shell.
IT244 - Introduction to Linux / Unix Instructor: Bo Sheng
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
The UNIX Shell Learning Objectives:
Some Linux Commands.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands:
CSE 303 Concepts and Tools for Software Development
Basic UNIX OLC Training.
Introduction to UNIX.
The Linux Command Line Chapter 6
John Carelli, Instructor Kutztown University
Linux Shell Script Programming
CSE 303 Concepts and Tools for Software Development
LPI Linux Certification
Presentation transcript:

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 Operating System © Copyright 2013, All Rights Reserved

Command Line Interface (CLI) Advantages ◦ More options ◦ Wildcards ◦ Stack multiple commands together ◦ Scriptable ◦ GUI not always available (server, telnet, single user mode) ◦ No clickity-clackity-click!

Editing the Command Line set –o vi ◦ Escape begins edit of history list ◦ Slash “ / ” searches most current cmd ◦ Ex commands can’t be used ◦ Can start upon login via ~/.bashrc ◦ Carriage Return (Enter) terminates edit and executes command

Abort Command Execution Abort Command ◦ Ctrl+C: Aborts current execution

Launching Background Commands Background Execution ◦ command &

Suspended Jobs & Background Interactive Background Execution ◦ Ctrl+Z: Suspends current execution ◦ bg : Move suspended job to background

Suspended Jobs & Foreground Interactive Foreground Execution ◦ fg : Move background job to foreground

Listing Background Jobs List jobs running in background Every job has a unique job number ◦ jobs

Listing Background Jobs Every job has a unique process id

Finished Background Jobs Jobs with “Done” status

Finished Background Jobs Jobs with “Stopped” status

Terminating Background Jobs Killing a background job: ◦ kill %x

Standard Input, Output & Error Three Streams in Linux OS Standard Input (STDIN) Standard Output (STDOUT) Standard Error (STDERR) command

Output Redirection Syntax: ◦ command [args] > filename Example: ◦ cat > file.txt text from keyboard second line of text Ctrl+D Caution: Redirecting output can destroy a file!

Input Redirection Syntax: ◦ command [args] < filename Example: ◦ sort < file.txt

noclobber: Prevent Overwrites Turn on: ◦ set -o noclobber Caution: noclobber does not prevent overwrites from cp or mv

Overriding noclobber Clobber regardless of noclobber: ◦ set -o noclobber echo "contents" > file.txt echo "no can do" > file.txt echo "clobber me" >| file.txt Turn off: ◦ set +o noclobber echo "clobber it" > file.txt

/dev/null: The Bit Bucket Data Sink: ◦ echo "gone!" > /dev/null Unix Universe Black Hole: ◦ mv trash.txt /dev/null

Appending a File Syntax: ◦ command [args] >> filename Example: ◦ date >> timestamps.txt

Pipes Description: ◦ Connects standard output of one command to the standard input of another command. Syntax: ◦ command [args] | command [args] Example: ◦ cat grades | sort -n

Eliminating Temporary Files Description: A pipe can negate the need for temporary or intermediary files. Example: ◦ sort -n grades > sorted ◦ tail -1 < sorted ◦ rm sorted Syntax: ◦ sort -n grades | tail -1

Filters Description: ◦ Command that uses standard input stream to produce a standard output stream. Syntax: ◦ cmd [args] | filter [args] | cmd [args] Example: ◦ cat dates | sort | grep J

tee: Output in Two Directions Description: ◦ tee utility copies standard input to a file and sends output to standard output. Syntax: ◦ cmd [args] | tee file | cmd [args] Example: ◦ ls | tee output.out | grep txt

What is Shell Expansion One or more characters used to match a set of filenames Also known as “glob” or “globbing” The characters are called “wildcards”

Wildcard: * Star “ * ” (aka asterisk, splat) Character: ◦ Wildcard matches zero or more characters in a filename Example: ◦ ls bad* Matches: ◦ bad badland Does not match: ◦ obadiah

Wildcard: ? The “ ? ” Character: ◦ Wildcard matches any single character in a filename Example: ◦ ls verb? Matches: ◦ verbs verb1 Does not match: ◦ verb proverb

Wildcards: [] The “ [x] ” Character Set: ◦ Wildcard matches a single character contained in the set. Example: ◦ echo *[aeiou]* Matches: ◦ ape dog gnu platypus aardvark Does not match: ◦ fly

Brace Expansion: {} Generates strings at the command line by specifying a comma separated list inside curly braces “ {} ”.

Brace Expansion: {} A sequence consists of a starting and ending value separated by two periods “.. ”.

Globbing Hidden Files Hidden File Matching: ◦ Wildcards do not match the dot in hidden files Example: ◦ echo ?ark ◦ echo *ark Matches: ◦ mark park dark ◦ stark Does not match: ◦.ark

Globbing Hidden Files Example: ◦ echo.* Matches: ◦....ark Note: ◦ Use caution using “.* ” as a wildcard because it matches the current and parent directory!

Yanking the Rug From Under You Note: ◦ Someday, you will regret specifying “.* ” as a wildcard pattern for hidden files. You have been warned! Also Note: ◦ If you are not big enough to use a Red Ryder BB gun, perhaps you should not be using Linux! Trivia Question: ◦ How many times was Ralphie warned by his mother, “You’ll shoot your eye out!”? [Answer: Several times] Unexpected action may result from specifying “.* ” as a wildcard pattern

Shooting Your Eye Out in Linux Also Note: ◦ If you are not big enough to use a Red Ryder BB gun, perhaps you should not be using Linux! Trivia Question: ◦ How many times was Ralphie warned by his mother, “You’ll shoot your eye out!”? Example: rm -r.*/*