Practical Linux 2000 Ebook free download pdf pdf

Gratis

0
0
704
3 months ago
Preview
Full text

Introduction 1

  No patent liability is assumed with respect to the Matt Purcelluse of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author Project Editor Pamela Woolf assume no responsibility for errors or omissions.

4 Using Text Editors 63

Selecting an Editor 64Commercial Linux Word Processors 64 Using Screen Editors 67Using Stream Editors 75 Using Linux Dictionaries 77Getting the web2 Dictionary 77 Dictionaries: Rolling Your Own 78Spell Checking with the ispell Command 78 Using Internet Dictionaries with the dictClients 79 Saving Paper with the mpage Command 79 Creating Formatted Documents 80Using Text-Formatting Filter Commands 80 Using Text-Processing Systems 82 CONTENTS 7 Working with Hard Drives 113 Enabling PCMCIA Services 138Determining Your PCMCIA Controller 139 9 Enabling a PC Card Device 137 Adding a Zip Drive 132Before Installing a Zip Drive 133 Ejecting, Password-Protecting, and Read-Write–Protecting Zip Disks 134 Adding a Tape Drive 130Installing a Tape Drive 130 Using the mt Command 131 8 Adding Tape and Zip Drives 129 Partitioning a Hard Drive with the fdisk Command 120Manipulating Partitions with the sfdisk Command 123Mounting a Hard Drive or Other Device 124Mounting and Unmounting Remote NFS Hard Drives 126Mounting File Systems with linuxconf 126 Choosing a File System 118 Adding a Hard Drive 119Identifying Hard Drives and Devices 119 Determining the Volume Device and Partition 114Hard Drive Devices 115 Creating Aliases 108 Using the linuxconf Utility 109 5 Printing Files 87 Customizing Your Login 105Customizing Your Command-Line Prompt 106 Displaying Environment Variables with the printenv Command 100Displaying Environment Variables with the env Command 102Setting an Environment Variable on the Command Line 102Deleting an Environment Variable from the Command Line 103Setting Command PATHs 104 6 Configuring Your Environment 99 II Configuring Your System Reordering Print Jobs 95 Stopping Print Jobs 95Sending Faxes with the lpr Command 95 Printing Files at the Command Line 93 Listing the Print Queue 93Controlling Printers and Print Jobs 93 Configuring Printers for WordPerfect for Linux 91Spooling Files to Your Printer 92 Adding Printers 88Checking Your Printer 88 Adding a Local Printer by Editing/etc/printcap 90 Using the cardmgr Command 141Listing Your PC Card and Drivers 141 Disabling cardmgr Command EventNotification 142 Using the cardctl Command 142Checking the Status of Incoming or Outgoing Obtaining the Status of PC Cards 143 Faxes 164 Listing Your PC Card Configuration 143 Viewing Received Faxes 164 Inserting a PC Card 144 Printing a Received Fax 165Ejecting a PC Card 144 Deleting a Received Fax 165 Suspending and Restoring PC CardPower 145 III The X Window System 10 Adding a Pointing Device 147 12 Running and Configuring X 169 Adding a Mouse 148 Configuring XFree86 with XF86Setup 170Using and Configuring gpm 148 Configuring a Synaptics Touchpad 149 Configuring Xfree86 with XConfigurator 170 Installing a Joystick 151Configuring Your Graphics Card 170 Configuring a Joystick 152 Starting X11 171

11 Configuring a Modem and Fax Service 153

