Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ îðèãèíàëüíîãî äîêóìåíòà : http://tex.bog.msu.ru/numtask/unnu12.pdf
Äàòà èçìåíåíèÿ: Sat Aug 4 17:22:00 2012
Äàòà èíäåêñèðîâàíèÿ: Thu Feb 27 20:06:57 2014
Êîäèðîâêà:


.. ..

UNIX

2012



1 2 2 , " UNIX" " " ( ) 3 4 4.1 . 4.2 . . . . . . . . 4.3 . . . . . . . . . . 4.4 . . . . . . . . . 4.5 . . . . . . . . . . 4.6 ( ) 4.7 . . . . . . . . . . . . 4.8 . 4.9 . . . . 4.10 . . . . . . . . . . . 4.11 . . . . . . . . . . . . . . 5.1 mcedit . . . . 5.2 joe . . . . . 5.3 vi ( vim). 5.4 . . gcc 7.1 . . . . . . . . 7.2 . . 7.3 , 7.4

4 5 6 6 7 8 8 9 9 9 10 12 14 15 16 16 17 18 19 20 23 24 25 25 27 28

..... ..... ..... ..... ..... ..... ..... ..... ..... .....

. . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

5

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

6 7

. . .

......... ......... . . . .........

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

8

1


1



, UNIX, UNIX. , , , , UNIX. UNIX UNIX . : . ( , "" "", ..), - , , , ( ). , 95% UNIX. UNIX BSD, Solaris ( Sun), Linux1 Slackware, Debian, SUSE, Red Hat, Fedora, Ubuntu, .. , , free, open source. , , . , , , . , , , , . , : . , ( ) , . , , , , ( , ). Windows " cmd": , , , , , , , .. , 97.5% . ( ) , , . UNIX' , (6 ) . , ( X Windows). , , (.. X-). X- , 2 , , . . . . 1­6 , 7­8 . : 1 , . , , . . , login password.
, , Linux , UNIX. , "" . , UNIX . 2 , .
1

2


, login password, . , , . , . , ("", "shell"), . " bash", " zsh", " csh", " tcsh", " sh". , . , environment variables (, ). - , , , .. ("") , , , . , , . " bash" " csh", . , exit . , logout, logout , , . , . , , , , . ( " " ). , , ( ) : !gcc . . , , , , . , - , , , . (, -, , , ). / . UNIX network transparent, , , shell . -, , " rsh" (remote shell), " telnet", " ftp". , : , ( ) . , , , . login , password , . " ssh", " scp" ( "s" "secure"). ssh : ssh oryx7 -l studfve35 ( " l" , login). "studfve35" , -, . "bog.msu.ru" ,

3


"oryx7", , : "oryx7.bog.msu.ru". IP-: "213.131.20.147". login hostname : ssh studfve35@oryx7.bog.msu.ru password , , . ( ) , , , , command line, , . , ("") " exit". , , , , UNIX. , UNIX , Windows- . , , , putty ( ). putty pscp, . , , , , WinSCP.

2

, " UNIX" " " ( )

, , UNIX, Windows, . -, UNIX . , 2 , 4. 4- 4 , CPU 4100%, 480%, .. , UNIX (, , ..) Windows . , Windows "" UNIX. , , UNIX 3 . UNIX ( , , , ) DOS. , DOS UNIX. , , , (, ).4 , X Windows. ( , "C" DOS, VMS, UNIX, MacOS, ..). "" (, , ). , X Windows Windows . Apple Microsoft "".
3 , . (, ), 2 5- , single-sided, 180 Kb. ( ). DOS 1.0. 4 , "" ( , , ), .

4


, . . Microsoft Windows, , , DOS. ( ). , ( ) . , UNIX DOS. ( , "" UNIX) , . , , , ( cmd) . UNIX (X Windows) , .5 . , , network transparent, . , X Windows network transparent, , , X- .6 , , . : , , . , . , " " Windows . , X- . , , , , .

3



: 7 ("") " /", , . , , , .. ( - , - ). : /dirname1/dirname2/filename ( "dirname1", "dirname1" "dirname2", "dirname2" "filename"). , , .. "". , , .. : /home/username "username" (login name).
, X Windows , Window Manager . 6 : UNIX' , X Windows. X- , , (, , , - ), . 7 "".
5

5


" /etc" ; " /usr" " /usr/local" , " /usr/lib" , " /usr/bin" , " /usr/include" " *.h "; " /var" , " /tmp" , .. : · " . " () ; · " .. " ( ) ; · " ~ " () "" /home/username.

4



