P. 1
Linux Certification Bible

Linux Certification Bible

4.0

|Views: 2.327|Likes:
Publicado porMarcelo

More info:

Published by: Marcelo on Dec 18, 2008
Direitos Autorais:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

01/17/2013

pdf

text

original

4.12 Create, extract and edit file and tape archives using tar

The tarcommand is short for for tape archive. Originally, it was used for combining
a large number of files into a single file for archival to tape. Even if you don’t plan to
put files on tape, taris a helpful archival tool that you can use to help manage your
files.

The tarcommand does not compress files; it only combines them into one
larger file. To compress files, you need to use the gzipor compresscommand.

The format of the tarcommand is:

tar [options] (file1) (file2) ...

You can use several options and arguments with the tarcommand:

✦-c: Tells tar to create a new archive file

✦-v: Prints each filename as it is archived

✦-f: Specifies a filename for the archive

✦-x: Tells tar to extract files from an archive

164881-6 ch11.F 11/12/01 8:30 AM Page 369

370Part IV ✦Administration

To back up the entire /home directory to a file called homebackup.tar, use the
following command:

tar -cvf homebackup.tar /home

To extract the same file into the current directory, use the following command:

tar -xvf homebackup.tar

To back up three separate files, such as /etc/hosts, /etc/group, and /etc/passwd,
tothe archive etc.tar, use the following command:

cd /etc
tar -cvf etc.tar hosts group passwd

Know how to create and extract from a tar archive file.

Summary

This chapter details many system commands that are used routinely by the Linux
system administrator. This chapter introduces the concepts of runlevels and how
they interact with the init and shutdowncommands, plus the location and pur-
pose of startup scripts and how they can be used to stop and start services. This
chapter discusses the management of print queues, including lpd daemon charac-
teristics and print queue management commands. Finally, this chapter demon-
strates the use of the tar command to create and extract archives, and explains
some basic commands for the vi editor.

Here are some key points to remember from this chapter:

✦Runlevels

•0: Halt system

•1: Single User Mode

•2: Multiuser, no NFS

•3: Multiuser mode, no X

•4: Not used, user defined

•5: Multiuser mode with X

•6: Reboot

164881-6 ch11.F 11/12/01 8:30 AM Page 370

371

Chapter 11 ✦Linux System Commands

✦Startup scripts for each runlevel—Located in /etc/rc.d/

✦Service administration commands—Most scripts located in /etc/rc.d/init.d.
Options include start, restart, reload, stop

✦vi editor—Know the basic command to edit and save a text file

✦tar command—Used for making tape archive files, combines several files
into\one archive

tar -xvf [file]Used to extract files from archive

tar -cvf [file]Used to create an archive

✦Printing

•lpd—Line Printer Daemon

•lpq—Used to check queue status

164881-6 ch11.F 11/12/01 8:30 AM Page 371

STUDY GUIDE

The Study Guide section provides you with the opportunity to test your knowledge
about the objectives covered on the exam. The Assessment Questions provide an
understanding of the basics of Linux, and the Scenarios provide practice with real
situations. If you get any questions incorrect, use the answers to determine the
partof the chapter that you should review before continuing.

Assessment Questions

1.A Linux system seems to start up fine, but as soon as it is almost loaded
itshuts down again. What is the most likely cause of the problem?

A.The Ctrl-Alt-Delete is stuck

B.The default runlevel is set to 5

C.The default runlevel is set to 0

D.The kill command is corrupted

2.What command should be used to shut down the system and halt in
100 seconds?

A.shutdown -r now

B.shutdown -h 100

C.halt

D.init 0 –100

3.Your /etc/rc.d/rc3.d contains a script called S10network. What is the
purposeof this script?

A.To start the networking processes

B.To kill the networking processes

C.To reload the nfs daemon

D.To start the login process

4.What runlevel does init 5 represent?

A.Single User Mode

B.Halt system

C.Reboot

D.Full multiuser mode with X-windows

372Chapter 11 ✦Study Guide

164881-6 ch11.F 11/12/01 8:30 AM Page 372

373

5.What daemon controls the print spooling process?

A.lprm

B.lpd

C.lpq

D.lpstatus