Using the startx Command 171 Using Virtual Consoles with X 172Selecting a Modem for Linux 154 Starting Multiple X Sessions 172 Using the dmesg Command to Check SerialPort Status 154 Stopping X 173Testing Your Modem with the echo Command 155 System and X Session Control with Display Managers 173 Creating the /dev/modem Device 156Logging In with xdm 173 Creating /dev/modem with the lnCustomizing the xdm Banner Screens 176 Command 156 Customizing the .xinitrc Startup Script 178Getting Serial Port Information with the set- serial Command 156 Customizing Your Workspace 179 Enabling Dial-In Service 157Setting a Screen Saver 179 Configuring Linux for Dial-in Service 157 Setting the Background Desktop Color 182 Configuring Linux for Dial-in PPP Setting the Background Desktop Service 160 Pattern 182Using a Desktop Wallpaper 182 Configuring Fax Service 161Setting the Mouse Pointer 184 Configuring the fax Shell Script 162Configuring the Mouse 185 Testing Your Fax Configuration 163Configuring Terminal Windows 186 Sending a Fax Using the fax Shell Using X11 Resources 187Script 164 Setting Up to Wait for Incoming Faxes 164vi CONTENTSUsing the xloadimage Client to View 13 Using a Window Manager 189 Captures 210Window Managers and Desktop Capturing and Viewing Screens with the xvEnvironments 190 Client 210 Using the xmag Client to Capture MagnifiedSelecting an X11 Window Manager 190 Images 212 The K Desktop Environment and kwm 191Enlightenment 192 15 Using Graphics and Multimedia Tools 215 Window Maker 193Selecting a Graphics Program 216 Starting a Window Manager 193 Using the GIMP Client 216 Starting KDE 194Using ImageMagick 224 Starting Enlightenment/GNOME 194 Starting Window Maker 195Translating or Converting Graphics 229 Using the pbm, ppm, and pnm Utilities 233 14 Performing Common X Operations 197 Previewing Graphics and PostScript Using X11 Toolkit Command-LineDocuments 234 Options 198 Using the gv PostScript Previewer 234 Using Geometry Settings to Set WindowUsing Adobe Acrobat 237 Size 198 Playing Music CDs 240Setting Foreground and Background Colors 199 Watching and Listening to Internet TV and Radio 243Moving, Resizing, and Managing Windows 200 Using RealPlayer 244 Specifying an X11 Window Title 200Playing Animations and Movies with the Minimizing, Maximizing, or Closingxanim Client 245 Windows 201Viewing X11 Fonts 202 IV Connecting to Your Internet ServiceViewing X11 Fonts with the xfontsel Provider Client 203Using the xfd Client to View Font

16 Connecting to Your Internet Service

Character Maps 203 Provider 249 Copying and Pasting Text 206 Configuring a PPP Connection 250Using the xcutsel Client to Copy Text 206 Checking Your Serial Port and Modem 251Copying Text with the xclipboard Client 207 Checking Your Linux Kernel and File Systemfor PPP Support 251 Capturing Windows and the Desktop 208Using xwd to Capture Windows 208 Configuring PPP for Your ISP 253Using xwud to Display Window Dumps 209 Configuring Your PPP Connection Using the ncftp Command 292Scripts 254 Downloading with the ncftp Command 292 Editing the ppp-on Connection Script 254Using Netscape to Download Files 293 Configuring PPP with kppp 255 19 Using Web Browsers 295 Starting a PPP Connection 257Configuring the Lynx Browser 298 Starting a PPP Connection Using the minicom Program 257Using Netscape Communicator 300 Starting a PPP Connection with the ppp-on Downloading and Installing NetscapeScript 258 Communicator 300Starting a PPP Connection with kppp 258 Working with Netscape Communicator 303Closing Your PPP Connection 258 20 Using telnet and Internet Relay Chat 309 Checking Your PPP Connection 259Checking PPP Connections with the ifconfig Using the telnet Command 310Command 259 Connecting to Other Computers 310Getting PPP Statistics with the pppstats Downloading Files During telnetCommand 260 Sessions 313Getting PPP Statistics with kpppload 260 Chatting with Internet Relay Chat 314Testing PPP Connection Speed with the ping Starting an irc Session 314Command 260 Getting PPP Interface Information with theroute Command 261 V System AdministrationTroubleshooting PPP Connections with Your System Log 261 21 Basic Shell Programming 321 17 Using Electronic Mail 265 What Shell Scripts Are Used For 322 Retrieving Electronic Mail 266Writing Shell Programs 323 Using fetchmail 266 Good Programming Practice 323A Sample Program 323 Selecting a Mail Program 269Using mail 269 Using Shell Variables 327Using pine 271 Using Variables in Scripts 328Using Netscape Messenger to Create, Send, A Sample Script 328and Read Mail 274 Using Shell Constructs 332 Managing Electronic Mail 280Conditional Constructs: The if Configuring procmail to Filter Mail 281Statement 333 Repeating Commands with while 336

18 Using FTP 283