" mc" (MidnightCommander) , . . , mc . Help mc, . ( Help , ). mc , , , (" ?"). mc , , ( ). , : , . , . . , , , . ( , , ). , , mc . , , , , .

4.1



" man" "". , " ls", man ls . , , " man" . ,

6


, , . . ( ) " info". (, man - , info ). info ls ( " man"), . , , , "<" (""). , , . ( ), . , . " info" .

4.2



mc . , . ( ) . , . , " .. " ( ), . " cd". . : cd dirname " dirname" . , cd .. , cd ~ /home/username. : cd /home/username/mydir3 : cd ../../mydir3/mydir4 , 2 , " mydir3" (, ), " mydir3", , " mydir4" ( , ). , , (metacharacters). " *" ( ) , " ?" . cd /home/username/mydir3

7


cd /ho*/use?nam?/m*3 , , " m*3", . .

4.3



mc ( mc "8 Delete"). , , . "", mc , , .8 , mc , ( ( ) ), . rmdir dirname "dirname" , "dirname" . , , . , .. rmdir mydir? , mydir?. rmdir * . : rmdir /home/username/mydir3

4.4



mc ( "7 Mkdir"). , . : UNIX (, Linux), , , .. . , , - - . mkdir dirname "dirname" .
, X Windows File Manager (- ""). , , .
8

8


4.5



mc ( ) -, , . ( , ). ( "5 Copy"). , . , . - , , ( , ). , mc , . : cp filename1 filename2 "filename1" "filename2". , , cp ./filename1 ./filename2 , ; cp /home/username/mydir1/fil3 /home/username/mydir4/fil7 , . , , . cp /home/username/mydir1/fil3 /home/username/mydir4 cp /home/username/mydir1/fil3 /home/username/mydir4/fil3 cp fil3 ../mydir4 cp * /home/username/mydir4 . , " cp * . . .", , , ( mc).

4.6

( )

( "6 RenMov"), " mv" " cp". , - , .

4.7



( "8 Delete"), " rm" " cp". , ( ) , . : rm *.c

9


4.8



mc . ( ) , . , - ( , , .. ). , , ( , , , , ). " ls" , . , . , . ls -l . , ( , ), " " ( , ), , () , , , .

: drwxr--r- -rw-r--r- -rwxr-xr-x .. : , (d) (-). 3 3 . ( 3 ) , 9 , . 3 : (r) ( , ), (w) ( ), (x, "eXecute") ( , ). -rwxrwxrwx , , , -rwx-----, , , -rw-r--r-, , .
, , . , "Users".
9

10


, , . " chmod" .10 , "myprog", chmod : chmod -x myprog ( ). , . "", , , " ls", " cp", " rm", .. : "myscript" : chmod +x myscript , "". . , , , , , . , "", .

