Sunteți pe pagina 1din 7

red hat ®

®
TRAINING

C H A PT E R 1

ACCESSING THE COMMAND


LINE

Overview

Goal To log i n t o a Lin u x system a n d r u n s i m p l e c o m m a nds u s i n g


the shell.

Objectives • Use B a s h s h e l l syntax to enter c o m m a nds at a L i n ux


console.

• L a u n c h a p p l i ca t i o n s i n a G N O M E desktop e n v i ro n me nt.

• Use Bash features to run c o m m a nds from a s h e l l p ro m pt


u s i n g fewer keystrokes.

Sections • Acces s i n g t h e C o m m a nd Line U s i n g t h e Loc a l Console


(a nd P ra c t i ce)

• Acces s i n g the C o m m a nd Line U s i n g the Desktop (a nd


Practice)

• Exec u t i n g C o m m a nds U s i n g t h e Bash S h e l l (and Pract ice)

Lab • Acces s i n g t h e C o m m a nd L i ne

R H 1 24- R H E L7-en-1 -20140606


-

C h a pte r 1 . Acces s i n g t h e C o m m a n d L i n e
-

Access i n g t h e Co m m a n d L i n e U s i n g t h e Loca l
-

Conso l e
-

Objectives
After com p l et i n g t h i s sect i o n , students s h o u l d be a b l e to l o g i nto a L i n u x system on a loca l text -

The bash shell


console a n d run s i m p l e co m m a n d s u s i n g the s h e l l .

A command line i s a text-based i nt e rface which c a n b e used to i n put i n st r u c t i o n s to a com puter


syste m. The L i n u x co m m a n d line i s p rovided by a p ro g ra m c a l l e d t h e shell. Over t h e long h i story
-
of U N IX - l i ke syste ms, m a ny s h e l l s have been deve l o pe d . The defa u lt s h e l l for u s e rs in Red H a t
E n t e r p r i s e L i n u x is t h e G N U Bourn e-Ag a i n S h e l l (bash). B a s h is a n i m p roved vers i o n of o n e o f
t h e m ost s u ccess f u l s h e l l s used o n U N I X- l i ke syste m s , t h e B o u r n e S h e l l ( s h ) .
-

W h e n a s h e l l i s used i nteractive l y, it d i s p l ays a stri n g w h e n it i s wa iting for a c o m m a n d from t h e


user. This is ca l l ed t h e shell prompt. W h e n a reg u l a r u s e r s t a r t s a s h e l l , t h e defa u lt p ro m pt e n d s
-
with a $ c h a racter.

r-
l [ student@desktopX -]$ -

T h e $ i s re p l a ced b y a # i f t h e sh e l l is r u n n i n g a s t h e s u pe r u s e r, root. T h i s m a kes it m o re obvious


t h a t it is a s u pe r u s e r s h e l l , which h e l ps to avo i d a c c i d e nts and m i sta kes i n t h e priv i l eg e d a ccou nt. -

[ root@desktopX -]#
� - �����
I
i
I
-

U s i n g bash to execute co m m a n d s c a n be powerf u l . T h e bash s h e l l prov ides a s c r i pt i n g l a n g u a g e


t h a t can s u p port a ut o m a t i o n o f tas ks. The s h e l l h a s a d d i t i o n a l ca pa b i l ities t h a t c a n s i m p l ify o r
-
m a ke poss i b l e o p e rat i o n s t h a t a re h a rd to acco m p l i s h eff i c i e n t l y w i t h g ra p h i c a l too l s .

L>=-SJ
-�>,
Note -

The bash s h e l l is s i m i l a r i n concept to t h e com m a n d l i n e interpreter fou n d i n recent


vers i o n s of M ic rosoft W i n d ows cmd . exe, a l t h o u g h bash h a s a m o re s o p h isticated
-
scri pti n g l a n g u a g e. It i s a l so s i m i l a r to W i n d ows Powe r S h e l l i n W i n d ows 7 and W i n dows
Server 2008 R2. Mac O S X a d m i n ist rators who u s e the M a c i ntos h ' s Te r m i n a l u t i l ity
may b e p l eased to note that bash is the d e fa u l t s h e l l in Mac OS X.
-

Virtual consoles -

Users access t h e bash s h e l l t h ro u g h a terminal. A t e r m i n a l provides a key boa rd for u s e r i n put


a n d a d i s p l a y for output. O n text-based i n sta l l a t i o n s , this c a n b e t h e L i n u x m a c h i n e ' s physical
-
console, t h e h a rdware key b o a rd a n d d i s p l ay. Te r m i n a l access c a n a l so be config u red t h ro u g h
seria l ports.

Another way to a ccess a s h e l l is from a virtual console. A L i n u x m a c h i n e ' s phys i c a l conso l e


s u p po rts m u l t i p l e v i rt u a l consoles w h i c h act l i ke s e p a rate term i n a l s. Each v i rt u a l co n s o l e
s u p po rts a n i n d e p e n d e n t l o g i n sess i o n .
-

