Chapter 1 Basic Sunos Commands: 1.1.1 Correcting Typing Mistakes
Chapter 1 Basic Sunos Commands: 1.1.1 Correcting Typing Mistakes
This chapter provides an introduction to user commands in the SunOS operating system. It
describes how to enter commands, how to correct typing mistakes, how to enter long or multiple
commands, how to use command options, and other useful information about SunOS commands.
To enter commands, use a Command Tool or Shell Tool window. To display these windows,
select the Programs submenu on the Workspace menu.
If you decide later that you want to change your command prompt, see "10.1.4 Changing Your
Command Prompt"in Chapter 10, Customizing Your Working Environment for instructions.
$ date
Mon Feb 3 10:11:51 PST 1991
$
As you can see, this command displays the current date and time. Now try entering the same
command, but capitalized:
$ Date
Date: Command not found.
$
As you can see, an uppercase D is not the same as a lowercase d when interpreted by the system.
Nearly all commands in the SunOS operating system are lowercase.
Try both of these and see how they work. (The Delete/Backspace key varies on some systems.
Ctrl-U should work on most systems.)
$ date; logname
Mon Feb 3 10:19:15 PST 1991
spanky
$
As you can see, this 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 very long command, you can use the backslash character (\) to continue
typing on a second line. For example:
$ date; \
logname
Mon Feb 3 10:13:15 PST 1991
hankw
$
Even though the date and logname commands are by no means long commands, they are used
in this example to demonstrate the concept of continuing a set of commands on the next line in as
simple a manner as possible. Later, when the commands you want to use are longer than the
width of your screen, you'll see how using the backslash character can be extremely useful.
Note -
If you are using the Shell Tool or Command Tool windows in the OpenWindows environment,
you won`t 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're typing wrap to the next line
automatically, and the system executes all commands when you press Return.
Note -
The command repeating features described in this section are available only if you are using the
C shell.
A quick way to repeat the last command you typed is to type !! and press Return. The system
keeps a history of commands you type and is able to repeat previous commands. For example, if
the last command you entered was date:
example% !!
date
Mon Feb 3 10:16:10 PST 1991
example%
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:
example% history
1 pwd
1 clear
3 ls -l
4 cd /usr/home/worker
5 logname
6 date
7 history
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, you would
type the following:
example% !-1
logname
hankw
example%
Using the example history list above, the logname command is repeated.
Still another method is to follow the ! with the first few characters of a previous command. For
example, if you had previously entered 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 will repeat the most recent command beginning with that letter.
$ date -u
Mon Feb 3 11:06:51 GMT 1993
$
Most options are expressed as a single character preceded by a dash (-). Not all commands have
options. Some commands have more than one. If you use more than one option for a command,
you can either type the options separately (-a -b) or together (-ab).
In this example, the output from the date command is redirected to a new file called
sample.file. Next, the contents of sample.file are displayed with the more command:
$ more sample.file
Mon Feb 3 11:56:16 PST 1993
$
As you can see, the contents of sample.file now contains the output from the date command.
(See Chapter 3, Working with Files and Directoriesfor information on the more command.)
Sometimes you may want to redirect the output of one command as input to another command.
A set of commands strung together in this fashion 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 may 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, you would enter the following:
$ date | lp
$
This would print the results of the date command. (See "8.1.1 Submitting Print Requests to the
Default Printer"for information on using the lp command to print files.)
The command redirection examples shown here are quite simple, but when you learn more
advanced commands, you will find that there are many uses for piping and redirection.
If you know you want to run a command in the background, type an ampersand (&) after the
command as shown below. The number that follows is the process id:
$ bigjob &
[1] 11414
$
The command bigjob will now run in the background, and you can continue to enter other
commands. After the job completes, you will see a message similar to the following the next
time you enter another command, such as date in this example:
$ date
Mon Feb 3 10:13:15 PST 1991
[1] + Done bigjob
$
If you are likely to log off before a background job completes, use the nohup (no hangup)
command to allow the job to complete, as shown in this example. Otherwise, the background job
will be terminated when you log off:
$ nohup bigjob &
[1] 11414
$
Note -
The features described here are in addition to the OpenWindows help facilities.
$ man man
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 which illustrate various uses
of the command.
$ whatis date
date (1) -display or set the date
$
Notice the number in parentheses after the command name in the above example. This number
indicates the 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. If you look for
the printed manual reference page for a command, you will find it in alphabetical order within its
group.
For some examples of apropos output, try entering one or more of the following:
apropos who
apropos execute
apropos apropos
If you do enter a keyword that generates an unreasonably lengthy display, pressing Ctrl-C
interrupts the display and returns you to the command prompt. (Hold down the Control key and
press "c".)