Linux. Администрирование и системное программирование.pdf

Embed Size (px)

Citation preview

  • Linux . ,

    Linux . , - . . Linux, .

    Mac OS X, UNIX/Linux .

    , (GUI), Macintosh, , (command-line interface, CLI) . OS X, - . , Linux, Mac OS X . .

    (CLI), , Linux . ,

    . - (, emacs) , - , - ASCII- . .

    Linux , , Linux . Linux, , Linux . , Linux-, .

    Linux , . Ubuntu,

    Fedora, Red Hat, Mint, OpenSUSE, Mandriva, CentOS Debian . , Linux, - . , - , , .

    Linux

    Mac OS X

    Linux

  • :

    Mac OS X ( ) . -Mac OS X ( ) . - OS X ( ) . -OS X ( ) . - X ( ) . -X ( ) . - ( ) . - V , Linux, , Mac OS X .

    Perl ( 11) .

    rsync ( 14) .

    V , -, Mac OS X .

    A Practical Guide to Red Hat Linux: Fedora and Red Hat Enterprise Linux A Practical Guide to Ubuntu Linux,

    . , ( 3 , V), , Bourne Again Shell (bash) Perl . , , , , vim emacs, TC Shell (tcsh), AWK sed, rsync, V, 97 Linux Mac OS X .

    . ,

    . :

    , , Linux Mac OS X;

    , Linux Mac OS X ;

    , Linux Mac OS X ;

    Macintosh, , UNIX/Linux , ;

    Macintosh, , UNIX/Linux, Mac OS X;

    UNIX, UNIX Linux Mac OS X;

    , Linux Mac OS X , bash Perl;

    , , Linux Mac OS X;

    , Linux Mac OS X;

    , Linux Mac OS X .

    12

  • Linux . - Linux Mac OS X

    . , , . , , Linux/OS X, - .

    Macintosh . - Macintosh . UNIX/Linux , Mac OS X, Macintosh , Linux UNIX- .

    , LINUX, LINUX, MAC OS X UNIX Linux, Mac OS X. (GUI) , (CLI) . Linux, Mac OS X. , Linux Linux, Mac OS X. , , .

    . , , , Linux . Linux : , . V, .

    Linux . -, - : , .

    Linux . :

    , , - .

    , , - , , .

    , , , , - .

    13

  • , - .

    - www.sobell.com, -, , , - .

    , .

    URL (-), , - .

    , .

    , . - www.sobell.com .

    , GNUs, gcc, GNU, make, gzip, .

    , - , .

    , Apple Mac OS X, diskutil, ditto, dscl, GetFileInfo, launchctl, otool, plutil SetFile .

    , , , Linux . .

    1, Linux Mac OS X . Linux OS X .

    Linux, OS X Mach, -Linux, OS X Mach, -, OS X Mach, -OS X Mach, - X Mach, -X Mach, - Mach, -Mach, -, -, GNU Linux , Linux, .

    I . Linux Mac OS X

    , I UNIX/Linux , , . , . 42, , . 52, , Linux, .

    14

  • I Linux -I Linux - Linux -Linux - - .

    2, ! . , -

    . , , , Linux .

    3, .

    30 , . , Linux, , . :

    y grep, ; y unix2dos, Linux

    Windows; y tar, , ; y bzip2 gzip, , ,

    ; y diff, .

    4, . Linux, ,

    , , , , . - , . , .

    5, . , , -

    . , , bash, tcsh . :

    y ;

    y , , ;

    y ; y -

    , ;

    y , -, Linux ;

    y - , .

    I. Linux Mac OS X 15

  • II . Linux-, -Linux-, --, - . vim, vi, GNU- emacs Linux . , , , . Linux -Linux - - , , Linux- .

    6, vim . vim, ,

    , , , , . - .

    7, emacs . , -

    emacs, , META, ALT ESCAPE . , , , - , . , , . , , emacs .

    , , emacs C, C- . 7 emacs .

    III . III bash TC Shell (tcsh) .

    8, Bourne Again Shell . ,

    5, . Bourne Again Shell bash, , . 8 :

    y , ;

    y ;

    16

  • y , ;

    y ; y , ,

    , ; y , ,

    ; y ; y , ,

    .

    9, TC Shell . tcsh, bash tcsh

    , , . :

    y tcsh , tcsh; y , ,

    ; y

    ; y tcsh; y .

    IV . IV , Linux Mac OS, .

    10, Bourne Again Shell . ,

    8, - 8, -8, - bash, . :

    y , ifthenelse case;

    y , ;

    y () ;

    y , , exec, trap getopts .

    Linux , .

    10 , -, .

    IV. 17

  • . - . - . - . - . - . - . - . - . - . - . - . - - quiz, , , , . ( V , -V , - , - .)

    11, Perl . Perl, -Perl, -, -

    . :

    y Perl, perldoc;

    y Perl ;

    y ;

    y ;

    y CPAN- .

    Perl Linux- . 11 , . - Perl .

    12, AWK . , ,

    AWK, , . , - , , , .

    13, sed . sed, ,

    . sed , - .

    14, rsync . rsync, ,

    , . , - .

    V . Linux . 1214, V , - , C . , UNIX/Linux, . .

    18

  • , 1214, V, , , Linux- (man-), . , - (, ls cp), , (sort, paste test), Linux (ps, kill fsck) (ssh, scp ftp) . - , Mac OS X, , Linux . , , . -, , , . , - , AWK ( 20 12), ftp ( V) sort ( V) .

    (www.sobell.com) , , , Linux OS X, , , , , - .

    , . - -, ([email protected]), - . (www.sobell.com) , . -, Linux .

    (Mark G. Sobell)-,

    19

  • 1 . Linux Mac OS X

    , - , - , - , , , , , . : . , - , , , . - , , (), ( ), , , . , - - . , GNU, .

    Linux - (Linus Torvalds), ,

    . Linux 0 .01 1991 .

    . - , - , BSD UNIX System V UNIX (SVR4) . Linux , Linus UNIX .

    Linux, , - ( ) . , . , . - , , , , ( , -) . GNU (www.gnu.org/philosophy/free-sw.html) :

    , . ,

    , ( ) .

    OS X Mach, - (Carnegie Mellon University, CMU),

    . CMU 1994 , . Much

    Linux

    Mach

  • Mac OS X : Mac OS X Mach FreeBSD, BSD GNU, BSD, Apple .

    LINUX, OS X UNIXLinux OS X UNIX. Linux OS X. , Linux, OS X Linux, , OS X Linux, . Linux Linux , Linux, OS X.

    UNIX GNULinux , UNIX Linux, GNU Linux . www.levenez.com/unix - , UNIX .

    UNIX Linux UNIX , -UNIX , - , - , . , , - , .

    UNIX . 1975 UNIX , Bell Labs . , , , . UNIX , . , . , UNIX -UNIX - - .

    UNIX, - (Computer Sys-tems Research Group, CSRG)

    . , - UNIX, Berkeley Software Distribution (BSD) UNIX system ( Berkeley UNIX) . UNIX System V (SVR4), -, AT&T UNIX

    BSD (Berkeley) UNIX

    UNIX GNULinux 21

  • System Laboratories . Mac OS X BSD .

    1983 (Richard Stallman, www.stallman.org) 1 GNU, -GNU, -, - , , , GNU Manifesto2, :

    GNU, Gnu UNIX (Gnus Not UNIX), UNIX- , , , .

    , , , :

    . , GNU. , , GNU - . , . , free , . , free, -free, -, -. , - , , . , - , .

    :

    GNU. , ,

    , , . , , . . . -, , : , .

    1 www.gnu.org/gnu/initial-announcement.html2 www.gnu.org/gnu/manifesto.html

    22 1. Linux Mac OS X

  • , , - , -. , MIT ( ) - GNU.

    , 1991 GNU . GNU, . :

    90- ( GNU Hurd1, Mach2). , , 3.

    , , , UNIX- .

    , , GNU. 4 , , GNU 1984 . UNIX- GNU GNU. GNU GNU. Linux [GNU] 5.

    GNU FreeBSD (www.freebsd.org) NetBSD (www.netbsd.org), Linux, -Linux, -, - Hurd Darwin (developer.apple.com/opensource), - .

    , UNIX , . , UNIX -UNIX - - , , . , -

    1 www.gnu.org/software/hurd/hurd.html2 www.gnu.org/software/hurd/gnumach.html3 www.gnu.org/software/hurd/hurd-and-linux.html4 www.gnu.org/philosophy/free-sw.html5 www.gnu.org/gnu/linux-and-gnu.html

    UNIX GNULinux 23

  • UNIX, . UNIX , , .

    , UNIX- : (Doug Comer) XINU, (Andrew Tanenbaum) MINIX . Linux, MINIX . , ( MINIX), , . Linux .

    Linux . GNU, . - Free Software Foundation (www.fsf.org), (GNU), , , Linux ( , Ubuntu, Red Hat, openSUSE), , .

    Linux GNU GNU General Public License (GPL, www.gnu.org/licenses/licenses.html) . GPL , , - . , . - , , GPL, , GPL- . - copyright ( , ), copyleft . ( GPL, , . GPL, .)

    ! Linux ! (Have Fun!) . . UNIX, Linux , . , (less) (more): GNU , UNIX more, less . PostScript ghostscript ( ), vi elvis . -

    MINIX

    GPL

    24 1. Linux Mac OS X

  • , , Intel, - Intel Inside ( ), Linux- Linux Inside . Linus Inside .

    Linux? Linux UNIX- . UNIX- . UNIX, Linux UNIX : Linux BSD System V, Linux , Linux UNIX , . , - , GNU Linux .

    1985 - POSIX (Portable Operating System Interface for Computer Environments) , - UNIX System V Interface Definition (SVID) . , - , . 1988 , POSIX IEEE-, API (application program interface), - . UNIX- , - . , , - , - , UNIX, Linux .

    Linux , , , - , , , - , - . Linux -, Linux, GNU, KDE , Linux . , , Linux, IBM (www.ibm.com/linux) . Linux POSIX, - . , Linux -

    Linux? 25

  • - .

    Linux

    , . Linux . , , , , - .

    - (-

    ), , - . . Netscape, , Linux Java , - . , , , Mozilla-Thunderbird-Firefox .

    Linux Intel ( Apple): - Power PC, Apple (ppclinux), Compaq ( Digital Equipment Corpora-tion) Alpha, MIPS-, Motorola 68K, 64- IBM S/390 . Linux : 2 .0, (SMP) . O(1), SMP- .

    Linux , , . - , Linux , - DOS, Windows Macintosh . , Wine (www.winehq.com) - Windows API, X Window System UNIX/Linux .

    (VM, ) -

    . - VM, (, ) . , , (VMM) . , , . , -

    26 1. Linux Mac OS X

  • , Windows, Ubuntu 7 .10, Ubuntu 9 .04 Fedora 10 . . ( ) .

    -, :

    , : - .

    , , . , - , .

    , - .

    , () , , . . , , , .

    . - .

    - , () .

    , .

    (), , - .

    - , , .

    Linux? 27

  • Xen, - , (VMM), . Xen .

    Xen . - Xen -Xen - - - www.cl.cam.ac.uk/research/srg/netos/xen, - wiki.xensource.com/xenwiki .

    VMware, Inc . (www.vmware.com) VMware Server, , , Linux . VMware Server , , Windows Linux . VMware - VMware player, VMware Server .

    , (Kernel-based Virtual Machine, KVM; kvm.qumranet.com libvirt.org), , Linux . Intel VT (VMX) AMD SVM .

    Qemu (bellard.org/qemu), (Fabrice Bellard), VMM , - , - - . , , , - .

    VirtualBox (www.virtualbox.org) - , Sun Microsystems .

    Linux , , UNIX Linux -UNIX Linux - Linux -Linux - - . -, , . - 70- - , - . 64- , , - , - .

    Xen

    VMware

    KVM

    Qemu

    VirtualBox

    28 1. Linux Mac OS X

  • -, -, - , , -

    (, DEC/Compaq VMS) . , .

    - (UNIX, OS X, Windows) (Linux) . Linux -

    - , . , ( , Microsoft Windows) . , . . - , - .

    UNIX , -UNIX , - , - - , , . Linux , : .

    Linux , . 95 % Linux C, , - . ( - C C .)

    Linux , () - . , Linux , - , , , . . , Linux - .

    -

    Linux? 29

  • .

    Linux -Linux - - , . Linux , -; . Linux -Linux - - , .

    : , , -, , .

    - . , .

    C (Ken Thompson) UNIX 1969 PDP-7 . -: -PDP-7 . -: --7 . -: -, , , , . UNIX ( ) .

    UNIX , - B, - , BCPL . (Dennis Ritchie) C, - B, 1973 UNIX C . C . - .

    C . , . C - . , C . -C . - . - .

    C ( -, , ) .

    C . . ,

    30 1. Linux Mac OS X

  • , . C , - . , - .

    80- (American National Standards Institute, ANSI) C, ANSI C C89 ( ) . C99, - GNU ( gcc) . Kernighan & Ritchie ( K&R) C, ( ), C .

    Linux

    . 1 .1 . Linux

    , Bell Labs, (Bjarne Strou-strup), - C++, C . - -C . - - . - - , C++ , C . Objective-C, - . -, GNU, C, C++ Objective-C .

    Linux Linux . , . UNIX, ( . . 1 .1) , .

    Linux 31

  • Linux , Linux , - , -, , , , DVD -, . , - . - . , write() , . write() - . , . - ( ) .

    Linux - Linux , . , , , . , - , . , , , - . - . , , , , - .

    Linux Linux , . , - , , - . ,

    32 1. Linux Mac OS X

  • , , . X Window System - . .

    Linux , , , , - . , . Linux - , , . . , . ., . , . , - ( . 1 .2) .

    ,

    , Linux Filesystem Standard (FSSTND), Linux Filesystem Hierarchy Standard (FHS) . Linux . , Linux, . Overview of Linux 13

    Links A link allows a given file to be accessed by means of two or more names. The alter-native names can be located in the same directory as the original file or in anotherdirectory. Links can make the same file appear in several users directories, enablingthose users to share the file easily. Windows uses the term shortcut in place of linkto describe this capability. Macintosh users will be more familiar with the termalias. Under Linux, an alias is different from a link; it is a command macro featureprovided by the shell (page 324).

    Security Like most multiuser operating systems, Linux allows users to protect their datafrom access by other users. It also allows users to share selected data and programswith certain other users by means of a simple but effective protection scheme. Thislevel of security is provided by file access permissions, which limit the users who canread from, write to, or execute a file. More recently, Linux has implemented AccessControl Lists (ACLs), which give users and administrators finer-grained controlover file access permissions.

    The Shell: Command Interpreter and Programming Language

    In a textual environment, the shellthe command interpreteracts as an interfacebetween you and the operating system. When you enter a command on the screen,the shell interprets the command and calls the program you want. A number ofshells are available for Linux. The four most popular shells are

    The Bourne Again Shell (bash), an enhanced version of the original Bourne Shell (the original UNIX shell).

    The Debian Almquist Shell (dash), a smaller version of bash, with fewer features. Most startup shell scripts call dash in place of bash to speed the boot process.

    Figure 1-2 The Linux filesystem structure

    /

    etctmphome

    hlssammax

    notesbin

    report log

    000.book.fm Page 13 Wednesday, September 30, 2009 10:13 AM

    . 1 .2 . Linux

    Linux 33

  • - . -

    . , - . Windows (shortcut) . Macintosh (alias) . Linux ; , - .

    , Linux -

    . , . , , , . Linux - Access Control Lists (ACL), - .

    : . , . Linux . :

    Bourne Again Shell (bash), - Bourne Shell ( UNIX) .

    Debian Almquist Shell (dash), bash, . - dash bash .

    TC Shell (tcsh), C Shell, , - BSD UNIX .

    Z Shell (zsh), , Korn Shell .

    , . - Linux: , .

    , - , ,

    . , ( Linux ; Windows

    34 1. Linux Mac OS X

  • ) . , , , , , - .

    , , - , , . - . , , :

    , . . , - mak* make-3.80.tar.gz . , .

    Readline, -Readline, -, - , , : ESCAPE, , , , .

    (, ) Linux- .

    Linux . - .

    , , , - , . ,

    . , cat . -

    cat , .

    - . -, , . .

    -

    -

    Linux 35

  • , Bourne Again Shell, , -Bourne Again Shell, , - Again Shell, , -Again Shell, , - Shell, , -Shell, , -, , - , - . , .

    , . . , , - . , , , , . ( BSD UNIX, C Shell .)

    Linux , -, . , , , . sort, , ( ) , , , , , , , . . sort , Linux- . , , , , , , , , . man ( manual ) info Linux .

    Linux . -

    . , , . , - . - .

    . , sort head (, ); lpr, .

    36 1. Linux Mac OS X

  • , .

    Linux . . , . ( ), - , , , , . , , .

    Linux Linux BSD, System V Solaris ( Sun Microsystems), . , UNIX, Linux, . , Linux .

    GUI X Window System ( X X11) - -

    (Massachusetts Institute of Technology, MIT) Linux . , X, , , , - , . X - , , , .

    Mac OS X , - . -

    Macintosh Aqua, - Mac OS X . Aqua -

    X11

    Aqua

    Linux 37

  • Quartz . Mac OS X X11, Quartz .

    X : (desktop manager) - (window manager) . -

    , - , . Linux - GNOME (www.gnome.org), - KDE (www.kde.org) - . Mac OS X Aqua, X11, X11 .

    ,

    , - , . - . Microsoft Windows , X - : ( , ), , .

    X Linux . - Linux Metacity ( - GNOME) kwin ( KDE) . , Sawfish WindowMaker .

    Mac OS X Quartz, Apple Aqua . X11 quartz-wm, Apple Aqua, X11 Mac , Mac OS X .

    Linux , . , , , , -, . , , - , (local area network, LAN) (wide area network, WAN), .

    38 1. Linux Mac OS X

  • , , . , - , .

    Linux . Linux . C C++, , Linux, Ada, Fortran, Java, Lisp, Pascal, Perl Python . bison (), , ( , , ) . flex (, ) . make, , GNU (GNU Configure and Build System), - . (Source code management systems), CVS, - . , ups gdb, . GNU C- (gcc) - gprof, . C C-, , .

    Apple Xcode, OS X, -, .

    Linux UNIX - ( Windows), ( ) . UNIX Linux . Linux UNIX-, - , , - GNU . Linux . , , Linux . , Linux, , -

    39

  • Linux , , , , , , .

    1 . (free software)? -

    .

    2 . Linux? ?

    3 . ? ?

    4 . (Free Software Foundation) GNU? Linux? Linux - ? ?

    5 . Linux? Linux?

    6 . ()?

    7 . ? ? ?

    8 . - ?

    9 . Linux ?

    10 . ?

    11 . .

    12 . , Linux? ?

    13 . GNU General Public License .

    40 1. Linux Mac OS X

  • I

    Linux OS X

    2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

    3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

    4 . . . . . . . . . . . . . . . . . . . . 97

    5 . . . . . . . . . . . . . . . . . . . . . . . . . . . 137

  • 2 . !

    , , , , , Linux . , -Linux . , - . , - (GUI) . , (command-line interface, CLI) . GUI, -command-line interface, CLI) . GUI, --line interface, CLI) . GUI, -line interface, CLI) . GUI, - interface, CLI) . GUI, -interface, CLI) . GUI, -, CLI) . GUI, -CLI) . GUI, -) . GUI, -GUI, -, -, , , xterm, Konsole, GNOME Terminal, Terminal ( Mac OS X), ( . . 61) .

    , , , . , - . , (root privileges), , , , . Linux . , .

    , (root-) . , : , , , , .

    , , - . .

    Mac OS X Mac OS X, Mac OS X Server . -

    .

    Mac OS X 10 .5 (Leopard) . -

    , OS X , - . - (www.sobell.com) .

    , - :

    $ cat practice , .

    Mac OS X

    Mac OS X

  • , , . ($)

    , Linux, - , -, .

    Arial . - emacs ls ls

    ( ls), ls a, . , , , .

    . , memo5, letter.1283 reports .

    , . Linux ext2, ext3 ext4, , memo5, MEMO5 Memo5 .

    HFS+, Mac OS X , -HFS+, Mac OS X , -+, Mac OS X , -Mac OS X , - OS X , -OS X , - X , -X , - , - , OS X memo5, MEMO5 Memo5 . - . 100 .

    . -

    , . - , passwd: Sorry, passwords do not match1 .

    :

    , 2, ESCAPE TAB .

    , , , .

    , CONTROL, CONTROL+D . (, D , , SHIFT; CONTROL+D CONTROL d .)

    1 ( ) . . .

    2 . . RET, NEWLINE, ENTER, RETURN . . , , .

    , 43

  • , Linux . ($), (#), - (%) .

    , . . , .

    , - . : $ vim memo.1204

    - vim, vim memo.1204 . ( vim ESCAPE ZZ; vim 6 .) , .

    , FOLDOC, (Denis Howe), -

    Free On-Line Dictionary of Computing (foldoc.org), . , , , .

    , , . , , - . , , , . .

    -, URL-, http://, : ftp:// https:// . ,

    , , http://, FTP- HTTP- . , URL- , .

    , Linux- .

    . .

    . , .

    URL- (-)

    , - -

    44 2. !

  • , , , - , (issue) ( /etc/issue) . Linux, , , . :

    Ubuntu 9.10 tiny tty1

    . - . Max, tiny:

    tiny login: maxPassword:Last login: Wed Mar 10 19:50:38 from dog[max@tiny max]$

    login:, , . login: , CONTROL+Q ( Xon) .

    , ? , , : . , , , . , , , , . , , .

    Apple, PC, Linux- , , ssh, telnet - , , IP- , . , , - . , , . , Linux . Mac OS X .

    45

  • TELNET telnet , , . ssh , , , , telnet. ssh , Linux. ssh .

    , ssh - Linux:$ ssh max@tinymax@tiny's password:Permission denied, please try again. , , max@tiny's password:Last login: Wed Mar 10 21:21:49 2005 from dog[max@tiny max]$

    Max , -Max , - , - , . , , - - -, , , at (@) . Max ssh tiny .

    ( -), , . , , motd, /etc/motd .

    ($) . -, , , , , . $ ( ) - (max), at (@), (tiny) , Max . 8, bash, 9, - tcsh .

    TERM TERM . TERM , . , .

    (GUI) UNIX, Linux ( -Linux ( - ( -

    46 2. !

  • command-line interface, CLI) . , , ssh telnet .

    () - . , . . .

    - , . -

    - , - , , . , GUI - - . , - . - , GUI , . , , - , - .

    , - , GUI . , , ( . chmod V) .

    - , , , , -

    , , . -, , . , , dpkg-reconfigure, .

    , , , , - . . : 5, Bourne Again Shell, , TC Shell, 8, 9 TC Shell, 10 ( ) Bourne Again Shell .

    -

    -

    47

  • ? Bourne Again Shell (bash) TC Shell (tcsh) . , bash, , , tcsh - , Z Shell (zsh) . ps . ps .$ ps PID TTY TIME CMD 2402 pts/5 00:00:00 bash 7174 pts/5 00:00:00 ps

    , : bash ps . tcsh, bash ps tcsh . , ps .

    , , - . , , - .

    : -, . : , , .

    , , . . , - . , - . , - . , - . , - . , - . , - . , - , - .

    BACKSPACE . , DELETE, CONTROL+H . , stty1 ( . . 49):$ stty ek

    stty V .

    1 stty set teletypewriter, , UNIX . stty .

    48 2. !

  • , CONTROL+W . , . CONTROL+W, ( ) ( ) .

    CONTROL+Z , ( CONTROL+Z) , . , Stopped (), , . fg, , . 155.

    , . , , . CONTROL+U . , CONTROL+X . , stty, .48 .

    . , , , , .

    - (CONTROL+C , , DELETE DEL) . - - , . 841 V .

    , ( CONTROL+Z), jobs, , kill, . , ( [1]) . kill TERM, , (%1) . TERM -, kill .$ bigjobCONTROL+Z[1]+ Stopped bigjob

    49

  • $ jobs[1]+ Stopped bigjob$ kill -TERM %1$ [1]+ Killed bigjob

    kill . , . , . , , , (KILL) . - , . . 154 kill . 738 .

    Linux . , .

    ( ), , , .

    Bourne Again Shell , . , , - . , . , ; - . , .

    , bash tcsh, . - . , , . , .

    - . . .

    - bash 8 tcsh 9 .

    su/sudo: (root-) UNIX Linux root . root ( root-),

    50 2. !

  • , . , root-, , . root- , - , . root-, . -, -, , .

    ROOT- oot, . oot, . , . oot, . . oot , Linux.

    root- . -root- . -- . - root . root-, . , , su (substitute user ), , root-, root-, . root -root - - su root- , root . , -root . , - . , - su .$ ls -l /lost+foundls: cannot open directory /lost+found: Permission denied /lost+found: $ su -c 'ls -l /lost+found'Password: root total 0$

    , , - root-, /lost+found: - ls . su c (command ) root- . , - . (ls , - ), root- . su root- . root- (#) . exit .$ suPassword: root# ls -l /lost+found

    su/sudo: (oot) 51

  • total 0# exitexit$

    (, Ubuntu) root ( root) -root ( root) - ( root) -root) -) - sudo (www.sudo.ws), root- . sudo root- ( root) . , root- /lost+found .$ sudo ls -l /lost+found[sudo] password for sam: total 0$

    i sudo root- . root- -root- . root- -- . root- -root- -- - (#) . exit .$ sudo -i[sudo] password for sam: # ls -l /lost+foundtotal 0# exitlogout$

    Linux - . Linux . man (manual ) info, - man info . , Linux, . , Linux .

    help GNU- help, . , GNU, h help .$ cat --helpUsage: cat [OPTION] [FILE]Concatenate FILE(s), or standard input, to standard output. -A, --show-all equivalent to -vET -b, --number-nonblank number nonblank output lines

    52 2. !

  • -e equivalent to -vE -E, --show-ends display $ at end of each line

    , help, , - less, :$ ls --help | less

    man: man ( . V) man- . , , , - . man- - , Linux . , man-, apropos . , , - .

    . 2 .1 . man,

    - MAN http://tldp.og/manpages/man.html man. , HTML, man.

    , man, . . 2 .1 man, ; man man .

    53

  • man , less, .

    less , , , Manual page man(1) line 1, , , . h (help ), less . q (quit ), - . . 66 .

    FHS (Filesystem Hierarchy Standard - ), Linux

    man- , - :

    1 . User Commands ( ) .

    2 . System Calls ( ) .

    3 . Subroutines () .

    4 . Devices () .

    5 . File Formats ( ) .

    6 . Games () .

    7 . Miscellaneous () .

    8 . System Administration ( ) .

    9 . Kernel () .

    10 . New () .

    UNIX . , man - , . 1, 6 7; .

    . , man- passwd 1 :$ man passwd

    man- passwd 5, :$ man 5 passwd

    man man- 5 . , man- passwd(5) . man- , a (adjacent ), , q . , , passwd, man a passwd .

    less

    54 2. !

  • . , . , , . . . 138.

    apropos: , , apropos - . ( ) man- , . man k (keyword ) , apropos .

    , apropos, whatis, Linux- , -Linux- , -- , - cron ( cron V , crontab) .

    , apropos who . , - , , man- . (who) , :$ apropos whoat.allow (5) - determine who can submit jobs via at or batchat.deny (5) - determine who can submit jobs via at or batchfrom (1) - print names of those who have sent mailw (1) - Show who is logged on and what they are doing.w.procps (1) - Show who is logged on and what they are doing.who (1) - show who is logged onwhoami (1) - print effective userid

    . 2 .2 . , info coeutils

    55

  • whatis whatis apropos, , :$ whatis whowho (1) - show who is logged on

    info: info, , , - , GNU - Linux . info - Linux, , GNU . info www.gnu.org/software/texinfo/manual/info . . 2 .2 , info info coreutils (coreutils , Linux) .

    MAN INFO info GNU , man. man , info, man info. man , , GNU. info , GNU, man.

    , , . info- :

    ? info;

    , ;

    m , ;

    m , ;

    q CONTROL+C info.

    info, , . C-h , CONTROL+H . , M-x META ALT x . , META+X, ESCAPE, x . : - . 231 .

    , INFO PINFO pinfo info, , emacs. , info, . , pinfo . pinfo .

    56 2. !

  • . 2 .3 . info coeutils, /sleep

    info coreutils /sleep, sleep . / , Search for string []: , . , . sleep , sleep .

    sleep ( . 2 .3) - / ( /sleep) . - , . , .

    info-, . , , , . menu . , sleep, m sleep, . m ( menu), ( , /) Menu item: . sleep , .

    . 2 .4 sleep . , . n, p . ( sleep .) man info . -

    57

  • PostScript-, , man t . , man t cat | lpr cat . -, - www.tldp.org, - .

    . 2 .4 . info, sleep

    HOWTO: , HOWTO , -, Linux, -Linux, - - . Mini-HOWTO . Linux, , -Linux, , -, , - HOWTO, .

    HOWTO mini-HOWTO - Linux (Linux Documentation Project, LDP) . - www.tldp.org, HOWTOs, HOWTO mini-HOWTO . HOWTO , LDP .

    , Linux .

    58 2. !

  • . 2 .5 . Google

    ,

    /usr/share/doc /usr/src/linux/Documentation ( - )

    , , man info . , , . , .

    , grep info . , , zcat ( . V), less .$ less /usr/share/doc/grep/README$ zcat /usr/share/doc/info/README.gz | less

    , Linux . . , , , Google ( www.google.com Linux www.google.com/linux) . , . , , ( . 2 .5) .

    /usr/share/doc

    59

  • GNU www.gnu.org/manual . GNU (www.gnu.org) - GNU- . GNU- - .

    . 2 .6 . Linux Documentation Poject

    Linux (Linux Documentation Project, www.tldp.org, . 2 .6), - Linux, , HOWTO, , man-

    , Linux . , -, , , . . - , , Linux ( Links Search www.tldp.org/links) . , , , , - , .

    , - .

    GNU

    Linux

    60 2. !

  • Linux , . - , 63 ( ) . , . , CONTROL ALT, , , . , CONTROL+ALT+F5 . , CONTROL+ALT+F1, .

    , . , , . , , ( ) .

    , , , , , . - , , . - - - , .

    :

    . , , , .

    . , - . , , .

    . , . .

    - CONTROL+D .

    61

  • EOF (end of file ) . -EOF (end of file ) . - (end of file ) . -end of file ) . - of file ) . -of file ) . - file ) . -file ) . - ) . - - - - - - - -- exit . ; , . , , GNOME, GNOME .

    - , , . .

    : , , , ( ). , .

    , , , , ( ) . . , , : , , , .

    . , ; . , : , .

    , passwd . passwd () . , , - , . .

    PWGEN pwgen (, , ) . , , , .

    , , . , . , , , - :Sorry, passwords do not match ,

    , :You must choose a longer password

    62 2. !

  • , :Bad: new password is too simple :

    , . , , - passwd .

    . , -, root-, passwd, .

    OS X passwd , Keychain . Keychain -Keychain . Keychain - . Keychain -Keychain - - . , Keychain Access .

    , ,

    . :

    ( - ) . - .

    , , - .

    , , .

    .

    , - .

    . - (, CONTROL+H), . . .

    Linux, , -Linux, , -, , - . login: , . passwd . , , , .

    . - . - - , . -

    63

  • . - , root-, - root su sudo . root- .

    root-, . -, root-, - . , .

    man . , Linux, , . info , Linux .

    1 . ,

    : Login incorrect

    , , , , . ?

    2 . . ? . , .

    3 . fido ? .

    4 . , ?

    5 . dog . ? . ?

    1 . tcsh, root- .

    2 . man- Devices () ? (: Devices Special

    Files .)

    3 . apropos: , man- passwd 1 5 . , - man, , .

    4 . , Linux ?

    64 2. !

  • 3 .

    Linux, (GUI): , - (command-line interface, CLI) . . - Linux , , , - . , GUI- . GUI , , .

    ( . - 5, 8 10) . , , - . : ls, cat, rm, less hostname . , , , -, , , , , , .

    , . . 157 . , , , - . , - ( emacs ), :& ; | * ? ' " ' [ ] ( ) $ < > { } # / \ ! ~

    , , TAB, , .

    , , . - , - .

    , , , ( ) . -

  • . - . (/) - , .

    , - (\) .

    , (, ** \*\*) . , (\\) .

    : '**' . -

    , : ' : >' . , .

    (CONTROL+H), - (CONTROL+U) ( CONTROL+M) , CONTROL+V . . :$ echo 'xxxxxxCONTROL+U'$ echo xxxxxxCONTROL+V CONTROL+U

    , CONTROL+U, , , , . echo od (octal display ), , CONTROL+U 25 (025):

    $ echo xxxxxxCONTROL+V CONTROL+U | od c

    0000000 x x x x x x 025 \n

    0000010

    \n , echo .

    Linux , , . , , -, , . , . , .

    66 3.

  • , , . , , GUI, .

    , - , . -

    , Windows Mac OS X, Linux GUI, . : , , ( ) .

    . : , , . 4.

    ls: , practice . ( vim 6, emacs 7 .) , , ls (list ) . , 3 .1, ls practice . ( , .) , 3 .1, - . . V info coreutils 'ls invocation' .

    3.1. ls, cat rm practice

    $ lspractice$ cat practice , $ rm practice$ cat practicecat: practice: No such file or directiory

    cat: cat . catenate, . ( 5, - 5 .4 cat - .)

    67

  • cat, . 3 .1 cat, practice . ls cat: ls , cat . V info coreutils 'cat invocation' .

    rm: rm (remove ) . 3 .1 rm, practice . rm , ls cat , practice . ( ls , cat , .) rm . V info coreutils 'rm invocation' .

    , ( ), , m. m i , m , , , y (yes ). , y, .$ rm -i toollistrm: remove regular file 'toollist'? y

    . m i (. 8, m i (. 8, i (. 8, i (. 8, (. 8, ) (. .103), m .

    less more: , , - less, more . , - . -, . less more . , less END , , , q . h , . less practice more practice cat, 3 .1, - 3 .1, -3 .1, -, . - , less /usr/share/dict/words . less more V man- .

    68 3.

  • hostname: hostname , . - , , . man- .$ hostnamedog

    , , -, , , , .

    ( ) T, oune gain Shell, , T, oune gain Shell, , , oune gain Shell, , oune gain Shell, , gain Shell, , gain Shell, , Shell, , Shell, , , , . , . , . , , , . T , T (. , oune gain Shell 8) CONTROL+D (. , TC Shell 9), .

    cp: cp (copy ) ( 3 .2) . , ( -) . cp .

    , cp, , -:cp _ _

    _ , cp, _- , cp () .

    3.2. cp

    $ lsmemo$ cp memo memo.copy$ lsmemo memo.copy

    cp, 3 .2, - 3 .2, -3 .2, - memo memo.copy . , . ls , memo -

    69

  • . cp ls : memo memo.copy .

    . 30 (0130):$ cp memo memo.0130

    Linux , , . - , . . 99 .

    cp V info-, info coreutils 'cp invocation' . - , scp, ftp rsync, V .

    CP , cp, cp, , . cp ( ) , , cp . cp i (inteactive ) . , oange.2 cp. , y:$ cp i orange orange.2cp: overwrite 'orange.2'? y

    mv: mv (move ) . , mv, , , - cp:mv __ __

    3 .3 memo memo.0130 . ls , memo . - mv memo.0130 . , 3 .2 cp .

    mv . - mv, cp: . 110 . V, , info coreutils 'mv invocation' .

    MV , cp, mv . , cp, mv i (inteactive). . cp .

    70 3.

  • 3.3. mv

    $ lsmemo$ mv memo memo.0130$ lsmemo.0130

    lpr: lpr (line printer ) . Linux , . . ( , ), lpstat p . lpr - , ( ) , P . report:$ lpr report

    , , . , .

    , - mailroom:$ lpr -P mailroom report

    , , - lpstat o lpq:$ lpqlp is ready and printing Rank Owner Job Files Total Sizeactive max 86 (standard input) 954061 bytes

    Max , , . , ( 86) lprm:$ lprm 86

    . - laser1:$ lpr -P laser1 05.txt 108.txt 12.txt

    lpr lpr 4 man- .

    71

  • grep: grep1 . , , - , .

    grep 3 .4 memo , credit, , . memo , discredit, creditor accreditation, grep , , . w (words ) -words ) - ) - grep . , , - .

    3.4. grep

    $ cat memoHelen:In our meeting on June 6 wediscussed the issue of credit.Have you had any further thoughtsabout it? Max$ grep 'credit' memodiscussed the issue of credit.

    grep , . V -V - - man- .

    head: head ( ) . , - . , months, 12 , , head Jan Oct ( 3 .5) .

    3.5. head , tail

    $ head monthsJanFebMarApr

    1 grep , ed UNIX-, Linux . g/re/p . g global ( ), re , , p (print) .

    72 3.

  • MayJunJulAugSepOct$ tail -5 monthsAugSepOctNovDec

    head , - , . . , , . , months:$ head -1 monthsJan

    head , . V info coreutils 'head invocation' .

    tail: , tail head, . , - , , , , .

    tail 3 .5 ( Aug Dec) months .

    logfile:$ tail -f logfile

    tail -, ( CONTROL+C) . V info coreutils 'tail invocation' .

    3.6. sort

    $ cat daysMondayTuesdayWednesdayThursdayFriday

    73

  • 3.6 ()

    Sunday$ sort daysFridayMondaySaturdaySundayThursdayTuesdayWednesday

    sort: sort , - . 3 .6 cat, - days, , . sort .

    sort - . u , ( ) . n . - V info coreutils 'sort invocation' .

    uniq: uniq (unique ) , -unique ) , - ) , - ) , -) , - , . , , uniq - ( 3 .7) .

    uniq , . (, sort , u .) V info coreutils 'uniq invocation' .

    diff: diff (difference ) . . , .

    diff u (unified output format -unified output format - output format -output format - format -format - -) , , (+), () . 3 .8 colors.1, colors.2 .

    74 3.

  • 3.7. uniq, -

    $ cat dupsCathyFredJoeJohnMaryMaryPaula$ uniq dupsCathyFredJoeJohnMaryPaula

    diff u , (hunk) . , - at (@@) . , , . - 3 .8 colors.1 ( ) . +1,5 , colors.2 .

    diff u - , . , , . , , . , ( , ), . V info-, diff .

    3.8. diff,

    $ diff -u colors.1 colors.2--- colors.1 2009-07-29 16:41:11.000000000 -0700+++ colors.2 2009-07-29 16:41:17.000000000 -0700@@ -1,6 +1,5 @@red+bluegreenyellow-pinkpurpleorange

    file: file . file ,

    75

  • letter_e.bz2 , bzip2, - :$ file letter_e.bz2letter_e.bz2: bzip2 compressed data, block size = 900k

    file :$ file memo zach.jpgmemo: ASCII textzach.jpg: JPEG image data, resolution (DPI), 72 x 72

    file V -V - - man- .

    | (): Linux, . . 151 .

    Linux- ( . - . 321) . UNIX Linux . ( [|] -) . - . UNIX Linux, , . ( . 143 .) -, , . , . , - . , head , head, . months ( . 3 .5) head :$ sort months | head -4AprAugDecFeb

    -, (, ) . wc (word count ) w (words ) -words ) - ) - , :$ ls | wc -w14

    76 3.

  • , - :$ tail months | lpr

    echo date - Linux- . script , todos unix2dos , , Windows Mac OS X .

    echo: echo , echo . 3 .9 . , (*), : , .

    echo Linux- . , * . 158, echo . - 4, 8 10 echo , .

    3.9. echo ( echo)

    $ lsmemo memo.0714 practice$ echo HiHi$ echo This is a sentence.This is a sentence.$ echo star: *star: memo memo.0714 practice$

    V -V - - info coreutils 'echo invocation' . echo, - bash tcsh, man- .

    echo , :

    $ echo 'My new file.' > myfile

    $ cat myfile

    My new file. , (>) echo myfile . -myfile . - . - . 146 .

    77

  • date: date :$ dateWed Mar 18 17:12:20 PDT 2009

    , , , :$ date +"%A %B %d"Wednesday March 18

    V info coreutils 'date invocation' .

    script: script , , . , , . vim, , vim - , , , .

    cat , vim, .

    script typescript . , script - . , script, , a . , script:$ scriptScript started, file is typescript$ whoamisam$ ls -l /bin | head -5total 5024-rwxr-xr-x 1 root root 2928 Sep 21 21:42 archdetect-rwxr-xr-x 1 root root 1054 Apr 26 15:37 autopartition-rwxr-xr-x 1 root root 7168 Sep 21 19:18 autopartition-loop-rwxr-xr-x 1 root root 701008 Aug 27 02:41 bash$ exitexitScript done, file is typescript

    , script, - exit . , cat, less, more . , script:$ cat typescriptScript started on Thu Sep 24 20:54:59 2009

    78 3.

  • $ whoamiSam$ ls -l /bin | head -5total 5024-rwxr-xr-x 1 root root 2928 Sep 21 21:42 archdetect-rwxr-xr-x 1 root root 1054 Apr 26 15:37 autopartition-rwxr-xr-x 1 root root 7168 Sep 21 19:18 autopartition-loop-rwxr-xr-x 1 root root 701008 Aug 27 02:41 bash$ exitexitScript done on Thu Sep 24 20:55:29 2009

    vim, emacs - , fromdos dos2unix ( ), ^M, . man-, script .

    todos/unix2dos: Linux Mac OS X Windows , Linux-, -, Windows Mac OS X, , . todos (to DOS DOS, tofrodos) unix2dos (UNIX to DOS UNIX DOS, unix2dos) Linux, , Windows OS X . memo.txt ( ) DOS-, :$ todos memo.txt

    $ unix2dos memo.txt

    -- Windows OS X . , -Windows OS X . , - OS X . , -OS X . , - X . , -X . , - . , - todos . todos , .bak, b (backup ) . unix2dos - , (unix2dos ), n (new ) .

    Windows OS X , Linux, fromdos (from DOS DOS, tofrodos) dos2unix (DOS to

    UNIX DOS UNIX, dos2unix):$ fromdos memo.txt

    $ dos2unix memo.txt

    fromdos dos2unix

    79

  • man-, - todos, fromdos, unix2dos dos2unix .

    t (translate , . V) Windows OS X Linux . d (delete ) tr ( \r) :

    $ cat memo | tr -d '\r' > memo.txt

    , (>) t memo.txt . 5, - . , todos unix2dos, .

    - . , --, DVD . , . , - , . , , , . , . , . , , , .

    bzip2: bzip2 . - . - - . bzip2 , . - , .

    . 8000 - letter_e 72 e , . .$ ls -lrwrwr-- 1 sam sam 584000 Mar 1 22:31 letter_e

    l (long ) ls - . , letter_e

    80 3.

  • 584 000 . v (verbose ) bzip2 , . - 99,99 :$ bzip2 -v letter_eletter_e: 11680.00:1, 0.001 bits/byte, 99.99% saved, 584000 in, 50 out.$ ls -l-rw-rw-r-- 1 sam sam 50 Mar 1 22:31 letter_e.bz2

    50 . bzip2 , .bz2 . - , ;

    , . bzip2 , .

    K ip2 , unip2, ip2 , unip2, 2 , unip2, unip2, 2, . k (keep ) .

    , zach.jpg - :$ ls -l-rw-r--r-- 1 sam sam 33287 Mar 1 22:40 zach.jpg

    bzip2 28 , :$ bzip2 -v zach.jpgzach.jpg: 1.391:1, 5.749 bits/byte, 28.13% saved, 33287 in, 23922 out.$ ls -l-rw-r--r-- 1 sam sam 23922 Mar 1 22:40 zach.jpg.bz2

    V man-, - bzip2 . - www.bzip.org Bzip2 mini-HOWTO (, , HOWTO: , . 58) .

    bunzip2 bzcat: , bzip2, bunzip2:$ bunzip2 letter_e.bz2$ ls -l-rw-rw-r-- 1 sam sam 584000 Mar 1 22:31 letter_e$ bunzip2 zach.jpg.bz2$ ls -l-rw-r--r-- 1 sam sam 33287 Mar 1 22:40 zach.jpg

    bzcat , bzip2 . cat .bz2, bzcat . cat, bzcat

    .bz2

    81

  • . , , - bzcat, head, :$ bzcat letter_e.bz2 | head -2eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

    bzcat letter_e.bz2 , - .

    bzip2recover , . -

    bzip2recover, , .

    gzip: gzip (GNU zip) , bzip2, . ,

    gzip, .gz . Linux - gzip- . , - , gzip- . gzip, gunzip zcat - bzip2, bunzip2 bzcat . V man-, gzip .

    compress , - , gzip . ,

    .Z .

    GZIP ZIP gip gunip ip unip. gip gunip ip unip. gunip ip unip. gunip ip unip. ip unip. ip unip. unip. unip. . ip, , , indows indows . ip ip, unip. ip unip PKZIP, indows, .

    tar: tar . tape archive . tar - . ( tar-, ) , tar- . cpio ( . V) .

    ls g, b d . tar c (create ), v (verbose ) f (file ) all.tar . , tar .

    bzip2recover

    gunzip zcat

    compress

    82 3.

  • tar . - all.tar 9700 , 6000 . .$ ls -l g b d-rw-r--r-- 1 zach other 1178 Aug 20 14:16 b-rw-r--r-- 1 zach zach 3783 Aug 20 14:17 d-rw-r--r-- 1 zach zach 1302 Aug 20 14:16 g$ tar -cvf all.tar g b dgbd$ ls -l all.tar-rw-r--r-- 1 zach zach 9728 Aug 20 14:17 all.tar$ tar -tvf all.tar-rw-r--r-- zach /zach 1302 2009-08-20 14:16 g-rw-r--r-- zach /other 1178 2009-08-20 14:16 b-rw-r--r-- zach /zach 3783 2009-08-20 14:17 d

    t . x t tar- . , tar 1, v .

    tar-, - , bzip2, compress gzip .

    , , . , tar bzip2, .tar.bz2 .tbz . , tar gzip, - .tar.gz, .tgz .gz, , tar compress, - .tar.Z .

    , tar gzip, . ( , bzip2, , gunzip bunzip2 .) , GNU- make (ftp.gnu.org/pub/gnu/make/make-3.81.tar.gz):$ ls -l mak*-rw-r--r-- 1 sam sam 1564560 Mar 26 18:25 make-3.81.tar.gz$ gunzip mak*$ ls -l mak*-rw-r--r-- 1 sam sam 6072320 Mar 26 18:25 make-3.81.tar$ tar -xvf mak*make-3.81/make-3.81/config/

    1 UNIX- tar , - , GNU- Linux- , . tar , .

    tar-

    83

  • make-3.81/config/dospaths.m4make-3.81/config/gettext.m4make-3.81/config/iconv.m4make-3.81/tests/run_make_testsmake-3.81/tests/run_make_tests.plmake-3.81/tests/test_driver.pl

    , - tar gzip: make-3.81.tar.gz ( 1,2 ) . (*) ( . * . 158, ls , mak . . , . gunzip make-3.81.tar ( .gz), - 4,8 . tar make-3.81, .$ ls -ld mak*drwxr-xr-x 8 sam sam 4096 Mar 31 2006 make-3.81-rw-r--r-- 1 sam sam 6072320 Mar 26 18:25 make-3.81.tar$ ls -l make-3.81total 2100-rw-r--r-- 1 sam sam 53838 Mar 31 2006 ABOUT-NLS-rw-r--r-- 1 sam sam 2810 Mar 19 2006 AUTHORS-rw-r--r-- 1 sam sam 18043 Dec 10 1996 COPYING-rw-r--r-- 1 sam sam 106390 Mar 31 2006 ChangeLog-rw-r--r-- 1 sam sam 16907 Feb 11 2006 vmsjobs.c-rw-r--r-- 1 sam sam 17397 Feb 11 2006 vpath.cdrwxr-xr-x 6 sam sam 4096 Mar 31 2006 w32

    tar , , mak: make-3.81.tar make-3.81 . d (directory ) ls - , . ls , - make-3.81 . V man-, tar .

    TAR: X ta . ta . . , , ta t ta. (. mkdi 4), ta mkdi 4), ta 4), ta ta . , . . , , ta , ta , , . t , ta .

    84 3.

  • TAR: X x ta , , . , .

    gunzip tar (|), gunzip, tar:

    $ gunzip -c make-3.81.tar.gz | tar -xvf -

    c gunzip . () tar . , , - . 151, V ( gzip tar) . tar z . tar gunzip ( gzip, ) :

    $ tar -xvzf make-3.81.tar.gz

    j bzip2 bunzip2 .

    , whereis slocate , , , , . , which , . slocate .

    which whereis: Linux - , -

    . . , , PATH: , . 312 . , , - . .

    which , , . ( 4 -

    Linux .) . - . which , - . which tar:$ which tar/bin/tar

    which

    , 85

  • which , , . which, , , , . ( . 111 .) , , tar -, /bin/tar /usr/local/bin/tar, , .

    whereis , -, , .

    , , , - tar:$ whereis tartar: /bin/tar /usr/include/tar.h /usr/share/man/man1/tar.1.gz

    whereis , tar: tar, tar man-, - tar .

    WHICH WHEREIS , which () , (. . 312, PTH: , , . , which (, ). wheeis , . wheeis () , ; wheeis .

    WHICH, WHEREIS , which, wheeis, , , , , (. 5, ). wheeis, , echo ( , , ), :$ whereis echoecho: /bin/echo /usr/share/man/man1/echo.1.gz

    wheeis echo. which wheeis echo. which echo. which echo. which . which which :$ which echo/bin/echo

    ash, type (. 10, ), , :$ type echoecho is a shell builtin (echo , )

    slocate locate: slocate (secure locate ), -secure locate ), - locate ), -locate ), - ), - locate, :

    whereis

    86 3.

  • $ slocate motd/usr/share/app-install/icons/xmotd.xpm/usr/share/app-install/desktop/motd-editor.desktop/usr/share/app-install/desktop/xmotd.desktop/usr/share/base-files/motd.md5sums/usr/share/base-files/motd

    , slocate locate, - . slocate locate updatedb slocate . - cron ( crontab cron V) .

    , , , . , , .

    , , , .

    , , - , . who -, , , , .

    w finger , , . , finger - , . . 3 .1 , .

    who: , who , . 3 .10 who , Sam, Max Zach . (Max .) , . -, . . ( ) , .

    , who, , , . ,

    87

  • write ( . ) . who , ( . ) .

    , who, , (|, . . 151), less, . - grep, .

    , , who am i:$ who am imax tty2 2009-07-25 16:42

    3.10. who

    $ whosam tty4 2009-07-25 17:18max tty2 2009-07-25 16:42zach tty1 2009-07-25 16:39max pts/4 2009-07-25 17:27 (coffee)

    3.11. finger, : ,

    $ fingerLogin Name Tty Idle Login Time Office max Max Wild *tty2 Jul 25 16:42max Max Wild pts/4 3 Jul 25 17:27 (coffee)sam Sam the Great *tty4 29 Jul 25 17:18zach Zach Brill *tty1 1:07 Jul 25 16:39

    finger: , finger , . finger - , , , , , - - , , . , , , . , 3 .11 Max coffee . (*), Tty, - , , ( . mesg: . 92) .

    FINGER , , finge. , . Mac OS X finge .

    88 3.

  • finger - , . 3 .12 finger Max, - (tty2) . (pts/4) 3 7 . finger , Max , Zach - 1693 .

    3 .12 finger . ,

    Plan:, Max . finger .plan Max .

    3.12. finger, : ,

    $ finger maxLogin: max Name: Max WildDirectory: /home/max Shell: /bin/tcshOn since Fri Jul 25 16:42 (PDT) on tty2 (messages off)On since Fri Jul 25 17:27 (PDT) on pts/4 from coffee 3 minutes 7 seconds idleNew mail received Sat Jul 25 17:16 2009 (PDT) Unread since Sat Jul 25 16:44 2009 (PDT)Plan:I will be at a conference in Hawaii all next week.If you need to see me, contact Zach Brill, x1693.: . , . 1693.

    ( , , .plan, - , ls, .) , .plan, , , , . finger .project .pgpkey, . Max , finger , , .

    finger . , , Helen Simpson, , Helen Simpson, , - hls . finger, , Helen, . -, Helen Simpson:

    .plan .project

    89

  • $ finger HELENLogin: hls Name: Helen Simpson.$ finger simpsonLogin: hls Name: Helen Simpson.

    finger V .

    w: , w , . w , , - who: , w, , - .

    3 .13 , Max, Zach Sam . , - . , - . , (, , ) . , - , , . , .

    , w, , , ( , ), - ( ) . , , , , 1, 5 15 . , uptime . w, who finger . 3 .1 .

    3.13. w

    $ w 17:47:35 up 1 day, 8:10, 4 users, load average: 0.34, 0.23, 0.26USER TTY FROM LOGIN@ IDLE JCPU PCPU WHATsam tty4 - 17:18 29:14m 0.20s 0.00s vi memomax tty2 - 16:42 0.00s 0.20s 0.07s wzach tty1 - 16:39 1:07 0.05s 0.00s run_bdgtmax pts/4 coffee 17:27 3:10m 0.24s 0.24s bash

    3.1. w, who finger

    w who finger

    ( )

    90 3.

  • w who finger

    ,

    ,

    ( /etc/passwd)

    ,

    , , - , , .

    write: write , . write , . write - ( 3 .14) .

    write :write _ []

    3.14. write,

    $ write maxHi Max, are you there? o , Ma, ? o

    3.15. write,

    $ write maxHi Max, are you there? o , Ma, ? oMessage from [email protected] on pts/0 at 16:23 Yes Zach, I'm here. o , , .

    _ , - . , , . who, w finger , , .

    , , write, , . write - ( 3 .15) . -

    91

  • , o ( over ), , , oo ( over and out ), . , CONTROL+D . write , EOF (end of file) . .

    , , CONTROL+ L CONTROL+ R, .

    , , . , , .

    mesg: . , :$ mesg y

    Max , Zach - , Zach :$ write maxwrite: max has messages disabled max

    mesg n . mesg y ( yes, , ) n ( no, , ) .

    - write, , -, , :$ write maxwrite: write: you have write permission turned off. write

    , , -, . .

    write , - , .

    92 3.

  • , . .

    Linux , mailx, , Mozilla/Thunderbird, pine, Kmail , . emacs . sylpheed (sylpheed.sraoss.jp/en) .

    , . procmail (www.procmail.org) , , - ; , - ; . . GNU Privacy Guard (GPG GNUpg; www.gnupg.org) , .

    , , ,

    , , . , Max , . , [email protected] .

    , , , , Linux- . , .

    , . 3 .2, -, , .

    3.2.

    cp

    diff

    file

    grep ()

    head

    lpq ,

    lpr ()

    lprm

    93

  • mv ()

    sort

    tail

    uniq , -

    , , bzip2 . , , , - . , bzip2 bunzip2, () . . 3 .3 - 3 .3 -3 .3 - , . bzip2 .

    3.3.

    bunzip2 , bzip2,

    bzcat , bzip2

    bzip2

    compress

    gunzip , gzip compress, -

    gzip ( , bzip2)

    zcat , gzip

    , , - , , - , , - . tar ( . 3 .4) . .tar.bz2, .tar.gz .tgz , , , tar, , .

    3.4.

    tar

    , . 3 .5, , - . , C++, .

    3.5.

    locate

    whereis , man-

    which

    3.2 ()

    94 3.

  • . 3 .6 , - . , , , , , - .

    3.6.

    finger ,

    hostname

    w ,

    who ,

    , . 3 .7, - 3 .7, -3 .7, - .

    3.7.

    mesg , write

    write ,

    . 3 .8

    3.8.

    date

    echo

    1 . , , -

    ?

    2 . write ? ?

    3 . , , done -?

    $ cp to_do done $ mv to_do done

    4 . ? Hi $2, I'm number * (guess)!

    5 . Ace Electronics phone, ? ? -? -?

    6 . , diff -, ? ( gzip .) , , diff , , ASCII .

    95

  • 7 . .plan . finger .plan?

    8 . , which , , ?

    9 . , - ? , ?

    10 . , file /usr/bin . ?

    11 . status.report? ?

    1 . colors.1 colors.2, 3 .8 .

    , diff u . , ?

    2 . : $ echo cat $ cat echo

    , .

    3 . 5, phone.gz, - . , .

    4 . ,

    ) gzip 80 ;

    ) gzip 10 ;

    ) gzip .

    ls l , - . , , ?

    5 . . , , gzip, - , . man-, uuencode, - ASCII . .

    ) ASCII, uuencode . , ? . ( uuencode , , yum aptitude, . sharutils .)

    ) uuencode ? .

    96 3.

  • 4 .

    , . , - . Linux , , . , . , - , Access Control Lists (ACL), ( ) . - , .

    , - df, fsck, mkfs tune2fs, V, -V, -, - .

    . -

    : , , , - , . - ( . 4 .1) .

    1 2

    1 2

    . 4 .1 .

    -

  • Linux . -

    . , . Linux- , - . - .

    , . ,

    . , . , . 4 .2 , - correspond () . : business (), memos () personal () .

    business , , . , , , , milk_co .

    Linux . - .

    , , , , , - . . 4 .2 4 .3 , , , . , . , , - . , , , . , - , , . ( . 4 .2 4 .3 .)

    , . , , ( , ) ( ) . , . .

    98 4.

  • Directory Files and Ordinary Files 79

    downward from the root, with paths connecting the root to each of the other files. Atthe end of each path is either an ordinary file or a directory file. Special files, whichcan also appear at the ends of paths, provide access to operating system features.Ordinary files, or simply files, appear at the ends of paths that cannot support otherpaths. Directory files, also referred to as directories or folders, are the points thatother paths can branch off from. (Figures 4-2 and 4-3 show some empty directo-ries.) When you refer to the tree, up is toward the root and down is away from theroot. Directories directly connected by a path are called parents (closer to the root)and children (farther from the root). A pathname is a series of names that trace apath along branches from one file to another. See page 83 for more informationabout pathnames.

    FilenamesEvery file has a filename. The maximum length of a filename varies with the type offilesystem; Linux supports several types of filesystems. Although most of todaysfilesystems allow files with names up to 255 characters long, some filesystems

    Figure 4-2 A secretarys directories

    correspond

    personal

    milk_co

    businessmemos

    cheese_co

    letter_2letter_1

    Figure 4-3 Directories and ordinary files

    DirectoryDirectory

    Ordinary FileOrdinary File

    Ordinary File Ordinary File

    Ordinary File

    Directory

    Directory

    Directory

    Directory

    000.book.fm Page 79 Wednesday, September 30, 2009 10:13 AM

    . 4 .2 .

    . 4 .3 .

    . - . Linux . - . - - 255 , . , , , , :

    (AZ) .

    (az) .

    (09) .

    (_) .

    ( .) .

    (,) .

    99

  • , . ( , Linux .) -Linux .) - .) -, , .

    . , hold1, wombat junk, , foo foobar . , , . , :

    correspond ();

    january ();

    davis ();

    reports ();

    2001;

    acct_payable (__) .

    - , -

    . , - DOS Windows, , , . UNIX- 14- , Macintosh 31- . , , , , . .

    stat ( . V) . , Namelen:, , - (/home) .$ stat -f /home | grep -i name ID: ff1f5275f648468b Namelen: 255 Type: ext2/ext3

    f stat . i (case insensitive ) -case insensitive ) - insensitive ) -insensitive ) - ) - grep .

    . , - . . 69 .

    () , : - . , ext UFS

    -

    100 4.

  • , JANUARY, January january . FAT (- ) - , . HFS+, OS X, , , - .

    , . , . . : joe.05.04.26, new_stuff. , , , , . my file .$ lpr my\ file$ lpr "my file"

    , . , . 4 .1, . , C, , - . , . , , notes.4.10.01 files.tar.gz . - Mac OS X , .

    4.1.

    compute .c C

    compute .o compute .c

    compute compute .c

    memo .0410 .txt

    memo .pdf PDF-; GUI xpdf kpdf

    memo .ps PostScript- GUI; -- GUI; -GUI; - - gs kpdf

    memo .Z , compress; - uncompress gunzip

    memo .tgz memo .tar .gz tar- , gzip

    101

  • memo .gz , gzip; - zcat, gunzip

    memo .bz2 , bzip2; - bzcat, bunzip2

    memo .html , -, - Firefox

    photo .gif, photo .jpg,photo .jpeg, photo .bmp,photo .tif, or photo .tiff

    , ,

    , , ( - ), ls . ls a , . ( . . 103) , .

    .plan ( . 3, .plan .project) . - - - - (. ..) ( . . . . . 108) .

    Linux ,

    . : ( ) zach . pwd (print working directory ) ( . - 5, ) .

    . pwd ( . 4 .1) . - Linux /home, Mac OS X /Users .

    ls . , ls , . ( , , - .)

    pwd

    4.1 ()

    102 4.

  • , , - . Mac OS X . , -, stty (set terminal ) ( . . 48) ( . . 49) .

    4.1.

    login: maxPassword: Last login: Wed Oct 20 11:14:21 from bravo$ pwd/home/max

    , -, , . , , . , , ls a . . 284 ( bash) 9 ( tcsh) .

    , . (/) , . , , - . , . , .

    .

    (/), , - .

    (/), . , . , - , . , (/) . ,

    / ( )

    103

  • , - . - , , , (, /home/zach/) . , , , . . 4 .4 .

    ( ), - , , . , Sam, -Sam, -, -, , /usr/bin:$ pwd/home/sam$ ls /usr/bin7z kwin7za kwin_killer_helper822-date kwin_rules_dialog84 Chapter 4 The Filesystem

    ~ (Tilde) in PathnamesIn another form of absolute pathname, the shell expands the characters ~/ (a tildefollowed by a slash) at the start of a pathname into the pathname of your homedirectory. Using this shortcut, you can display your .bashrc startup file (page 272)with the following command, no matter which directory is the working directory:

    $ less ~/.bashrc

    A tilde quickly references paths that start with your or someone elses home directory.The shell expands a tilde followed by a username at the beginning of a pathname intothe pathname of that users home directory. For example, assuming he has permissionto do so, Max can examine Sams .bashrc file with the following command:

    $ less ~sam/.bashrc

    Refer to Tilde Expansion on page 337 for more information.

    Relative PathnamesA relative pathname traces a path from the working directory to a file. The path-name is relative to the working directory. Any pathname that does not begin with theroot directory (represented by /) or a tilde (~) is a relative pathname. Like absolutepathnames, relative pathnames can trace a path through many directories. The sim-plest relative pathname is a simple filename, which identifies a file in the workingdirectory. The examples in the next sections use absolute and relative pathnames.

    Significance of the Working DirectoryTo access any file in the working directory, you need only a simple filename. Toaccess a file in another directory, you must use a pathname. Typing a long pathnameis tedious and increases the chance of making a mistake. This possibility is less likelyunder a GUI, where you click filenames or icons. You can choose a working direc-tory for any particular task to reduce the need for long pathnames. Your choice of a

    Figure 4-5 Absolute pathnames

    /

    etctmphome

    hlszachmax

    notesbin

    report log

    /home /etc

    /home/hls

    /home/hls/notes

    /home/hls/bin/log

    /home/zach

    000.book.fm Page 84 Wednesday, September 30, 2009 10:13 AM

    . 4 .4 .

    ~ () - ~/ (, ), , . , .bashrc ( . . 286) ( , ):$ less ~/.bashrc

    104 4.

  • , - . , - , . (, ), Max .bashrc, Sam, :$ less ~sam/.bashrc

    . 355 .

    . , ( /) (~), . , , , . , . - .

    . . , . (GUI), . , . - , - , - .

    , , , ( ). , , . pwd. , vim, , . , . , goals, :$ vim ~/goals

    . 4 .5 . , - , . , , : ,

    105

  • . . , , - , - . ( . .. . . . . . 108 .)

    /

    etctmphome

    hlszachmax

    notesbin

    report log

    ..

    notes

    bin/log

    .. /zach

    =.

    . 4 .5 .

    ( mkdir), - ( cd), ( rmdir), , . , Linux .86 Chapter 4 The Filesystem

    mkdir: Creates a DirectoryThe mkdir utility creates a directory. The argument (page 941) to mkdir becomes thepathname of the new directory. The following examples develop the directory struc-ture shown in Figure 4-7. In the figure, the directories that are added appear in alighter shade than the others and are connected by dashes.

    In Figure 4-8, pwd shows that Max is working in his home directory (/home/max)and ls shows the names of the files in his home directory: demo, names, and temp.Using mkdir, Max creates a directory named literature as a child of his home direc-tory. He uses a relative pathname (a simple filename) because he wants the literaturedirectory to be a child of the working directory. Max could have used an absolutepathname to create the same directory: mkdir /home/max/literature or mkdir~max/literature.

    The second ls in Figure 4-8 verifies the presence of the new directory. The F option tols displays a slash after the name of each directory and an asterisk after each executable

    Figure 4-7 The file structure developed in the examples

    /

    home

    max

    literature

    promo

    demonames temp

    $ pwd/home/max$ lsdemo names temp$ mkdir literature$ lsdemo literature names temp$ ls -Fdemo literature/ names temp$ ls literature$

    Figure 4-8 The mkdir utility

    000.book.fm Page 86 Wednesday, September 30, 2009 10:13 AM

    . 4 .6 . ,

    106 4.

  • mkdir: mkdir . mkdir . , . 4 .6 . .

    4 .2 pwd , Max (/home/max), ls : demo, names temp .

    mkdir, Max literature - . ( ), , literature - . Max : mkdir /home/max/literature mkdir ~max/literature .

    ls, 4 .2, - . F ls - ( , ) . ls , . ls , literature .

    4.2. mkdir

    $ pwd/home/max$ lsdemo names temp$ mkdir literature$ lsdemo literature names temp$ ls -Fdemo literature/ names temp$ ls literature$

    promo, - literature . , /home/max , - :$ pwd/home/max$ mkdir literature/promo

    :$ mkdir /home/max/literature/promo

    , literature promo, mkdir p (parents ):$ pwd/home/max

    107

  • $ lsdemo names temp$ mkdir -p literature/promo

    $ mkdir -p /home/max/literature/promo

    cd: cd (change directory ) , . 4 .3 /home/max/literature, pwd . Max cd , - literature . , .

    pwd , Max . -Max . - . - cd , . cd, 4 .3, , Max -Max - - . , , , Max literature (cd literature) pwd .

    4.3. cd

    $ cd /home/max/literature$ pwd/home/max/literature$ cd$ pwd/home/max$ cd literature$ pwd/home/max/literature

    . . . , , , . , . , . , , . cd . Sam, .

    . . . mkdir : (.) (..) . . 4 .5 . (.) - , (..) ,

    108 4.

  • . , .

    literature (..) - : (/home/max), memoA .$ pwd/home/max/literature$ ls ..demo literature names temp$ cp memoA ..$ ls ..demo literature memoA names temp

    cd promo ( literature ) Max vim - .$ cd promo$ vim ../../names

    , , , . ls, vim, mkdir, rm Linux- .

    rmdir: rmdir (remove directory ) . , -, . .., . , , rm , . ( ) . .., rmdir . promo:$ rmdir /home/max/literature/promo

    rm r (rm r filename), , .

    RM R , m , m , , , , . , (*). , .

    , -

    letter . - touch ( . V):

    touch

    109

  • $ cd$ pwd/home/max$ touch letter

    /home/max, cp letter /home/max/literature/promo . ( promo, .) letter.0610:$ cp letter literature/promo/letter.0610

    Max , -Max , - , - vim :$ vim literature/promo/letter.0610

    Max , cd, vim promo :$ cd literature/promo$ pwd/home/max/literature/promo$ vim letter.0610

    ( /home/max/literature), Max , -Max , - , - ..:$ cd ..$ pwd/home/max/literature90 Chapter 4 The Filesystem

    mv, cp: Move or Copy FilesChapter 3 discussed the use of mv to rename files. However, mv works even moregenerally: You can use this utility to move files from one directory to another(change the pathname of a file) as well as to change a simple filename. When usedto move one or more files to a new directory, the mv command has this syntax:

    mv existing-file-list directory

    If the working directory is /home/max, Max can use the following command to movethe files names and temp from the working directory to the literature directory:

    $ mv names temp literature

    This command changes the absolute pathnames of the names and temp files from/home/max/names and /home/max/temp to /home/max/literature/names and/home/max/literature/temp, respectively (Figure 4-10). Like most Linux com-mands, mv accepts either absolute or relative pathnames.

    As you work with Linux and create more files, you will need to create new directo-ries using mkdir to keep the files organized. The mv utility is a useful tool for movingfiles from one directory to another as you extend your directory hierarchy.

    The cp utility works in the same way as mv does, except that it makes copies of theexisting-file-list in the specified directory.

    mv: Moves a DirectoryJust as it moves ordinary files from one directory to another, so mv can move direc-tories. The syntax is similar except that you specify one or more directories, notordinary files, to move:

    mv existing-directory-list new-directory

    Figure 4-10 Using mv to move names and temp

    home

    sammaxzach

    literature

    names temp

    names temp

    /

    000.book.fm Page 90 Wednesday, September 30, 2009 10:13 AM

    . 4 .7 . mv names temp

    mv, cp: 3 mv . mv :

    110 4.

  • ( ), . mv - , :mv __

    /home/max, Max names temp literature :$ mv names temp literature

    names temp /home/max/names /home/max/temp /home/max/literature/names /home/max/literature/temp ( . 4 .7) . Linux, mv , .

    Linux , -, mkdir . mv .

    cp , mv, , __ .

    mv: mv , . , , :mv __ _

    _ , __ - , mv _ ( mv ) .

    mv, cp , - r (recursive ) . V, tar cpio .

    Linux - . - Linux, , Linux- . Linux, FSSTND (Linux Filesystem Standard) 1994 . 1995 - , UNIX- FHS (Linux Filesystem Hierarchy Standard Linux;

    111

  • proton.pathname.com/fhs) . FHS LSB (Linux Standard Base Linux; www.linuxfoundation.org/en/LSB), FSG (Free Standards Group ) . , FSG Open Source Development Labs (OSDL), Linux Foundation (www.linuxfoundation.org) . . 4 .8 FHS . . Working with Directories 91

    If new-directory does not exist, the existing-directory-list must contain just onedirectory name, which mv changes to new-directory (mv renames the directory).Although you can rename directories using mv, you cannot copy their contents withcp unless you use the r (recursive) option. Refer to the explanations of tar(page 846) and cpio (page 644) for other ways to copy and move directories.

    Important Standard Directories and FilesOriginally files on a Linux system were not located in standard places within thedirectory hierarchy. The scattered files made it difficult to document and maintain aLinux system and just about impossible for someone to release a software packagethat would compile and run on all Linux systems. The first standard for the Linuxfilesystem, the FSSTND (Linux Filesystem Standard), was released early in 1994. Inearly 1995 work was started on a broader standard covering many UNIX-like sys-tems: FHS (Linux Filesystem Hierarchy Standard; proton.pathname.com/fhs). Morerecently FHS has been incorporated in LSB (Linux Standard Base; www.linuxfoun-dation.org/en/LSB), a workgroup of FSG (Free Standards Group). Finally, FSG com-bined with Open Source Development Labs (OSDL) to form the Linux Foundation(www.linuxfoundation.org). Figure 4-11 shows the locations of some importantdirectories and files as specified by FHS. The significance of many of these directo-ries will become clear as you continue reading.

    The following list describes the directories shown in Figure 4-11, some of the direc-tories specified by FHS, and some other directories. Most Linux distributions donot use all the directories specified by FHS. Be aware that you cannot always deter-mine the function of a directory by its name. For example, although /opt stores add-on software, /etc/opt stores configuration files for the software in /opt.

    / Root The root directory, present in all Linux filesystem structures, is the ancestor ofall files in the filesystem.

    /bin Essential command binaries Holds the files needed to bring the system up and run itwhen it first comes up in single-user or recovery mode.

    /boot Static files of the boot loader Contains all files needed to boot the system.

    /de