Repeating Commands with for 336 Using ftp to Download Files 286Writing Shell Functions 336 Using ftp Help Commands 291 A Simple Shell Function 337Using a Library 338viii CONTENTSUsing the usercfg Tool 363 22 Using Basic Programming Tools 339 Adding a User with usercfg 365Recompiling Code 340 View/Edit Users 367 Locking a User 368Compiling Programs with gcc 340 Unlocking a User 369Linking Programs with the ld Linker 341 Removing a User 370 Adding a Group 371Building Programs with the make Editing an Existing Group 373Command 342 Removing a Group 373 A Sample Program 343Finishing Up with usercfg 373 make Options 344 Adding, Editing, and Deleting Users UsingA Sample Program: the makethe Command Line 373 Command 345 Adding Users with useradd 374A Sample Program 345 Modifying Users with the usermod Specifying Different Makefiles 347Command 374 Deleting Users with the userdel Getting Started Quickly with NewCommand 375 Programs 347 Adding, Editing, and Deleting Groups 376Specifying Different Makefiles 349 Adding Groups with the groupaddBuilding X11 Makefiles with the xmkmf Command 376Script 349 Modifying Groups with the groupmod Command 376 23 Using Boot Managers 351 Deleting Groups with the groupdel Command 376How Linux Boots: LILO/LOADLIN 352 Changing User and Group Ownership 377Configuring LILO 352 Managing Groups with gpasswd 377 Changing the Default Boot 354Using the chgrp Command 378 Passing Kernel Parameters 354 Booting to a Specific Run Level 355 Changing File Ownership andPermissions 378 Using LOADLIN 356 Using the chown Command 378 Booting from DOS to Linux 356Using the chmod Command 379 Setting Up LOADLIN 357 Advanced Concepts: Password AuthenticationPassing Kernel Parameters with Module 382LOADLIN 359 Improving System Security Using PAM 382 24 Managing Users and Groups 361 25 Managing Scheduling Services 389 Users, Groups, and Their Relation to the System 362 Configuring inittab and rc Files 390The inittab File 391 The rc Files 394 LinuxPRACTICAL Configuring crontab Scheduling Enabling the Network File SystemService 395 Service 425 Enabling crontab Service 396Enabling Dial-In Service 427crontab Entries 396 Setting Up the PPP Options Files 427Allowing and Preventing Access to the crontab Configuring Getty Devices 428Service 399 Configuring the at Command Service 400

27 Managing Daemons 431

Enabling at Command Service 400Editing and Creating Run Levels 434 Common Problems with the at Command 401Editing inittab 435 Allowing and Preventing Access to the at Command Service 403 Using chkconfig 436Listing Services by Using chkconfig 436

26 Managing Network Connections 405

  IV I LINUX BASICSIntroducing the Shell 5 1 Entering Commands 19 2 Navigating the Linux File System 35 3 Using Text Editors 63 4 Printing Files 87 5 chapter 1 Introducing the Shell ■ Linux is distributed under the terms of the Free Software Foundation’s GeneralPublic License, or GPL. ■ Linux is distributed over the Internet, and is easy to download, upgrade, and share.■ Programmers all over the world create, distribute, and maintain programs for Linux, and much of this software is also distributed under the GPL.

