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!
Suspended Jobs & Background
Interactive Background Execution◦Ctrl+Z: Suspends current execution
◦bg: Move suspended job to background
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!
/dev/null: The Bit Bucket
Data Sink:◦echo "gone!" > /dev/null
Unix Universe Black Hole:◦mv trash.txt /dev/null
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 “{}”.