2 RH124- R H E L7-en-1 -20140606 -

-
-

Shel l basics
-

I f t h e g ra p h i c a l en vi ro n m e n t i s ava i l a b l e, it w i l l r u n on t h e first v i rt u a l conso l e i n Red H a t


E n te r p r i s e L i n u x 7. Five a d d i t i o n a l t e x t l o g i n p ro m pts a re a va i l a b l e o n conso l es t w o t h ro u g h s i x
-
(or o n e t h ro u g h f i v e if t h e g ra p h ica l e n v i ro n m e nt i s t u r n e d off). With a g ra p h ica l e n v i ro n m e n t
r u n n i n g , access a text l o g i n pro m pt o n a v i r t u a l conso l e by h o l d i ng Ct r l +Alt a n d p ress i n g a
f u n c t i o n key (F2 t h ro u g h F6). Press C t r l +Al t + F l to ret u r n to t h e fi rst virtua l conso l e a n d t h e
-
g ra p h i c a l d e s ktop.

-
Important
I n t h e p re-config u re d v i rt u a l i m a g es d e l ivered by Red H a t , l o g i n p ro m pts have b e e n
- d i sa b l ed i n t h e v i rt u a l co n s o l es .

-
Note
I n Red H a t Enterprise L i n u x 5 a n d ea r l i e r, t h e f i rst six v i r t u a l c o n s o l e s a l ways p rovided
-
text login prom pts. When the g ra p h i ca l e n v i ro n m e nt was l a u n c h e d , it ran o n v i rt u a l
c o n s o l e seven (accessed t h ro u g h Ct r l +Al t + F 7 ) .

Shell basics
-
C o m m a n d s entered at t h e s h e l l p ro m pt have t h ree basic pa rts:
• Command to run
-
• Options to adjust the b e h a v i o r of t h e com m a n d

• Arguments, w h i c h a re typica l l y t a rg ets o f t h e co m m a n d


-

T h e command is t h e n a m e o f t h e p ro g ra m t o r u n . I t may b e fo l l owed by o n e or m o re options,


w h i c h a dj u st t h e behavior of t h e c o m m a n d or w h a t it w i l l d o. O pt i o n s n o rm a l l y sta rt w i t h o n e o r
- t w o d a s hes ( - a o r - - all, for exa m p l e) to d i st i n g u i s h t h e m from a rg u ments. Com m a n d s may a l so
b e fo l l owed by one or m o re arguments, w h i c h often i n d icate a t a rg et t h a t t h e co m m a n d s h o u l d
o p e rate o n .
-

Fo r exa m p l e, t h e com m a n d l i n e u s e r mod - L mo r gan h a s a com m a n d ( use rmod), a n option


( - L), and a n a rg u m e n t (mo r g an ) . T h e effect of t h i s com m a n d i s to l o c k t h e passwo rd o n user
-
m o rg a n ' s a ccount.

To u s e a com m a n d effect i ve l y, a user needs to k n ow w h a t options and a rg u ments it ta kes a n d


-
i n w h a t o rd e r i t expects t h e m (t h e syntax o f t h e com m a n d). M ost c o m m a n d s have a - - help
option. This causes t h e com m a n d to print a description of what it does, a " u sage state m e n t " t h a t
d e s c r i b e s t h e co m m a n d ' s sy n t a x , a n d a l i st o f t h e opt i o n s it a ccepts a n d w h at t hey d o .
-

U s a g e statements m a y seem c o m p l icated a n d d i ff i c u l t to rea d . T h e y b e c o m e m u c h s i m p l e r t o


u n d e rsta n d once a user beco m e s fa m i l i a r w i t h a few b a s i c convent i o n s :
-
• S q u a re b ra c kets, [ ] , s u rro u n d o pt i o n a l ite m s .

• Anyt h i n g fol lowed by ... represents a n a r b it ra ry- l e n g t h l i st o f items o f t h a t type.


-

• M u lt i p l e items sepa rated by p i pes, I. m e a n s o n l y one of t h e m ca n b e specified.

- R H 1 24- R H E L 7-en-1-20140606 3

-
-

C h a pte r 1 . Access i n g t h e C o m m a n d L i n e
-

• Text i n a n g l e b ra c kets, < > , represe n t s va r i a b l e data. Fo r exa m p l e, <filename> m e a n s " i n s e rt


t h e f i l e n a m e you w i s h to u s e h e re". S o m et i m es these va ria b l es a re s i m p l y written i n c a p ita l -
l etters (e.g., F I L E N A M E).

C o n s i d e r t h e f i rst usage state m e n t for t h e da t e co m m a n d :


-

r·�
[student@desktopX -]$ date
date [OPTION] . . . [+FORMAT]
! - - h elp

I -

T h i s i n d icates t h a t d at e c a n take a n o pt i o n a l l i st of o p t i o n s ( [OPTION] . . . ), fo l l owed by a n


