+ All Categories
Home > Documents > A Practical Guide to Fedora and Red Hat Enterprise Linux Unit 4: More Command Line Interface (CLI)...

A Practical Guide to Fedora and Red Hat Enterprise Linux Unit 4: More Command Line Interface (CLI)...

Date post: 17-Dec-2015
Category:
Upload: leslie-fisher
View: 234 times
Download: 2 times
Share this document with a friend
25
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
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!

Abort Command Execution

Abort Command◦Ctrl+C: Aborts current execution

Launching Background CommandsBackground 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 JobsKilling a background job:◦kill %x

Standard Input, Output & ErrorThree Streams in Linux OS

Standard Input(STDIN)

Standard Output(STDOUT)

Standard Error(STDERR)

command

Output RedirectionSyntax:

◦command [args] > filename

Example:◦cat > file.txttext from keyboardsecond line of textCtrl+D

Caution: Redirecting output can destroy a file!

Input Redirection

Syntax:◦command [args] < filename

Example:◦sort < 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

PipesDescription:

◦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

FiltersDescription:

◦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

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 “..”.


Recommended