|
| 以 PDF 格式下载本书 (736 KB)
Chapter 2 Logging In and Using Basic SunOS CommandsThis chapter describes the following topics. To enter commands, use a terminal or window. Use your desktop environment documentation if you need information on starting a terminal or window. Logging InA standard work session is the interval between the time you log in to the system and the time you log out. The SunOS multiuser environment requires that you identify yourself each time you want to use the system. Your login name (also known as a user name or an account) serves as your identity to the system and to other users on the system. Your password restricts use of your account to you. If you don't already have a login name and password, ask your system administrator to set up an account for you. After you have this information, you are ready to log in. Before you log in to the system, your screen should look similar to the following:
Type the login name given to you by the system administrator and press the Return key. For example, if your login name is spanky, type:
and press Return. Next, the system requests your password as follows:
Type your password at the prompt and press Return. If your account does not have a password assigned to it, the system logs you in without asking you for a password. Note that the system does not display (echo) your password on the screen as you type it. The failure to display your password helps to prevent others from discovering your password. Your Login ShellIn the chapters that follow, you enter SunOS commands. When you issue a command to the system, you are actually providing information to a command interpretation program, called a shell. The shell program then reads the information you have provided and causes the proper action to occur within the system. The default shell for SunOS system software is the Bourne shell. The Solaris operating environment also supports the following shells.
Each of these shells has its own unique differences. Note – You can get specific information about any SunOS command, including each of the available shells, by viewing its man (manual reference) page. For more information on man pages, see Displaying Manual Pages With man. When you initially log in to the system (or open a new terminal or window) and you see your command prompt, it indicates that a shell program has been started for you automatically. This shell is called your login shell. If your login shell is not the SunOS default (the Bourne shell), it is because a different shell has been specified for you by your system administrator. Some commands or procedures available when using one shell might not be available when using another shell. Unless stated otherwise, all commands and procedures described in this manual are available in the Bourne shell. Logging OutWhen you have finished your work session and are ready to exit the operating system, log out by typing the following:
After a moment, the system once again displays the login prompt:
When you see the login prompt, it indicates that you have successfully logged out. The system is now ready for you or another user to log in. Note – In the SunOS operating system, turning off your workstation or terminal does not necessarily log you out. Unless you log out explicitly, you might remain logged in to the system. Keyboard EquivalentsYou can often speed up operations by using a sequence of keystrokes, called keyboard accelerators, that duplicate the operations of the mouse and menus, and of the preconfigured keyboard keys. The following table lists several command operations and the keyboard equivalents for both SPARCTM and IA machines. Note – The Meta key is the <> key on SPARC keyboards and is obtained on IA keyboards by pressing Ctrl-Alt. To use a keyboard accelerator, press and hold the first key (Meta or Ctrl-Alt together) and type the second key. For example, to cut selected text, press and hold the Meta key and press X on a SPARC system. On an IA system, press and hold Ctrl and Alt together and press X simultaneously. Table 2–1 Keyboard Accelerators
Command PromptWhen you log in, the screen or window displays an initial prompt. The appearance of this prompt varies depending on the shell you are using and on how your system administrator originally set it up. Because the default command prompt for SunOS system software is the dollar sign ($), this prompt is used in most of the examples presented in this manual. If you decide later that you want to change your command prompt, see Changing Your Command Prompt for instructions. Typing CommandsWhen you see the command prompt, the system is waiting for you to type a command. Try typing the command date at the prompt, as shown in this example (type date and press the Return key):
This command displays the current date and time. When you type the same command, but capitalized, you receive the following message.
The Solaris operating environment interprets an uppercase D differently than a lowercase d, and the Date command fails. Most commands in the Solaris operating environment are lowercase. Correcting Typing MistakesThe commands you type are not sent to the system until you press Return. If you type a command incorrectly, but do not press Return, you can correct your mistake in the following ways.
Try both of these methods and see how they work. The Delete/Back Space key varies on some systems. Ctrl-U should work on most systems. Typing Multiple Commands and Long CommandsYou can type more than one command on a single line. Simply place a semicolon (;) between the commands, as shown here with the date command and the logname command:
This command entry displays the current date and time (from the date command) and the login name of the user currently logged in to the system (from the logname command). If you are typing a long command, you can use the backslash character (\) to continue typing on a second line. For example:
Although the date and logname commands are not long commands, they demonstrate the concept of continuing a set of commands on the next line. Later, when the commands you want to use are longer than the width of your screen, you will see how useful the backslash character can be. Note – If you use a desktop window, you might not need to use the backslash character to continue typing commands on the next line. When you reach the end of a line, the commands you type wrap to the next line automatically, and the system executes all commands when you press Return. Repeating Previous CommandsThe Korn, Bourne Again, C, TC, and Z shells enable your system to keep a history of commands you type and are able to repeat previous commands. Note – The Bourne shell (sh) does not support the history command. Repeating Commands in the Bourne Again, C, TC, or Z ShellIf you use the Bourne Again, C, TC, or Z shell, type !! and press Return to repeat the last command you typed.
You can also repeat any previously typed command by typing !x, where x is the desired command's corresponding number on the history list. To see the history list, type the history command and press Return. The following is an example of what you might see.
Note – The Z shell does not display the history command in the history list. Another method for repeating characters from the history list is to follow the ! with a negative number. For example, to repeat the second from the last command on the history list, type the following command.
Note – If you use this command repetition method immediately after the history command in the Z shell, increase the negative number after the ! by one (!-3). Using the previous example history list, the date command is repeated. You can also type the ! character, followed by the first few characters of a previous command to repeat that command. For example, if you had previously typed the clear command to clear your screen, you could type !cl to clear your screen again. With this method for repeating commands, however, you must use enough characters for the desired command to be unique in the history list. If you use only one letter after the !, the system repeats the most recent command that begins with that letter. Repeating Commands in the Korn ShellIf you use the Korn shell, type the following command to repeat the previous command.
You can also repeat any previously typed command by typing fc -s x, where x is the desired command's corresponding number on the history list. To see the history list, type the fc -l command and press Return. The following example is a sample history list.
You can also repeat commands from the history list by following the fc -s command with a negative number. For example, to repeat the second from the last command on the history list, type the following command.
Using the previous example history list, the date command repeats. You can also use the fc -s command with the first few characters of a previous command. For example, if you had previously typed the date command to display the current date, you could type fc -s da to display the date again. However, you must use enough characters for the desired command to be unique in the history list. If you use only one letter after the fc -s command, the system repeats the most recent command that begins with that letter. Adding Command OptionsMany commands have options that invoke special features of the command. For example, the date command has the option -u, which expresses the date in Greenwich Mean Time instead of local time:
Most options are expressed as a single character preceded by a dash (-). Not all commands have options. Some commands have more than one option. If you use more than one option for a command, you can either type the options separately (-a -b) or together (-ab). Redirecting and Piping Command OutputUnless you indicate otherwise, commands normally display their results on the screen. Some special symbols allow you to redirect the output of a command. For example, you might want to save the output to a file rather than display it on the screen. The following example illustrates the use of the redirect symbol (>).
In this example, the output from the date command is redirected to a new file called sample.file. You can display the contents of sample.file by typing the more command.
As you can see, the contents of sample.file now contain the output from the date command. See Chapter 3, Working With Files and Directories for information on the more command. Sometimes you might want to redirect the output of one command as input to another command. A set of commands strung together in this way is called a pipeline. The symbol for this type of redirection is a vertical bar (|) called a pipe. For example, instead of saving the output of a command to a file, you might want to direct it as input to the command for printing (lp) by using the pipe symbol (|). To send the output from the date command directly to the printer, type the following:
This pipeline would print the results of the date command. See Submitting Print Requests to the Default Printer for information on using the lp command to print files. The command redirection examples shown here are simple, but when you learn more advanced commands, you will find many uses for piping and redirection. Running Commands in the BackgroundWhen you type a command and press the Return key, your system runs the command, waits for the command to complete a task, and then prompts you for another command. However, some commands can take a long time to finish, and you might prefer to type other commands in the meantime. If you want to run additional commands while a previous command runs, you can run a command in the background. If you know you want to run a command in the background, type an ampersand (&) after the command as shown in the following example.
The number that follows is the process id. The command bigjob will now run in the background, and you can continue to type other commands. After the job completes, you will see a message similar to the following the next time you type another command, such as date in the following example.
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.
Using a PasswordTo ensure your system's security, the Solaris operating environment requires you use a password to access your system. Changing your password several times a year helps to ensure that you are the only user with easy access to your account. Note – If you believe someone has used your account without your permission, change your password immediately. When you choose a password, follow these guidelines.
Changing Your PasswordTo change your personal password, type the passwd command:
Password AgingIf your system uses password aging (implemented with options to the passwd command), your password can have either a maximum, or a maximum and minimum lifespan. The lifespan of your password is set by your system administrator. When your password reaches the maturity date, your system prompts you to change your password when you log in. The following message displays.
The system then automatically runs the passwd program and prompts you for a new password. If, for example, the minimum age of your password has been set for two weeks, and you try to change your password before the minimum life span has elapsed, the following message displays.
For more information on passwd(1) and password aging, refer to the man Pages(1): User Commands. Getting Help With OS CommandsThis section describes various online help features. These features enable you to view reference information from your workstation or terminal. Displaying Manual Pages With manIf you know the name of a command, but you are not sure what it does, the man command can be helpful. Type the following to find out more about this command:
This command displays the first part of a SunOS manual reference page in the window display area. Press the space bar to see the next screen, or press the Q key to quit and return to the command prompt. Use the man command to see all the available options and to show the proper command syntax. Manual reference pages often provide examples that illustrate various uses of the command. Displaying a One-line Summary With whatisIf you want just a one-line summary of the command's function, use the whatis command, as shown here:
The number in parentheses after the command name in the previous example indicates the Reference Manual section to which this command belongs. Commands are grouped into various categories according to function. Most user commands are in section 1. By common convention, the section number is displayed in parentheses after the name of the command. You can find the printed manual reference page for a command in alphabetical order within its group. Note – The whatis command is only available if your system administrator has set up a special database of command descriptions. Keyword Lookup With aproposIf you know what you want to do, but you do not know which command to use, use the apropos command to locate commands by keyword lookup. The apropos command lists all commands that have one-line summaries that contain any keywords you supply. The output of the apropos can be lengthy, as some keywords might appear in many places. Note – The apropos command is only available if your system administrator has set up a special database of command descriptions. To view examples of apropos output, type one or more of the following commands.
If you do type a keyword that generates an unreasonably lengthy display, press Ctrl-C to interrupt the display and return you to the command prompt. Hold down the Control key and press “c.” |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||