6.What configuration file defines the default runlevel for the init process?

A./sbin/init

B./etc/rc.d/rc3.d

C./etc/inittab

D./etc/rc.d/init.d

7.What command should you use to save your file and quit the vi editor?

A.:wq

B.:w

C.:q!

D.save

8.What function can the tarcomand notperform?

A.Create an archive file

B.Extract files from an archive

C.Combine several files into one file

D.Compress files

9.Which command can you use to shut down and halt a Linux System?

A.reboot

B.halt

C.init 1

D.shutdown -r 300

10.What init level should you set to bring the system to single-user mode?

A.init 1

B.init 0

C.init 3

D.init 5

373

Chapter 11 ✦Study Guide

164881-6 ch11.F 11/12/01 8:30 AM Page 373

11.What command do you use to check the status of a print queue?

A.lp

B.lprm

C.lpq

D.lpstat

12.A user wants to restart the Web server because they want to enable changes
made in the configuration file. What command accomplishes this task?

A./etc/rc.d/init.d/httpd start

B./etc/rc.d/init.d/httpd reload

C.httpd reboot

D.init 3

13.What file contains information about specific printer configurations?

A./etc/printcap

B./etc/printers

C./etc/lpd

D./etc/printconf

14.What command can you use to reboot a Linux system?

A.init 5

B.restart

C.shutdown -h

D.reboot

15.What mode must you be in when using vi editor to input text into a file?

A.super mode

B.command mode

C.text mode

D.insert mode

374Chapter 11 ✦Study Guide

164881-6 ch11.F 11/12/01 8:30 AM Page 374

375

16.Some users are complaining that the DHCP server is not running. After exam-
ing the running processes on the system, you notice that the process is not
present. What command should you use to start the DHCP service?

A.dhcp restart

B.start dhcp

C./etc/rc.d/init.d/dhcpd start

D./etc/rc.d/init.d/dhcpd reload

17.What tarargument is used to extract files from an archive?

A.-x

B.-e

C.-f

D.-ext

18.What init runlevel should be set to shut down and reboot the system?

A.init 6

B.init 0

C.init 3

D.init 5

19.In what directory can you find the startup scripts for a system running in
runlevel 5?

A./etc/rc.d

B./etc/rc.d/rc5.d

C./etc/init.d/rc5.d

D./etc/rc5.d

20.In the vi editor, what command should you use to quit without saving a file?

A.:wq!

B.:wq

C.:!

D.:q!

375

Chapter 11 ✦Study Guide

164881-6 ch11.F 11/12/01 8:30 AM Page 375

Scenarios

1.Your users are having problems being able to resolve names on the network.
You suspect that the DNS server is not working, but when you check the run-
ning processes, it seems to be alive. What steps should you take to fix the
problem?

2.You have just installed a new Linux system on your server. Unfortunately, it
boots into X windows automatically, and you need the server to boot only to
the command line interface. What steps should you take to fix the problem?

Lab Exercises

Lab 11-1Runlevels and system shutdown

The objective for this hands-on lab is to gain experience in exploring different run-
levels and how to properly shutdown a Linux system. You should be able to use any
default Linux installation for this exercise.

1.Login as the root user on your system.

2.Enter the following command:

reboot

This should instantly reboot the system.

3.When the system comes back up, login as root again, and enter the following

command:

shutdown -r now.

The system should perform the same function as in Step 2 and reboot.

4.When the system comes back up, login as root again, and enter the following

command:

init 6.

The system should perform the same function as in Step 2 and reboot.

5.When the system comes back up, login as root again, and enter the key
sequence: Crtl-Alt-Delete.The system should perform the same function as in
Step 2 and reboot. Each of the last four commands (Steps 2-5) performed the
exact same function.

6.When the system comes back up, login as root again, and enter the following

command:

init 0

The system will shutdown and come to a halt without rebooting.

376Chapter 11 ✦Study Guide

164881-6 ch11.F 11/12/01 8:30 AM Page 376

377

7.When the system comes back up, login as root again, and enter the following

command:

halt

The system will shutdown and come to a halt without rebooting.

8.When the system comes back up, login as root again, and enter the following

command:

shutdown -h now

