Sunteți pe pagina 1din 6

FREEENGINEER.

ORG
Lear n UNI X i n 10 mi nut es. Ver si on 1. 3
Preface
Thi s i s somet hi ng t hat I had gi ven out t o st udent s ( CAD user t r ai ni ng) i n year s past .
The pur pose was t o have on one page t he basi cs commands f or get t i ng st ar t ed usi ng
t he UNI X shel l ( so t hat t hey di dn' t cal l me aski ng what t o do t he f i r st t i me someone
gave t hema t ape) .
Thi s document i s copyr i ght ed but f r eel y r edi st r i but abl e under t he t er ms of t he GFDL .
Have an i dea f or t hi s page?
Send me pat ches, comment s, cor r ect i ons, about what ever you t hi nk i s wr ong or shoul d be
i ncl uded. I amal ways happy t o hear f r omyou. Pl ease i ncl ude t he wor d "UNI X" i n your subj ect .
Sections:
Directories:
Moving around the file system:
Listing directory contents:
Changing file permissions and attributes
Moving, renaming, and copying files:
Viewing and editing files:
Shells
Environment variables
Interactive History
Filename Completion
Bash is the way cool shell.
Redirection:
Pipes:
Command Substitution
Searching for strings in files: The grep command
Searching for files : The find command
Reading and writing tapes, backups, and archives: The tar command
File compression: compress, gzip, and bzip2
Looking for help: The man and apropos commands
Basics of the vi editor
FAQs
******************************************************************************************
Basi c UNI X Command Li ne ( shel l ) navi gat i on : Last r evi sed May 17 2001
******************************************************************************************
Directories:
Fi l e and di r ect or y pat hs i n UNI X use t he f or war d sl ash " / "
t o separ at e di r ect or y names i n a pat h.
exampl es:
/ "r oot " di r ect or y
/ usr di r ect or y usr ( sub- di r ect or y of / " r oot " di r ect or y)
/ usr / STRI M100 STRI M100 i s a subdi r ect or y of / usr
Moving around the file system:
pwd Show t he "pr esent wor ki ng di r ect or y" , or cur r ent di r ect or y.
cd Change cur r ent di r ect or y t o your HOME di r ect or y.
cd / usr / STRI M100 Change cur r ent di r ect or y t o / usr / STRI M100.
cd I NI T Change cur r ent di r ect or y t o I NI T whi ch i s a sub- di r ect or y of t he cur r ent
di r ect or y.
cd . . Change cur r ent di r ect or y t o t he par ent di r ect or y of t he cur r ent di r ect or y.
cd $STRMWORK Change cur r ent di r ect or y t o t he di r ect or y def i ned by t he envi r onment
var i abl e ' STRMWORK' .
cd ~bob Change t he cur r ent di r ect or y t o t he user bob' s home di r ect or y ( i f you have per mi ssi on) .
Listing directory contents:
Learn UNIX in 10 minutes http://freeengineer.org/learnUNIXin10minutes.html
1 of 6 05/09/2014 18:50
l s l i st a di r ect or y
l s - l l i st a di r ect or y i n l ong ( det ai l ed ) f or mat
f or exampl e:
$ l s - l
dr wxr - xr - x 4 cl i f f user 1024 J un 18 09: 40 WAI TRON_EARNI NGS
- r w- r - - r - - 1 cl i f f user 767392 J un 6 14: 28 scanl i b. t ar . gz
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
| | | | | | | | | | |
| | | | | owner gr oup si ze dat e t i me name
| | | | number of l i nks t o f i l e or di r ect or y cont ent s
| | | per mi ssi ons f or wor l d
| | per mi ssi ons f or member s of gr oup
| per mi ssi ons f or owner of f i l e: r = r ead, w = wr i t e, x = execut e - =no per mi ssi on
t ype of f i l e: - = nor mal f i l e, d=di r ect or y, l = symbol i c l i nk, and ot her s. . .
l s - a Li st t he cur r ent di r ect or y i ncl udi ng hi dden f i l es. Hi dden f i l es st ar t
wi t h ". "
l s - l d * Li st al l t he f i l e and di r ect or y names i n t he cur r ent di r ect or y usi ng
l ong f or mat . Wi t hout t he "d" opt i on, l s woul d l i st t he cont ent s
of any sub- di r ect or y of t he cur r ent . Wi t h t he "d" opt i on, l s
j ust l i st s t heml i ke r egul ar f i l es.
Changing file permissions and attributes
chmod 755 f i l e Changes t he per mi ssi ons of f i l e t o be r wx f or t he owner , and r x f or
t he gr oup and t he wor l d. ( 7 = r wx = 111 bi nar y. 5 = r - x = 101 bi nar y)
chgr p user f i l e Makes f i l e bel ong t o t he gr oup user .
chown cl i f f f i l e Makes cl i f f t he owner of f i l e.
chown - R cl i f f di r Makes cl i f f t he owner of di r and ever yt hi ng i n i t s di r ect or y t r ee.
You must be t he owner of t he f i l e/ di r ect or y or be r oot bef or e you can do any of t hese t hi ngs.
Moving, renaming, and copying files:
cp f i l e1 f i l e2 copy a f i l e
mv f i l e1 newname move or r ename a f i l e
mv f i l e1 ~/ AAA/ move f i l e1 i nt o sub- di r ect or y AAA i n your home di r ect or y.
r mf i l e1 [ f i l e2 . . . ] r emove or del et e a f i l e
r m- r di r 1 [ di r 2. . . ] r ecur si vl y r emove a di r ect or y and i t s cont ent s BE CAREFUL!
mkdi r di r 1 [ di r 2. . . ] cr eat e di r ect or i es
mkdi r - p di r pat h cr eat e t he di r ect or y di r pat h, i ncl udi ng al l i mpl i ed di r ect or i es i n t he pat h.
r mdi r di r 1 [ di r 2. . . ] r emove an empt y di r ect or y
Viewing and editing files:
cat f i l ename Dump a f i l e t o t he scr een i n asci i .
mor e f i l ename Pr ogr essi vel y dump a f i l e t o t he scr een: ENTER = one l i ne down
SPACEBAR = page down q=qui t
l ess f i l ename Li ke mor e, but you can use Page- Up t oo. Not on al l syst ems.
vi f i l ename Edi t a f i l e usi ng t he vi edi t or . Al l UNI X syst ems wi l l have vi i n some f or m.
emacs f i l ename Edi t a f i l e usi ng t he emacs edi t or . Not al l syst ems wi l l have emacs.
head f i l ename Show t he f i r st f ew l i nes of a f i l e.
head - n f i l ename Show t he f i r st n l i nes of a f i l e.
t ai l f i l ename Show t he l ast f ew l i nes of a f i l e.
t ai l - n f i l ename Show t he l ast n l i nes of a f i l e.
Shells
The behavi or of t he command l i ne i nt er f ace wi l l di f f er sl i ght l y dependi ng
on t he shell pr ogr amt hat i s bei ng used.
Dependi ng on t he shel l used, some ext r a behavi or s can be qui t e ni f t y.
You can f i nd out what shel l you ar e usi ng by t he command:
echo $SHELL
Of cour se you can cr eat e a f i l e wi t h a l i st of shel l commands and execut e i t l i ke
a pr ogr amt o per f or ma t ask. Thi s i s cal l ed a shel l scr i pt . Thi s i s i n f act t he
pr i mar y pur pose of most shel l s, not t he i nt er act i ve command l i ne behavi or .
Learn UNIX in 10 minutes http://freeengineer.org/learnUNIXin10minutes.html
2 of 6 05/09/2014 18:50
Environment variables
You can t each your shel l t o r emember t hi ngs f or l at er usi ng envi r onment var i abl es.
For exampl e under t he bash shel l :
expor t CASROOT=/ usr / l ocal / CAS3. 0 Def i nes t he var i abl e CASROOT wi t h t he val ue
/ usr / l ocal / CAS3. 0.
expor t LD_LI BRARY_PATH=$CASROOT/ Li nux/ l i b Def i nes t he var i abl e LD_LI BRARY_PATH wi t h
t he val ue of CASROOT wi t h / Li nux/ l i b appended,
or / usr / l ocal / CAS3. 0/ Li nux/ l i b
By pr ef i xi ng $ t o t he var i abl e name, you can eval uat e i t i n any command:
cd $CASROOT Changes your pr esent wor ki ng di r ect or y t o t he val ue of CASROOT
echo $CASROOT Pr i nt s out t he val ue of CASROOT, or / usr / l ocal / CAS3. 0
pr i nt env CASROOT Does t he same t hi ng i n bash and some ot her shel l s.
Interactive History
A f eat ur e of bash and t csh ( and somet i mes ot her s) you can use
t he up- ar r ow keys t o access your pr evi ous commands, edi t
t hem, and r e- execut e t hem.
Filename Completion
A f eat ur e of bash and t csh ( and possi bl y ot her s) you can use t he
TAB key t o compl et e a par t i al l y t yped f i l ename. For exampl e i f you
have a f i l e cal l ed const ant i ne- monks- and- wi l l y- wonka. t xt i n your
di r ect or y and want t o edi t i t you can t ype ' vi const ' , hi t t he TAB key,
and t he shel l wi l l f i l l i n t he r est of t he name f or you ( pr ovi ded t he
compl et i on i s uni que) .
Bash is the way cool shell.
Bash wi l l even compl et e t he name of commands and envi r onment var i abl es.
And i f t her e ar e mul t i pl e compl et i ons, i f you hi t TAB t wi ce bash wi l l show
you al l t he compl et i ons. Bash i s t he def aul t user shel l f or most Li nux syst ems.
Redirection:
gr ep st r i ng f i l ename > newf i l e Redi r ect s t he out put of t he above gr ep
command t o a f i l e ' newf i l e' .
gr ep st r i ng f i l ename >> exi st f i l e Appends t he out put of t he gr ep command
t o t he end of ' exi st f i l e' .
The r edi r ect i on di r ect i ves, > and >> can be used on t he out put of most commands
t o di r ect t hei r out put t o a f i l e.
Pipes:
The pi pe symbol "| " i s used t o di r ect t he out put of one command t o t he i nput
of anot her .
For exampl e:
l s - l | mor e Thi s commands t akes t he out put of t he l ong f or mat di r ect or y l i st command
"l s - l " and pi pes i t t hr ough t he mor e command ( al so known as a f i l t er ) .
I n t hi s case a ver y l ong l i st of f i l es can be vi ewed a page at a t i me.
du - sc * | sor t - n | t ai l
The command "du - sc" l i st s t he si zes of al l f i l es and di r ect or i es i n t he
cur r ent wor ki ng di r ect or y. That i s pi ped t hr ough " sor t - n" whi ch or der s t he
out put f r omsmal l est t o l ar gest si ze. Fi nal l y, t hat out put i s pi ped t hr ough "t ai l "
whi ch di spl ays onl y t he l ast f ew ( whi ch j ust happen t o be t he l ar gest ) r esul t s.
Command Substitution
Learn UNIX in 10 minutes http://freeengineer.org/learnUNIXin10minutes.html
3 of 6 05/09/2014 18:50
You can use t he out put of one command as an i nput t o anot her command i n anot her way
cal l ed command subst i t ut i on. Command subst i t ut i on i s i nvoked when by encl osi ng t he
subst i t ut ed command i n backwar ds si ngl e quot es. For exampl e:
cat `f i nd . - name aaa. t xt `
whi ch wi l l cat ( dump t o t he scr een ) al l t he f i l es named aaa. t xt t hat exi st i n t he cur r ent
di r ect or y or i n any subdi r ect or y t r ee.
Searching for strings in files: The grep command
gr ep st r i ng f i l ename pr i nt s al l t he l i nes i n a f i l e t hat cont ai n t he st r i ng
Searching for files : The find command
f i nd sear ch_pat h - name f i l ename
f i nd . - name aaa. t xt Fi nds al l t he f i l es named aaa. t xt i n t he cur r ent di r ect or y or
any subdi r ect or y t r ee.
f i nd / - name vi mr c Fi nd al l t he f i l es named ' vi mr c' anywher e on t he syst em.
f i nd / usr / l ocal / games - name " *xpi l ot *"
Fi nd al l f i l es whose names cont ai n t he st r i ng ' xpi l ot ' whi ch
exi st wi t hi n t he ' / usr / l ocal / games' di r ect or y t r ee.
Reading and writing tapes, backups, and archives: The tar command
The t ar command st ands f or "t ape ar chi ve". I t i s t he " st andar d" way t o r ead
and wr i t e ar chi ves ( col l ect i ons of f i l es and whol e di r ect or y t r ees) .
Of t en you wi l l f i nd ar chi ves of st uf f wi t h names l i ke st uf f . t ar , or st uf f . t ar . gz. Thi s
i s st uf f i n a t ar ar chi ve, and st uf f i n a t ar ar chi ve whi ch has been compr essed usi ng t he
gzi p compr essi on pr ogr amr espect i vl y.
Chances ar e t hat i f someone gi ves you a t ape wr i t t en on a UNI X syst em, i t wi l l be i n t ar f or mat ,
and you wi l l use t ar ( and your t ape dr i ve) t o r ead i t .
Li kewi se, i f you want t o wr i t e a t ape t o gi ve t o someone el se, you shoul d pr obabl y use
t ar as wel l .
Tar exampl es:
t ar xv Ext r act s ( x) f i l es f r omt he def aul t t ape dr i ve whi l e l i st i ng ( v = ver bose)
t he f i l e names t o t he scr een.
t ar t v Li st s t he f i l es f r omt he def aul t t ape devi ce wi t hout ext r act i ng t hem.
t ar cv f i l e1 f i l e2
Wr i t e f i l es ' f i l e1' and ' f i l e2' t o t he def aul t t ape devi ce.
t ar cvf ar chi ve. t ar f i l e1 [ f i l e2. . . ]
Cr eat e a t ar ar chi ve as a f i l e "ar chi ve. t ar " cont ai ni ng f i l e1,
f i l e2. . . et c.
t ar xvf ar chi ve. t ar ext r act f r omt he ar chi ve f i l e
t ar cvf z ar chi ve. t ar . gz dname
Cr eat e a gzi p compr essed t ar ar chi ve cont ai ni ng ever yt hi ng i n t he di r ect or y
' dname' . Thi s does not wor k wi t h al l ver si ons of t ar .
t ar xvf z ar chi ve. t ar . gz
Ext r act a gzi p compr essed t ar ar chi ve. Does not wor k wi t h al l ver si ons of t ar .
t ar cvf I ar chi ve. t ar . bz2 dname
Cr eat e a bz2 compr essed t ar ar chi ve. Does not wor k wi t h al l ver si ons of t ar
File compression: compress, gzip, and bzip2
The st andar d UNI X compr essi on commands ar e compr ess and uncompr ess. Compr essed f i l es have
a suf f i x . Z added t o t hei r name. For exampl e:
compr ess par t . i gs Cr eat es a compr essed f i l e par t . i gs. Z
uncompr ess par t . i gs Uncompr essei s par t . i gs f r omt he compr essed f i l e par t . i gs. Z.
Not e t he . Z i s not r equi r ed.
Anot her common compr essi on ut i l i t y i s gzi p ( and gunzi p) . These ar e t he GNU compr ess and
Learn UNIX in 10 minutes http://freeengineer.org/learnUNIXin10minutes.html
4 of 6 05/09/2014 18:50
uncompr ess ut i l i t i es. gzi p usual l y gi ves bet t er compr essi on t han st andar d compr ess,
but may not be i nst al l ed on al l syst ems. The suf f i x f or gzi pped f i l es i s . gz
gzi p par t . i gs Cr eat es a compr essed f i l e par t . i gs. gz
gunzi p par t . i gs Ext r act s t he or i gi nal f i l e f r ompar t . i gs. gz
The bzi p2 ut i l i t y has ( i n gener al ) even bet t er compr essi on t han gzi p, but at t he cost of l onger
t i mes t o compr ess and uncompr ess t he f i l es. I t i s not as common a ut i l i t y as gzi p, but i s
becomi ng mor e gener al l y avai l abl e.
bzi p2 par t . i gs Cr eat e a compr essed I ges f i l e par t . i gs. bz2
bunzi p2 par t . i gs. bz2 Uncompr ess t he compr essed i ges f i l e.
Looking for help: The man and apropos commands
Most of t he commands have a manual page whi ch gi ve somet i mes usef ul , of t en mor e or l ess
det ai l ed, somet i mes cr ypt i c and unf at homabl e di scr i pt i ons of t hei r usage. Some say t hey
ar e cal l ed man pages because t hey ar e onl y f or r eal men.
Exampl e:
man l s Shows t he manual page f or t he l s command
You can sear ch t hr ough t he man pages usi ng apropos
Exampl e:
apr opos bui l d Shows a l i st of al l t he man pages whose di scr i pt i ons cont ai n t he wor d "bui l d"
Do a man apropos f or det ai l ed hel p on apr opos.
Basics of the vi editor
Openi ng a f i l e
vi f i l ename
Cr eat i ng t ext
Edi t modes: These keys ent er edi t i ng modes and t ype i n t he t ext
of your document .
i I nser t bef or e cur r ent cur sor posi t i on
I I nser t at begi nni ng of cur r ent l i ne
a I nser t ( append) af t er cur r ent cur sor posi t i on
A Append t o end of l i ne
r Repl ace 1 char act er
R Repl ace mode
<ESC> Ter mi nat e i nser t i on or over wr i t e mode
Del et i on of t ext
x Del et e si ngl e char act er
dd Del et e cur r ent l i ne and put i n buf f er
ndd Del et e n l i nes ( n i s a number ) and put t hemi n buf f er
J At t aches t he next l i ne t o t he end of t he cur r ent l i ne ( del et es car r i age r et ur n) .
Oops
u Undo l ast command
cut and past e
yy Yank cur r ent l i ne i nt o buf f er
nyy Yank n l i nes i nt o buf f er
p Put t he cont ent s of t he buf f er af t er t he cur r ent l i ne
P Put t he cont ent s of t he buf f er bef or e t he cur r ent l i ne
cur sor posi t i oni ng
^d Page down
^u Page up
: n Posi t i on cur sor at l i ne n
: $ Posi t i on cur sor at end of f i l e
^g Di spl ay cur r ent l i ne number
h, j , k, l Lef t , Down, Up, and Ri ght r espect i vl y. Your ar r ow keys shoul d al so wor k i f
i f your keyboar d mappi ngs ar e anywher e near sane.
st r i ng subst i t ut i on
Learn UNIX in 10 minutes http://freeengineer.org/learnUNIXin10minutes.html
5 of 6 05/09/2014 18:50
: n1, n2: s/ st r i ng1/ st r i ng2/ [ g] Subst i t ut e st r i ng2 f or st r i ng1 on l i nes
n1 t o n2. I f g i s i ncl uded ( meani ng gl obal ) ,
al l i nst ances of st r i ng1 on each l i ne
ar e subst i t ut ed. I f g i s not i ncl uded,
onl y t he f i r st i nst ance per mat chi ng l i ne i s
subst i t ut ed.
^ mat ches st ar t of l i ne
. mat ches any si ngl e char act er
$ mat ches end of l i ne
These and ot her "speci al char act er s" ( l i ke t he f or war d sl ash) can be " escaped" wi t h \
i . e t o mat ch t he st r i ng "/ usr / STRI M100/ SOFT" say " \ / usr \ / STRI M100\ / SOFT"
Exampl es:
: 1, $: s/ dog/ cat / g Subst i t ut e ' cat ' f or ' dog' , ever y i nst ance
f or t he ent i r e f i l e - l i nes 1 t o $ ( end of f i l e)
: 23, 25: / f r og/ bi r d/ Subst i t ut e ' bi r d' f or ' f r og' on l i nes
23 t hr ough 25. Onl y t he f i r st i nst ance
on each l i ne i s subst i t ut ed.
Savi ng and qui t t i ng and ot her " ex" commands
These commands ar e al l pr ef i xed by pr essi ng col on ( : ) and t hen ent er ed i n t he l ower
l ef t cor ner of t he wi ndow. They ar e cal l ed "ex" commands because t hey ar e commands
of t he ex t ext edi t or - t he pr ecur sor l i ne edi t or t o t he scr een edi t or
vi . You cannot ent er an " ex" command when you ar e i n an edi t mode ( t ypi ng t ext ont o t he scr een)
Pr ess <ESC> t o exi t f r oman edi t i ng mode.
: w Wr i t e t he cur r ent f i l e.
: w new. f i l e Wr i t e t he f i l e t o t he name ' new. f i l e' .
: w! exi st i ng. f i l e Over wr i t e an exi st i ng f i l e wi t h t he f i l e cur r ent l y bei ng edi t ed.
: wq Wr i t e t he f i l e and qui t .
: q Qui t .
: q! Qui t wi t h no changes.
: e f i l ename Open t he f i l e ' f i l ename' f or edi t i ng.
: set number Tur ns on l i ne number i ng
: set nonumber Tur ns of f l i ne number i ng
FAQs
The USENET FAQs shoul d be t he f i r st pl ace you l ook f or an answer t o speci f i c quest i ons.
You can f i nd most of t hemat RTFM
The cont ent s of t hi s di r ect or y i ncl udes vi , bash, and comp. uni x. quest i ons FAQs.
Sear chi ng USENET ar chi ves ar e ver y usef ul t oo.
googl e. comhas a USENET ar chi ve ( f or mer l y Dej a. com' s) .
Advanced Gr oup Sear ch r ul es.
Thi s document was conver t ed f r ompl ai n t ext usi ng Vi mand
t hen hacked. Vi mi s t he best ver si on of t he one t r ue t ext edi t or : vi .
Copyr i ght ( c) 2000- 2006
Per mi ssi on i s gr ant ed t o copy, di st r i but e and/ or modi f y t hi s document
under t he t er ms of t he GNU Fr ee Document at i on Li cense, Ver si on 1. 1
or any l at er ver si on publ i shed by t he Fr ee Sof t war e Foundat i on;
wi t h I nvar i ant Sect i on: Pr ef ace, wi t h Fr ont - Cover Text s, and wi t h no
Back- Cover Text s. A copy of t he l i cense can be f ound on t he GNU web si t e
her e.
FREEENGINEER.ORG
Learn UNIX in 10 minutes http://freeengineer.org/learnUNIXin10minutes.html
6 of 6 05/09/2014 18:50

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