6 Welcome to Linux

  To change a password, use thepasswdcommand, as follows: $ passwd(current> UNIX password:New UNIX password:Retype new UNIX password: passwd: all authentication tokens updated successfullyIf you are logged in as the root user, you can set the password for another accountpasswdby using followed by the username, like so:# passwd amy passwd /usr/binThe command, found under the directory, prompts for a new pass- word, and then asks you to type it again to verify the change. Through use of redirection, the outputcat of the command is sent to a specified file in the current directory.cat You can also combine the command and shell command-line redirection as a method to quickly create and enter text in a file.

3. To check your text, use the command:

  In order for you to be able to use a command in a pipe, the program must be able to read the standard input and write to the standard output. The shell will respond by printing a job number,followed by a process number of the program:$ sc &[1] 2689Running programs sent to the background with Ctrl+z will disappear, and the shell will print a job number like so:[2]+ Stopped sc Linux Basics PART I Entering Commands CHAPTER 2 Many programs or several instances of a single program can be started, suspended, bash jobsor run.

32 SEE ALSO ➤ For more information about using regular expressions with search programs such as grep , see page 58

  Printing the Current Working Directory pwdUse the (print working directory) command to print the current, or present, working directory (that is, the directory where you are at that moment):$ pwd/home/michael pwd /binA binary version of the command can be found under the directory, butpwd nearly all shells have a built-in command.pwd The built-in command is documented in each shell’s manual pages; or, from ahelp pwd bash command line, type . A hyphen, however, can be used as a quick navigation tool:$ pwd/home/michael$ cd /usr/local/bin$ cd -$ pwd/home/michael cdUse a hyphen with the command to quickly navigate between the two most recently visited directories (in the previous example, I navigated from my home /usr/local/bindirectory to the directory and then back to my home directory).

4 Display multiple files either by listing the names on the command line or by using a

  For example, the following command line uses to cre- ate three files:$ touch file1 file2 file3 ls -lUse to check the modification time of a file, like this:$ ls -l *.txt In the following lines, the command is used to update the file’s access and modification time to be four days more recent:$ touch friends.txt$ ls -l *.txt The command is useful to quickly create files, and can be used by other pro- grams during system-management tasks (such as backups). Searching the File System with KDE’s kfind Client kfindTo search for a particular file in the directory tree, you can use the client, either by selecting Find Files from the K menu, or from the command line:$ kfind & PART I Linux Basics CHAPTER 3 Navigating the Linux File System FIGURE 3.4 The various tabs in the kfind dialog box let you narrow down your search by many different criteria.

58 The resulting dialog box allows you to input the name of the file you are searching

  Redirect to multiple files.fgrep As illustrated by the following, the command does not recognize regular expressions:# fgrep ‘\(gp’ /etc/info-dir 60 PART I Searching Text Files CHAPTER 3 fgrepBecause the command does not recognize expressions other than simple wild-grep fgrepcards, no match is reported. Like the other commands, can use search patterns placed in a text file and used with the (file) option:# cat > search.txt gpm[EOT]# fgrep -f search.txt /etc/info-dir * gpm: (gpm). For example, the following command line reports on the copyright information of each /usr/binprogram under the directory:# find /usr/bin xargs strings -f fgrep Copyright less | | | Without the (report files) option, the command does not insert thefgrep searched file’s name in the output fed to the command.

66 Applixware for Linux can be found at

  Toemacsopen or create a text file, run on the command line, followed the by the name of a new or existing file, like this:$ emacs textfile emacsIf you’re using the X Window System, creates or opens your file and displaysemacsits main window as shown in Figure 4.4. Hold down the $ emacs emacsfrom the console or the command line of an X11 terminal window: Starting the emacs tutorial PART I Selecting an Editor CHAPTER 4 FIGURE 4.4 The emacs editor in the X Window System supports menus and the mouse.

2. Save the file, and then create a script file with the name . Enter a list

  (which could be a symbolic link to the filelinux.wordsunder the The default system dictionary,words Using Linux Dictionaries PART I Using Linux Dictionaries CHAPTER 4 sedcommand has replaced each word or phrase with the simpler replacement—almost like a grammar-checking program. Try using a com- bination of text filters and shell pipe operators to build your own, with a commandline like this:$ find *.txt xargs cat tr ‘ ‘ ‘\n’’ sort uniq >mydict.txt | | | |find This command line uses the command to pipe the names of all files in the cur-xargs xargsrent directory to the command.

2. If no misspelled words are found, returns you to the command line. If

  of Bushman nqu] pl : any of severallarge African antelopes (genera Connochaetes and XGorgon) with a head like that of an ox, short mane, long tail, and horns in both sexes that curvedownward and outward If you are using GNOME or KDE under the X Window System, you might have agdict kdict GUI tool ( or respectively) that allows you to type your word into a box and receive your answer in the text field at the bottom. When you use these macros in a text document, you must specify the macro set usedgroffon the command line, like so:$ groff -Tascii -mm mydocument.txt In the example above, the option tells to check for a macro named m and run the document through the m macro.groff Documentation for these macros is located in various -related manual pages.groff mm Table 4.4 lists some common macros from the manuscript macro set.

1. Use the command to typeset the file. This process can take up

  To print the document, click the File menu and select the Print Documentlpr -Poption, or use the command followed by the printer option, like this:$ lpr -Plp samples.ps TeXcan produce complex diagrams and documents, but it takes some effort on your TeX TeXpart to learn the system. TipIf the startup messages scroll by too quickly, wait for Linux to boot, log on, and then pipe the output of the dmesg command through the less pager: # dmesg less| Checking Your Printer There are many ways to ensure that a printer you created when you installed Linux is working.

1. Watch the startup messages while Linux is booting; look for a line specifying a

  lsPrint a directory listing by sending the output of the command directly to your printer, or the found device, with a command line similar to the following:# ls >/dev/lp1 88 PART I Adding Printers CHAPTER 5 Your printer should activate and print a list of the current directory. To print a text document, use the command along with the (printer) option to select a desired printer, like this:$ lpr -Pmylp mydocument 92 PART I Controlling Printers and Print Jobs CHAPTER 5 The printer name used with the option will be the name of a printer you’veprintcap defined in your file.# lpr -Pmylp /usr/share/ghostscript/3.33/examples/tiger.psLinux printing automatically recognizes and prints text and PostScript documents and graphics.

94 To stop a particular printer, specify the command followed by the printer’s name

  As root operator, you can also stop all the printlprmjobs for a particular user at a particular printer by using the command followed by the option (the printer’s name) and the user’s name, like this:# lprm -Pmylp bball mylp bballThis command line will stop all print jobs sent to the printer by the user . The shell requires the built-in command to define a variable:# setenv VARIABLE_NAME=value ksh exportDefining a variable using the shell requires its built-in command:# export VARIABLE_NAME=valueA more convenient way to set environment variables from the command line of anyenvshell is to use the command:# env VARIABLE_NAME=value Deleting an Environment Variable from the Command Line You cannot delete an environment variable in the current shell unless you know the proper shell command to use.

2. Change the definition line to be similar to the following:

PATH=$PATH:$HOME/bin:/usr/sbin Note that multiple entries are separated with a colon (:). ➤ To learn more about text editors for Linux, see Chapter 4, “Using Text Editors.”

3. To enable this change for all current or future users, make sure you’re logged in

  The promptbashdefinition uses special characters recognized by the shell, as shown here:PS1=”[\u@\h \W]\\$ “ \u \hIn this example, the is replaced by your username; the is replaced by your \Wmachine’s name; the is replaced with the name of the directory you are currently \\$ $ # in; and the is printed as a unless you are root, in which case it is a .[michael@brain stuff]$ .profile Copy this line to your , and then edit the string to define your own prompt. Print the history number of command\# Display the number of this command 106 PART II Customizing Your Login CHAPTER 6 nnn\s Print the name of the shell\t Print the time\u Print the current user’s name\w Character Definition ➤ To learn more about your computer’s hostname, see page 405.➤ To learn more about the X Window System, see page 169.➤ To learn how to use X11 terminals, see page 186.➤ To learn more about customizing your prompt, see the Bash Prompt HOWTO.

1. Using your favorite text editor, open the file in your home directory, and

  This alias uses the command’s output piped through theX11 xmessage client. The ampersand background operator (&) will run the pro- gram in the background automatically.

3. To use the alias right away without the need to log out and then log back

  Its native file system format is theext2fs ume, or hard drive, to make room for the kernel and software included with your ) because you created a partition on an existing vol- PART II Configuring Your System CHAPTER 7 Working with Hard Drives PART II Determining the Volume Device and Partition CHAPTER 7 Type Name vfat Windows file system xenix Xenix file system SEE ALSO For more information about the Linux kernel and loading modules, see page 535. To find out what file systems are currently supported by your kernel, use the /proccommand to see the contents of the file systems file under the directory, like this:# cat /proc/filesystems ext2ext2 msdosnodev proc vfatiso9660ext2 msdos vfat This example shows that the kernel is currently supporting the , , ,proc iso9660 , and file systems.

1. Log in as the root operator. Use the

  # sfdisk -s/dev/hda: 6342840 total: 6342840 blockssfdisk can also be used to make changes to the partition table of your hard drive.sfdisk Because of the command line nature of , this comes in useful for automated scripts (such as the installation scripts, for example) but isdangerous for manual use.fdisk A menu-driven partition, such as mentioned earlier, is a better choice for mak- ing changes to your hard drive by hand. In your command orfstabentry, replace the hard drive partition name with the hostname of the NFS server (or its IP address), a colon, and the path to the directory you want: # mount homeserver:/home/michael /mnt/home/michael homeserver This example mounts the directory on a server named as/mntumounton my local machine.

Dokumen baru