The system will shutdown and come to a halt without rebooting. The last
three commands (Steps 6-8) perform the same function.

Lab 11-2Using the vi editor

The objective for this lab is to open and edit a simple text file using the vi editor.

1.Start the vi editor and edit a blank file called, text.txt. Use the following
command:

vi text.txt

2.Enter the letter i to begin insert mode, and type the following sentence:

This is a test of the vi editor.

3.Hit Enter and then on the next line type the following sentence:

This is the second line of the test.

4.Hit Escape to enter command mode, and use the cursor keys to move the
cursor on top of the first letter of the word second. Type the letters dwto
delete the entire word.

5.Enter the letter ito begin insert mode again, and type the word second.
Afteryou finish, hit the Escape key to enter command mode.

6.Enter the letter oto begin inserting text on the next line.

7.Enter the following sentence:

This is the third line of the test.

8.Hit Escape and the :wqto save your file.

9.Enter the following command to see your edited file:

cat test.txt

377

Chapter 11 ✦Study Guide

164881-6 ch11.F 11/12/01 8:30 AM Page 377

Answers to Chapter Questions

Chapter Pre-test

1.The tarcommand, which stands for tape archive, archives several files into
one single file for easier storage on disk or tape.

2.Runlevel 0 indicates a halted system that is shutdown.

3.If you don’t shut down your Linux system properly with the shutdown or init
commands, you risk causing damage to your hard drive data because the file
systems aren’t properly unmounted before shutdown.

4.The process that runs the print spooler is lpd.

5.Startup scripts are located in /etc/rc.d or /etc/init.d.

6.“S” stands for a start script, which will start a process, and “K” stands for
killscript, which will kill a process.

7.To enter command mode in the vi editor, hit Escape.

8.The Graphical User Interface (GUI) will run in runlevel 5.

9.To print from the command line, use the lprcommand.

10.With the tar command, use tar -xvf [filename].

Assessment Questions

1.C. In the /etc/inittab file, the default runlevel is probably set to 0, which tells it
to shutdown right after the system has started. For review, see the “Linux
Runlevels” section.

2.B. The correct command is shutdown -h 100to perform this action. For
review, see the “Shutting down Linux” section.

3.A. This script is a startup script for the system’s networking processes. For
review, see the “Startup scripts” section.

4.D. Runlevel 5 is used to boot up a full multiuser system and to automatically
start X-windows. For review, see the “Linux Runlevels” section.

5.B. The Line Printing Daemon (lpd) controls the print spooling process, and is
started automatically at boot time. For review, see the “Printing management”
section.

6.C. The correct location is the /etc/inittab file. For review, see the “Linux
Runlevels” section.

7.A. The correct command is :wqused in command mode. For review, see the
“Using the vi Editor” section.

8.D. The tarcommand doesn’t compress data. To compress data, use the gzip
or compresscommand. For review, see the “Using the tarcommand” section.

378Chapter 11 ✦Study Guide

164881-6 ch11.F 11/12/01 8:30 AM Page 378

379

9.B. The haltcommand will shut down a Linux system without rebooting. For
review, see the “Shutting down Linux” section.

10.A. init 1will bring the system to single-user mode. For review, see the
“Linux Runlevels” section.

11.C. The correct command to check the printer queue status is lpq. For review,
see the “Printing management” section.

12.B. The reload command will tell the system to stop the service, reload the
configuration file, and restart the service. For review, see the “Managing Linux
Services” section.

13.A. The file that contains specific printer configuration information is
/etc/printcap. For review, see the “Printing management” section.

14.D. The command to reboot a Linux system is reboot. For review, see the
“Shutting down Linux” section.

15.D. To insert text in the vi editor, you must be in insert mode. For review, see
the “Using the vi Editor” section.

16.C. Because the service is currently not running, use the start command. For
review, see the “Managing Linux Services” section.

17.A. To extract files from an archive, use the -x argument in the tarcommand.
For review, see the “Using the tarcommand” section.

18.A. init runlevel 6 is used to shut down and reboot the system. For review, see
the “Linux Runlevels” section.

19.B. The correct location for the startup scripts for runlevel 5 is /etc/rc.d/rc5.d.
For review, see the “Linux Runlevels” section.

