# ypmatch host-name hosts  : IP address for the system
# more /etc/netmasks  : the system part of a subnet
# uname -n : Host name
# cat /etc/nsswitch.conf
# ypwhich :  For NIS clients, type the following command to display the
server's host name
# nisping : For NIS+ clients, type the following command to display the
server's host name.
 
For NIS clients, type the following command to display the
server's IP address.
# ypmatch nameserver-name hosts
 For NIS+ clients, type the following command to display the
server's IP address.
# nismatch nameserver-name
To display the server's IP address, type the following command.
# getent hosts dns
# zpool status
# zfs list
 
 
If you plan to log off before a background job completes, use the nohup (no hangup)
command to enable the job to complete, as shown in the following example. If you do
not use the nohup command , the background job terminates when you log off.
$ nohup bigjob &
 
$ pgrep xterm
17818
17828
17758
18210
$ pkill -n 18210
If you need to forcibly terminate a process, use the -9 option to the pkill command.
$ pkill -9 -n xterm
 
Moving With Arrow Keys
If your machine is equipped with arrow keys, try these now. You should be able to
move the cursor freely about the screen by using combinations of the up, down, right,
and left arrow keys. Notice that you can only move the cursor across already existing
text or input spaces.
If you’re using vi from a remote terminal, the arrow keys might not work correctly.
The arrow key behavior depends on your terminal emulator. If the arrow keys don’t
work for you, you can use the following substitutes:
To move left, press h.
To move right, press l.
To move down, press j.
To move up, press k.
Moving One Word
Press w (“word”) to move the cursor to the right one word at a time.
Press b (“back”) to move the cursor to the left one word at a time.
Press W or B to move the cursor past the adjacent punctuation to the next or previous
blank space.
Press e (“end”) to move the cursor to the last character of the current word.
Moving to Start or End of Line
Press ^ to move the cursor to the start of the current line.
Press $ to move the cursor to the end of the current line.
Moving Down One Line
Press the Return key to move the cursor to the beginning of the next line down.
Moving Left
Press the Back Space key to move the cursor one character to the left.
Moving Right
Press the Space Bar to move the cursor one character to the right.
Moving to the Top
Press H (“high”) to move the cursor to the top of the screen.
Moving to the Middle
Press M (“middle”) to move the cursor to the middle of the screen.
Moving to the Bottom
Press L (“low”) to move the cursor to the bottom of the screen.
Page Forward One Screen
To scroll forward (move down) one screenful, press Ctrl-F. (Hold down the Control
key and press the F key.) The cursor moves to the upper left corner of the new screen.
Scroll Forward One-Half Screen
To scroll forward one half of a screen, press Ctrl-D.
Page Backward One Screen
To scroll backward (that is., move up) one screenful, press Ctrl-B.
Scroll Backward One-Half Screen
To scroll backward one half of a screen, press Ctrl-U.
Inserting Text
vi provides many commands for inserting text. This section introduces you to the
most useful of these commands. Note that each of these commands places vi in entry
mode. To use any of these commands, you must first be in command mode.
Remember to press Esc to make sure you are in command mode.
Append
Type a (append) to insert text to the right of the cursor. Experiment by moving the
cursor anywhere on a line and typing a, followed by the text you want to add. Press
Esc when you’re finished.
Type A to add text to the end of a line. To see how this command works, position the
cursor anywhere on a text line and type A. The cursor moves to the end of the line,
where you can type your additions. Press Esc when you are finished.
Insert
Insert text to the left of the cursor by typing i from command mode.
Type I to insert text at the beginning of a line. The command moves the cursor from
any position on that line. Press Esc to return to command mode after you type the
desired text.
OpenLine
Use these commands to open new lines, either above or below the current cursor
position.
Type o to open a line below the current cursor position. To experiment, type o followed
by a bit of text. You can type several lines of text if you like. Press Esc when you are
finished.
Type O to open a line above the current cursor position.
Changing Text
Changing text involves the substitution of one section of text for another. vi has
several ways to do this, depending on circumstances.
Changing a Word
To replace a word, position the cursor at the beginning of the word to be replaced.
Type cw, followed by the new word. To finish, press Esc.
To change part of a word, place the cursor on the word, to the right of the portion to be
saved. Type cw, type the correction, and press Esc.
Changing a Line
To replace a line, position the cursor anywhere on the line and type cc. The line
disappears, leaving a blank line for your new text (which can be of any length). Press
Esc to finish.
Substituting Character(s)
To substitute one or more characters for the character under the cursor, type s,
followed by the new text. Press Esc to return to command mode.
Replacing One Character
Use this command to replace the character highlighted by the cursor with another
character. Position the cursor over the character and type r, followed by just one
replacement character. After the substitution, vi automatically returns to command
mode (you do not need to press Esc).
Undoing Changes
When you edit text and make changes to a vi file, you might occasionally wish that
you had not changed something. vi’s undo commands enable you to back up one
operation and continue on from there.
Undoing the Previous Command
If you make a mistake in vi or if you just change your mind after an operation is
completed, you can undo your last command by pressing u immediately after the
command. You do not need to press Esc after you type u. By pressing u a second time
you undo the undo.
Undoing Changes to a Line
Type U to undo all changes you’ve made to a line. This command works only if you
haven’t moved the cursor off the line. You do not need to press Esc after you type U.
Deleting Text
These vi commands delete the character, word, or line you indicate. vi stays in
command mode, so any subsequent text insertions must be preceded by additional
commands to enter entry mode.
Deleting One Character
To delete one character, position the cursor over the character to be deleted and type x.
The x command also deletes the space the character occupied—when a letter is
removed from the middle of a word, the remaining letters will close up, leaving no
gap. You can also delete blank spaces in a line with the x command.
To delete one character before (to the left of) the cursor, type X (uppercase).
Deleting a Word or Part of a Word
To delete a word, position the cursor at the beginning of the word and type dw. The
word and the space it occupied are removed.
To delete part of a word, position the cursor on the word to the right of the part to be
saved. Type dw to delete the rest of the word.
Deleting a Line
To delete a line, position the cursor anywhere on the line and type dd. The line and the
space it occupied are removed.
Copying and Moving Text —Yank, Delete, and Put
Many word processors allow you to “copy and paste” and “cut and paste” lines of
text. The vi editor also includes these features. The vi command-mode equivalent of
“copy and paste” is yank and put. The equivalent of “cut and paste” is delete and put.
The methods for copying or moving small blocks of text in vi involves the use of a
combination of the yank, delete, and put commands.
Copying Lines
Copying a line requires two commands: yy or Y (“yank”) and either p (“put below”)
or P (“put above”). Note that Y does the same thing as yy.
To yank one line, follow these steps.
1. Position the cursor anywhere on the line you want to yank.
2. Type yy.
3. Move the cursor to the line above where you want to put (copy) the yanked line.
4. Type p.
A copy of the yanked line appears in a new line below the cursor.
To place the yanked line in a new line above the cursor, type P.
The yy command works well with a count: to yank 11 lines, for example, type 11yy.
Eleven lines, counting down from the cursor, are yanked, and vi indicates this with a
message at the bottom of the screen: 11 lines yanked.
You can also use the P or p commands immediately after any of the deletion
commands discussed earlier. This action puts the text you deleted above or below the
cursor, respectively.