+ All Categories
Home > Documents > The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide for Linux System Administration CH03 powerpoint

Date post: 18-Nov-2014
Category:
Upload: wannabeef9
View: 910 times
Download: 2 times
Share this document with a friend
Description:
Chapter 3 powerpoint for The Complete Guide For Linus System Administration
40
Chapter 3: Using the Shell The Complete Guide to Linux System Administration
Transcript
Page 1: The Complete Guide for Linux System Administration CH03 powerpoint

Chapter 3:Using the Shell

The Complete Guide to Linux System Administration

Page 2: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 2

Objectives

• Use common features of the shell to work at the command line

• Manipulate variables in the shell to control your working environment

• Redirect data at the command line

• Edit text using the vi editor

• Print basic files from the command line

Page 3: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 3

Exploring the Bash Shell

• Shell – Command program – Accepts input from keyboard – Uses input to run commands or otherwise control

computer– Started when terminal window opened

Page 4: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 4

Exploring the Bash Shell (continued)

• Flexible– Interact with any file that you have permission to

access– Start any program on system– Use special features of shell to work more

efficiently

Page 5: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 5

The Shell Prompt

• Set of words or characters indicating that shell is ready to accept commands

• Default prompt example:– [Nwells@inverness nwells]$

• When logged in as root, prompt character changes to hash mark, #

Page 6: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 6

The Functions of a Shell

• Shell purpose– Make it easy for users to run programs and work

with files in Linux– Run programs– Pass parameters to program being started

• Behavior– If command succeeds, no response– If command fails, error message printed

Page 7: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 7

The Functions of a Shell (continued)

• Shell has many built-in features – Help you work with files and commands

• Script – Program– List of commands stored in text file

Page 8: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 8

Different Types of Shells

• Shell has no special relationship to Linux kernel– Can use any shell

• Bourne shell– Original shell for UNIX– Called sh– Old program with limited functionality

• Bash– Default shell for all Linux systems

Page 9: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 9

Different Types of Shells (continued)

• Shells fall into two groups:– Bourne shell programming style– C shell programming style

• Shell started for each user is determined by settings in user account– Each user on system can select preferred shell

• Immediately run different shell– Enter name of shell program

Page 10: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 10

Entering Commands

• Features designed to simplify process of entering commands:– Tab completion

• Enter part of file or directory name

• Press tab key

• Shell fills in remainder of name

– Command history• Records each command

Page 11: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 11

Entering Commands (continued)

• Command history– Quickly call up and repeat any command from list – Press the up arrow key at command prompt– Press enter to execute command

• History command – Displays entire history list

• Bang– !

Page 12: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 12

Entering Commands (continued)

• Locate previously executed command– Use history number– Use beginning of command– Search history list

Page 13: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 13

The Shell Start-up Process

• Scripts executed when you log in to Linux– Initialize various parts of environment

• Script /etc/profile executed on first log in

• Contains configuration information that applies to every user on system

• Profile script– Found in user’s home directory– Specific to single user

Page 14: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 14

The Shell Start-up Process (continued)

• Some systems – Additional scripts are executed when user logs in

• When user starts shell– Additional scripts executed

• bashrc script – Executed each time user starts bash shell– User can add configuration information

Page 15: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 15

The Shell Start-up Process (continued)

Page 16: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 16

Using Aliases

• Alias – String substituted for another string at shell prompt

• Alias command – Define how shell will substitute one string for

another – Format:

• alias <string entered by user>=<string substituted by the shell>

– Enter without arguments to see list of current aliases

Page 17: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 17

Command-line Expansion

• Shell can make many different substitutions, including:– Aliases– Variables– Command substitution– Special characters

• Place commands in single quotes – Executed first by shell

Page 18: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 18

Command-line Expansion (continued)

• Special characters– Place in single quotes– Precede with $

• Example: $’\n’

– Other special characters:• ;

• *

• ?

Page 19: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 19

Command-line Expansion (continued)

• Avoid command-line expansion– Escape individual characters

• Using \

– Single quote– Double quote

Page 20: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 20

Shell Variables

• Shell variable– Name that can have value assigned to it– Can be number or string of text– Typically created using all uppercase letters

• Environment variable – Typically defined during initialization of operating

system or user’s shell– Can be accessed by any program

Page 21: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 21

Shell Variables (continued)

• env command – Start program with environment variable setting

that is not part of current environment– Only used for started program

• Set command– Displays list of all environment variables

• Echo command– View value of single environment variable

Page 22: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 22

Shell Variables (continued)

• Export command – Makes newly created environment variable

available to other programs

• PATH environment variable – Contains list of directories that shell searches

each time command is executed

• PS1 environment variable– Defines shell prompt for bash

Page 23: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 23

Data Redirection

• Standard input channel– STDIN– Keyboard

• Standard output channel– STDOUT– Monitor

• Standard error– STDERR

Page 24: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 24

Data Redirection (continued)

• Data can be redirected from standard channels

• Pipe– Connects output channel of one command to the

input channel of another command– Example: $ ls /etc | sort

Page 25: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 25

Data Redirection (continued)

Page 26: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 26

Data Redirection (continued)

• Mail command – Basic e-mail client – Use from command line to create e-mail message– Format: mail -s "subject line" e-mail_address

Page 27: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 27

Editing Text with vi• Text editor

– Single most important utility for system administrator

• Many different text editors are available for Linux

• Text-mode editors:– vi– emacs– pico– Joe

Page 28: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 28

Editing Text with vi (continued)

• Very powerful program

• Available on virtually every Linux system

• Not easy to use

• Must learn to use at least basic features in order to work as Linux system administrator– Memorize keystroke sequences– Work without any onscreen prompts

Page 29: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 29

Editing Text with vi (continued)

• To start:– vi command– Can be followed by name of file to edit

• Modal editor– Keystrokes are interpreted differently depending

on mode you are working in

Page 30: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 30

Editing Text with vi (continued)

• Modes:– Command mode– Insert mode– Replace mode

• Begin in command mode– Return to command mode by pressing Esc key

Page 31: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 31

Editing Text with vi (continued)

Page 32: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 32

Editing Text with vi (continued)

Page 33: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 33

Editing Text with vi (continued)

Page 34: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 34

Editing Text with vi (continued)

Page 35: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 35

Printing from the Command Line

• Quickly configure printer attached to parallel port

• Print files directly from command line

Page 36: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 36

Setting Up a Printer

• Print queue – Printer definition– Associate physical printer with named printer

definition

• Set up printer via GNOME desktop interface – Choose system settings– Print– Follow steps in dialog

Page 37: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 37

Printing From a Command Line

• lpr command– Print from command line– Uses series of filters based on type of file to print

• lpoptions command– Save commonly used list of options

Page 38: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 38

Summary

• Shell – Command interpreter used to start programs– Many shells are available

• Tab completion – Helps to quickly enter long file and directory

names

• Command history – Quickly reenter previously entered command

Page 39: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 39

Summary (continued)

• Scripts executed when:– User logs in– New shell opened

• Aliases– Shell replaces text on command-line entry with

different text

• Shell expands text on command line in several ways

Page 40: The Complete Guide for Linux System Administration CH03 powerpoint

The Complete Guide to Linux System Administration 40

Summary (continued)

• Environment variables store values that programs can access

• Flow of data between programs can be changed using redirection operators on command line

• Linux supports numerous text editors

• After setting up printer, print files from command line using lpr command


Recommended