Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Linux+ Certification Bible.pdf
Скачиваний:
46
Добавлен:
15.03.2015
Размер:
3.78 Mб
Скачать

Chapter 11 Linux System Commands 369

If you are working on an existing file, you can use the cursor keys, or the h, j, k, l keys to navigate to where you want to begin. You can use the [ctrl-f] or [ctrl-b] to move ahead or back a page.

To insert text at an exact point, you can type the letter i for insert and start adding your text. Other options include the letter a, which adds text next to the cursor location, and the letter o, which starts your text on the next line below the current one.

If you make a mistake while typing, you can use the backspace key to delete characters. If you want to delete characters in command mode, hit the Escape key, and then use the letter x to delete characters one at a time. If you want to delete an entire line, use the dd command. The command dw deletes only the entire word that your cursor is currently on.

To save your file, hit the Escape key to enter command mode, and then type :w. To save and exit out of the vi editor, use the :wq command. Or you can use an equivalent to the :wq command — type the letters ZZ in command mode to save and then exit.

If you want to exit without saving your file, use the :q command. This command asks you if you want to save the file before quitting. If you want to bypass the prompt, use the :q! command.

Using the tar Command

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

The tar command 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, tar is a helpful archival tool that you can use to help manage your files.

The tar command does not compress files; it only combines them into one larger file. To compress files, you need to use the gzip or compress command.

The format of the tar command is:

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

You can use several options and arguments with the tar command:

-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

370 Part 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, to the 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 shutdown commands, plus the location and purpose 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 characteristics and print queue management commands. Finally, this chapter demonstrates 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

Chapter 11 Linux System Commands 371

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

372 Chapter 11 Study Guide

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 part of 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 it shuts 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 purpose of 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

Chapter 11 Study Guide 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 tar comand not perform?

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

374 Chapter 11 Study Guide

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

Chapter 11 Study Guide 375

16.Some users are complaining that the DHCP server is not running. After examing 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 tar argument 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!

Соседние файлы в предмете Операционные системы