ls -a , , ( : ".cshrc", ".profile", ".bashrc", ..). ls -al , . , , . , ls *.c , "." ( ""). ls myfil?? , "myfil??". ls /etc " /etc". ls /usr/lib/*.a , " /usr/lib/*.a" ( . , ). ls /usr/lib/*.so
, , . , , . , " chmod" .
10

11


( . , ).

:
. . " ls" , : ls /etc/*.hihi >myfil2 "myfil2" , . , " ls". " ls" "myfil1", : ls /etc/*.hihi >>myfil1 , " wc" ( : "wc" Word Counter), : ls /etc/*.hihi | wc " wc" , . , , ps- : ls *.ps | wc " grep". , . ls -l *hahaha* ls -l | grep hahaha - . " more". , , " ls". , : ls | more , , . , ( ) , .

4.9



" mc" - . (. "10 Quit"), . .

12


-, mc , . , " *.ps " PostScript . ps- . , . ( ) () ps-. -, (, , ""), . ( , , ..). , , , ( ). reset . , .

. · cat myfile . , , cat more: cat myfile | more more myfile -, " cat" " grep", , . " -n", , : cat myfile | grep -n hihihi , " cat" " grep" , , . , grep -n printf *.c , "printf ", - . . · " less" ( : "more", "less"): less myfile . , " less" 13


mc. ( mc ). " less" , " info" ( ), , . , . . · tail myfile "myfile" ( 10 ). (, 13), tail -n 13 myfile , , 63-, tail -n +63 myfile " tail".

" tail" , , . ( ) . , , -, , - . -, , , , . , "myprog.log" tail myprog.log . tail -f myprog.log . , , . , " tail", ( ) .

4.10

.

UNIX Windows zip/unzip. . , zip- , unzip, mc. , . tar gzip. ( bz2).

14


tar tar-.11 tar cvf myfile.tar * ( ) tar- "myfile.tar". , tar xvf myfile.tar tar , . , gzip. : gzip myfile "myfile.gz". , . , gzip tar-: gzip myfile.tar "myfile.tar.gz". "myfile.tgz". gunzip:12 gunzip myfile.gz "myfile.gz" "myfile". mc, : "myfile.tar.gz" ( "myfile.tgz") . , . , (. ).

4.11



mc ( "9 PullDn") . : "Command" "Find File". , . "Start at" , . , , . " . ", .. . , , "" (" /").
tar ( ). , 300 Mb , . , , , . , : raw data LHC . , , , , . , tar- ( ), , tar-, . 12 , . gzip. " -d": " gzip -d myfile.gz" . "gunzip" "link", .. , . , , (, ) " ", .. . gzip , : gzip, , gunzip, .
11

15


"filename" , "content" . , , , , . . : find /usr -name "hosts" -print (/usr) , ( , "", .. "/usr/lib" "/usr/include" , "/etc" ); (-name "hosts"), , .. " -name "host?" "; (-print) , .

5



, . , , . , , - .

5.1

mcedit

-, mc " mcedit". mc ( , "4 Edit"), : mcedit myfile.c myfile.c. , -. - : , , , .. . Help ( , "1 Help"), , , self-explanatory. (, Help , ). , , . . · , , ( "3 Mark"), . . · , , , ( "5 Copy") , ( "6 Move") . · , , . · , ( "7 Search"), , . . 16


· - , ( "4 Replac"), 2 , , . 13 , 1 1 , . , "Replace All", . , " ?". : (repl), (skip), (all), (cancel). · , ( "2 Save"). · , ( "10 Quit"), 2 .

5.2

jo e

c , Borland Turbo Pascal, Tubo Basic, Turbo C, Turbo Prolog .. Windows. , , , ( ), ( ). MultiEdit, MultiEdit. joe, : joe myfile.c · Help, 2 : , ( ). (, Help , .) · , , 2 : , . 2 : , . · , , 2 : , . · , , 2 : , . · , , . · - , 2 : , . , . , c (ignore) (replace). · , (replace), , . :
, , . mc .
13

17


(yes), (no), (rest). , , (backup). , (ignore), . , . · , 2 : , . · , 2 : , . · , . , , , , .

5.3

vi ( vim).

, . , , : , ( ). . "" (, h,j,k,l ), "" , "" , .. · "" . · : ( h,j,k,l ) . - , "". ( "Insert"). "" . · Help, , ( : ), :help ( ) . Help :q ( ) . , , Help. , Help, , , (Help ). · , , "" , . , . , , , (, ),

.

18


· , , 2 . · , /myword ( ) . , , . · - , :%s/oldword/newword/gc ( ) . : (y), (n), (a), (q). · , . · , :w . · , :wq . · , :q! . . · - , . vi , , , :qa! . , vi .

5.4



" nano". , , .

19


" emacs". nano . , , "" "MAXIM'".14 , , , . ( ) , , , . . Help'a, , , .., . , , , . . , . ( XWindows) .

6

gcc

" cc" UNIX, , . ( ) GNU gcc ("" ). , GNU, , open-source . -, ( , , , - ), . , UNIX' . () . : (source), prog-4.56.tar.gz, - (. ), , "configure": ./configure , . , "make": make , . , "README" "INSTALL". , . . , ,
, UNIX ( 40 Mb, 500 Kb, 286- 20 MHz), Windows ( ) , DOS. , DOS , : Turbo Basic, Turbo Pascal, Turbo C, Turbo Prolog (Borland); Quick Basic, Quick C (Microsoft); Watcom C, . Visual C Quick C, Microsoft: . , , Watcom 1998 , , Visual C 2010 . Watcom 1998 , , . , , gcc, - , Watcom.
14

20


make install . " ", .. /usr /usr/local, , "README" "INSTALL". , , , . , , , , ( ) gcc 2.3 gcc 2.5 , gcc 2.4 . Linux , ( CD [700Mb] DVD [ 25 Gb]), , Package Manager, - ( , )15 . , , gcc. UNIX. ( ), , , cross- (.. , , Intel' , Sun' . , , ), .. gcc, , info gcc ( , , ). , , , . , . - ( prog1.c prog1.o). ( ) . , , , . , . , , ( " -static"). , ( ), ( ), - . , -, , . ,
, , rpm- "" ("dependencies").
15

21


, , .., . , .16 . , "#include". , . , c- . " gcc" ( ) (""). , (, " -" ). "" gcc : gcc myprog.c . "myprog.c" , , ( ) . , , , , (" "). , , , , . . , "myprog.c" ( , , "sin" "sqrt"), , "a.out". : a.out ( " ." (environment variable) PATH " "), ./a.out ( ). . "myprog.c", . "myprog.c" (, "sin" "sqrt"), , . , , . " -l" ( ). " -lm", :17 gcc myprog.c -lm - " a.out". , " a.out" , , . " -o" ( <> ): gcc -o ispoln_file_myprog myprog.c -lm - , : gcc -o myprog myprog.c -lm
cuda- nvcc. , 10 . 17 " libm.a", .., , .
16

22


, , . · -, "" . " -O" ( <> ). , " -O3" ( 3-, 2- ). , "unwind loops" "inline functions". . . , . , ( - , ). . , , "static", , . , , , double 1000 , . . , , , - , - , . ( , ), - . · -, floating-point . ANSI , , double "" (.. , ANSI). . , 18 , . " -f" floating-point , " -ffast-math", ANSI, . · -, . , , , "generic i386" .19 " -march=i686", .20 (. gcc), , , . , , , , : gcc -o myprog -O3 -ffast-math -march=i686 myprog.c -lm - , " -lm" .

7



, , . " cat" , " /usr/bin", ,
, , - 10 . , . 20 , "i686" . , .
19 18

23


. ( ) " ls", " mc", " vi", " gcc", " a.out", ..

7.1



, ( , , "" environment variable "PATH"), ( , , ), . , "myprog", : /home/studfve37/myprog , " /home/studfve37" , : ./myprog , myprog , , echo $PATH , , - :
/usr/bin:/usr/local/bin:.:/home/username/bin:/usr/bin/X11:/usr/X11R6/bin:/bin

, " . " ( ), . , - (, , ), (, , !), .. ("") . () , . , , ( ) . , , , , , . , , , , , . . <&> (, "7"): ./myprog & , . , , . , . , , - . . , , , - ( ), , . , , . , .21 , .
, , . , .
21

24


, . - , , (background) , , , foreground-. , . , , , . , . . " nohup": nohup ./myprog & , , " nohup.out", .22 , . " exit", , , .

7.2



, . Windows, UNIX . , , , , . . . . , , . , , , : , . , . , , 5 , , . , , .. " nice": nice -19 ./myprog & , , , : nohup nice -19 ./myprog & "19" . -, , , 0 . . . 19 ( , 10 , 5 , ..), , : " nice", " nice -19".

7.3

,

, , , (, , ) , - . , , , " ps".
, . " nohup" , " nohup.out".
22

25


ps , , . . , , , . (" ls -l"), (" tar xvf"). , , . , BSD ( UNIX), ( ) . , . , , : ·x ·a ·l , - . (all) .

, ps ax ps alx , . , , " a" ("all") " e" ("every"). , " man ps" " info ps". -, " ps" - . , , " PID" ("", ), .23 , (, PID 16384), renice 15 16384 ( , " renice" , " nice"). , . , . , , . kill 16384 , () . , , . : kill -9 16384 , . , ( foreground-), . , top - . , , , , , . -, , . (%MEM), CPU (%CPU), ( ,
" UID" , ; (run, sleep, zombie, ..); ; , ; NI ; ; , .
23

26


100% CPU); ; NI ( " nice" " renice"); , ; , .24

7.4



, , . , , . , , . - , . "C", . . (, "myscript") , , : nohup nice -19 myprog 1.1 infile outfile1 gzip outfile1 nohup nice -19 myprog 1.2 infile outfile2 gzip outfile2 nohup nice -19 myprog 1.3 infile outfile3 gzip outfile3 : chmod +x myscript : nohup myscript & , , , , . , (, ) : nohup nice -19 myprog 1.8 infile outfile1 & nohup nice -19 myprog 2.7 infile outfile2 & nohup nice -19 myprog 3.6 infile outfile3 & nohup nice -19 myprog 4.5 infile outfile4 nohup nice -19 myprog 5.4 infile outfile5 & nohup nice -19 myprog 6.3 infile outfile6 & nohup nice -19 myprog 7.2 infile outfile7 & nohup nice -19 myprog 8.1 infile outfile8 , . , ( 1-4) . . , , . : , ( 5-8), 7 . , " chmod". , . , "myscript" . 25 :
: VIRT, RES, SHR, .. , RES=CODE+DATA, VIRT=RES+SWAP, SHR , "share" ( ) , .. , , %MEM. 25 , .
24

27


sh myscript , , bash myscript

8



, UNIX. , -, , -, , , ( ). , , , . ( . " , , ?!"). : -, . -, , .

28