20.D. The correct command to quit without saving in the vi editor is :q! in the
command mode. For review, see the “Using the vi Editor” section.

Scenarios

1.Because the DNS process (named) is already running, it may be in a locked
state. Use the following commands to change into the startup script directory
for the process, and then restart the service.

cd /etc/rc.d/init.d
./named restart

If you encounter no other problems, such as with the configuration file, the
service should recover.

2.To change the default runlevel, edit the configuration file for init, which is
/etc/inittab.

Use the vi editor to edit the file using the following command:

vi /etc/inittab

379

Chapter 11 ✦Study Guide

164881-6 ch11.F 11/12/01 8:30 AM Page 379

Use the cursor keys to jump down to the line that reads:

id:5:initdefault:

Position the cursor over the number 5, and hit the x key to delete the charac-
ter. Press the letter i to enter insert mode, and type the number 3.

The new entry should look like the following:

id:3:initdefault:

Now enter command mode by pressing Escape, and then use the following
command to save the file:

:wq

Now reboot the system, and it should boot up into runlevel 3, without the
Xwindows.

380Chapter 11 ✦Study Guide

164881-6 ch11.F 11/12/01 8:30 AM Page 380

Maintaining the
Linux System

System maintenance is another common task for the
Linux administrator. Some of your specific duties that
are necessary in maintaining a Linux system include creating
and managing local storage devices and file systems, verifying
user and root cron jobs, and identifying core dumps.

This part covers these topics, but also details how to run and
interpret ifconfig; how to download and install patches and
updates; how to identify, execute, and kill processes; and
finally, how to monitor system log files. I also cover how to
perform and verify backups and restores, along with how to
perform and verify security best practices, how to set daemon
and process permissions, and how to properly document
work that is performed on a system. System maintenance is
not only good to know in the real world but also for the
Linux+ exam. Fourteen percent for the exam will focus of
System Maintenance.

✦ ✦ ✦ ✦

In This Part

Chapter 12

Linux Disk and
System Management

Chapter 13

Process Management

Chapter 14

Linux Security

Chapter 15

Backing Up Your
Linux System

✦ ✦ ✦ ✦

P

A

R

T

V

V

174881-6 PtO5.F 11/12/01 8:30 AM Page 381

174881-6 PtO5.F 11/12/01 8:30 AM Page 382

Linux Disk and
System
Management

EXAM OBJECTIVES

5.1 Create and manage local storage devices and file systems

(e.g., fsck, fdisk, mkfs)

5.2 Verify user and root cron jobs and understand the function

ofcron

5.3 Identify core dumps and remove or forward as appropriate

5.4 Run and interpret ifconfig

5.5 Download and install patches and updates

(e.g., packages, tgz)

12

12

CHAPTER

✦ ✦ ✦ ✦

184881-6 ch12.F 11/12/01 8:30 AM Page 383

384Part V ✦Maintaining the Linux System

CHAPTER PRE-TEST

1.What is the function of cron?

2.What kind of file has a tar.gz extension?

3.What kinds of information can the ifconfigcommand show you?

4.After creating a partition, what command do you use to make a file

system?

5.Why should core dumps be analyzed?

6.What is the purpose of a program patch?

7.How does the atfunction differ from cron?

8.How can the fsckcommand help fix disk errors?

9.What is the best time to perform system updates and upgrades?

10.What is the purpose of the fdiskcommand?

✦Answers to these questions can be found at the end of the chapter.✦

184881-6 ch12.F 11/12/01 8:30 AM Page 384

385

Chapter 12 ✦Linux Disk and System Management

The daily management activities of a Linux system administrator include many
different tasks. From managing and configuring disk drives, to managing net-
works, to scheduling maintenance jobs, many parts of the system must be attended
to on a routine basis.

For each of these system management activities, the administrator can use many
tools and commands to ease the administration and configuration of various parts
of the system.

This chapter deals with such system administration items as disk and file system
management, by using the fdisk, mkfs, and fsckcommands; system job schedul-
ing, by using atand cron; network management, by using the ifconfigcommand;
finding and analyzing core dumps; and finally, upgrading packages and installing
patches.

You're Reading a Free Preview

Descarregar
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->