o pt i o n a l fo r m a t stri n g , prefixed w i t h a p l u s c h a racter, +, t h a t defines how t h e c u rrent date s h o u l d -

b e d i s p l ayed ( [+FORMAT]). S i n ce b o t h o f these a re option a l , d a t e wi l l w o r k even if it i s n o t g i v e n


o p t i o n s o r a rg u me nts (it w i l l p r i n t t h e c u rrent date a n d t i m e u s i n g i t s defa u lt form at).
-

Note
T h e man page for a com m a n d h a s a SY N O P S I S sect i o n t h a t p rovi d e s i nfor m a t i o n a b o u t -

t h e co m ma n d ' s s y n t a x . T h e man - pages(7) m a n pa g e d e s c r i b e s how to interpret a l l


t h e s q u a re b rac kets, vertica l ba rs, a n d s o forth t h at u s e rs see i n SY N O PS I S o r a u s a g e
message.

W h e n a u s e r is f i n ished u s i n g t h e s h e l l a n d wa nts to q u it. t h e re a re a c o u p l e of ways to e n d t h e -

s e s s i o n . T h e e x i t com m a n d ter mi nates t h e c u rrent s h e l l s e s s i o n . A n o t h e r w a y t o f i n i s h a sess i o n


is by typ i n g C t r l+D.
-

R References
in t r o(l), bash(l ) , console(4), p t s (4), a n d man - pages(7) m a n pages -

Note: Some details of the console(4) man page, involving init(B) and inittab(S), are
outdated. -

-
4 R H 1 24- R H E L7-en-1-20140606

-
-

Pract ice: Loca l Conso l e Access Te r m s


-

P ra ct i ce: Loca l Conso l e Access Te r m s


-

-
Quiz

M atch t h e fo l l ow i n g item s to t h e i r cou nterparts i n t h e t a b l e.


-

- I A rg u m e nt jI 18 Command Phys i ca l c o n s o l e

-
j P ro m pt
!B I I
Shell Te r m i n a l Vi r t u a l c o n s o l e

Description Term
-
I

T h e i n t e r p rete r t h at exe c u tes co m m a n d s typed


-
a s st r i n g s.

T h e v i s u a l c u e t h a t i n d i cates a n i nt e ract ive s h e l l


i s wa i t i n g fo r t h e u s e r to type a co m m a n d .
-

-
T h e n a m e o f a p ro g ra m to r u n .

- T h e pa rt o f t h e c o m m a n d l i n e t h a t a dj u sts t h e
b e h a v i o r o f a co m m a n d .
-

T h e p a rt o f t h e co m m a n d l i n e t h a t s pe c i f i e s t h e
- ta rget t h a t t h e co m m a n d s h o u l d o p e rate o n .

-
T h e h a rd wa re d i s p l a y a n d keyboa rd u s e d t o
i nt e ract w i t h a syst e m .
-

O n e of m u lt i p l e l o g i ca l co n s o l es t h a t c a n e a c h
- s u p po rt a n i n d e pe n d e n t l og i n sess i o n .

- R H 1 24- R H E L 7-en-1-20140606 5

-
-

C h a pte r 1 . Access i n g t h e C o m m a n d L i n e
-

Description Term -

A n inte rfa ce t h a t p rovid es a dis p l a y f o r o u t p u t -

a n d a key boa rd fo r in p u t to a s h e l l sessio n.


-

6 RH124- R H E L 7 - e n -1-20140606 -

-
-

Solution
-

Solution
-

M atch t h e fo l l owi n g items to t h e i r cou nterparts i n t h e ta b l e.

Description Term

T h e i nt e r p rete r t h a t executes com m a n ds ty p e d Shell


a s st r i n g s .
-

- T h e v i s u a l c u e t h a t i n d i cates a n i nt e ra ct ive s h e l l Prom pt


is wa i t i n g for t h e u s e r to t y p e a co m m a nd .

T h e n a m e of a p rog ra m to r u n . Co m m a n d
-

T h e p a rt of t h e c o m m a n d l i n e that a dj u sts t h e Option


- b e h a v i o r of a co m m a n d .

-
T h e pa rt of t h e c o m m a n d l i n e that s p e c i f i es t h e A rg u m e nt
ta rg et t h a t t h e c o m m a n d s h o u l d o p e rate o n .
-

T h e h a rd wa re d i s p l ay a n d keybo a rd u s ed to Phys i ca l c o n s o l e
-
i nt e ra ct w i t h a syst e m .

·-
O n e of m u l t i p l e l o g i ca l c o n s o l es t h a t ca n e a c h V i rt u a l co n so l e
s u p p o rt a n i n d e p e n d e n t l og i n sess i o n .
-

A n i nte rfa ce t h a t p rov i d es a d i s p l a y for o u t p u t Te r m i n a l


-
a n d a key boa rd for i n p u t to a s h e l l sess i o n .

- R H 1 24- R H E L 7-e n-1-20140606 7

S-ar putea să vă placă și