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

366 Part IV Administration

lpc restart: Attempts to start a new printer daemon. This is useful when an abnormal condition causes the daemon to die unexpectedly, thus leaving jobs in the queue. When this condition occurs, lpq reports that no daemon is present. If the user is the super-user, try to abort the current daemon first (for example, kill and restart a stuck daemon).

lpc status: Displays the status of daemons and queues on the local machine.

lpc stop: Stops a spooling daemon after the current job completes and disables printing.

lpc topg: Places the jobs in the order listed at the top of the printer queue.

lpq

To simplify printer queue administration, you can also use the lpq command. This command allows you to directly see what jobs are currently in a printer queue.

Entering the lpq command on its own provides information from a command prompt about the current printer queues. The lpq command normally displays information about who queued the print job, where it is in the queue, the files being printed, and the total size of the files. The -l option displays more information about each entry in the printer queue. Usually only one line of information is displayed.

You can specify a specific printer by using the lpq -P[printer name] command.

lprm

The line printer remove command, or lprm, removes print jobs from the printer queue. You need to know the print job ID to be able to remove its print jobs, but if you are logged in as root, you can remove all jobs for a printer by using the following command syntax:

lprm [-Pprinter_name] [-] [job_ID ...] [username ...]

You can also remove a particular printer’s jobs by using the -P option. The following command removes all print jobs queued on the printer hplj by the user who is issuing the command, or all print jobs for that printer if the command is issued by root:

lprm -Phplj -

Most versions of Linux come with their own print management tools, but it’s helpful to know the standard Unix way of setting up print spools and queues.

Using the vi Editor

4.16 Create, edit and save files using vi

Chapter 11 Linux System Commands 367

Linux administrators are constantly changing the configuration files of their system services and applications to enable new services or to make them run more efficiently. All configuration files in Unix are simple text files, but in order to edit them, you need a text editor. A wide variety of editors are available for Linux and Unix. Some of the most popular editors include Emacs and Pico. Although each person has his or her own favorite editor, only the vi editor comes by default with every version of Unix.

The vi editor is certainly not the easiest and most user-friendly text editor, but because of its wide availability and existence on most Unix systems, it is extremely important that every Linux system administrator know how to use it.

vi exists on every Unix and Unix-like system; therefore, it is very important to know how to use vi.

vi operation modes

The vi editor operates in two basic modes: Command mode and insert mode. When vi is started, it is in command mode. This mode allows you to enter commands to edit files or navigate your text file. However, you can only add or insert text by using the insert mode. From command mode, you can enter into insert mode by typing the letter i. To return to command mode, use the Escape key.

Command mode

In command mode, you can enter commands to edit your files or navigate the file that you are working on. Table 11-2 summarizes some of the more common commands while using command mode.

Table 11-2

vi commands

Navigation

Text Insertion

Searching

File Commands

 

 

 

 

l - Moves the cursor

i - Insert before cursor

fx - Find x on

<ESC> - Go

one position right

 

current line

to command

 

 

 

mode

 

 

 

 

h - Move the cursor

a - Insert after cursor

Fx - Find x on

:q - Quit

one position left

 

previous line

 

 

 

 

 

k - Move up one line

I - Insert at start of line

; - Repeat last fx

:q! - Quit and

 

 

 

don’t save

 

 

 

 

j - Move down one line

A - Insert at end of line

‘ - Repeat last Fx

:w - Write file

Continued

368 Part IV Administration

Table 11-2 (continued)

Navigation

Text Insertion

Searching

File Commands

 

 

 

 

w – Move forward

x - Delete current

/ - Search forward

:wq - Write and

one word

character

 

quit

 

 

 

b – Move backward

X - Delete to the left

? - Search backward :r - Insert file at

one word

 

 

current position

 

 

 

 

[ctrl-f] - Move forward

o - Open after current

n - Continue

:n – Go to

one page

line

forward search

another file

 

 

 

 

[ctrl-b] - Move backward

O - Open before

N - Continue

:! - Execute shell

one page

current line

backward search

command

 

 

 

 

[ctrl-d] - Move down

dd - Delete current line

“ - Back to start of

u - Undo last

one half page

 

search

change

 

 

 

 

[ctrl-u] - Move up one

cc - Change current line

 

. - Redo last

half page

 

 

change

 

 

 

 

G - Move to end of file

r - Replace current

 

U - Restore line

 

character

 

 

 

 

 

 

$ - Move to end of line

 

 

^| - Redraw the

 

 

 

screen

0 - Move to beginning of

line

[n]G - Go to line number “n”

Insert mode

In insert mode, you actually type text into the editor. You can type as many lines as you want; use Enter after you finish a line. You can correct mistakes by using the backspace key.

To perform any other command or function such as moving the cursor or saving the file, you need to hit the Escape key to bring you back into command mode.

Editing text files

To start the vi program, type the following at the command prompt:

vi [filename]

The filename can be a new or existing file. Remember that when you first start vi, you are initially in command mode. If you are working on a new file, you can immediately type the letter i to enter into insert mode and start adding text.

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