0% found this document useful (0 votes)
54 views

Chapter 1 Basic Sunos Commands: 1.1.1 Correcting Typing Mistakes

This document provides an introduction and overview of basic commands in the SunOS operating system. It describes how to enter commands, correct typing mistakes, enter multiple or long commands, use command options, redirect command output, run commands in the background, and get help for commands using the man and whatis commands.

Uploaded by

Shakil Ahmed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Chapter 1 Basic Sunos Commands: 1.1.1 Correcting Typing Mistakes

This document provides an introduction and overview of basic commands in the SunOS operating system. It describes how to enter commands, correct typing mistakes, enter multiple or long commands, use command options, redirect command output, run commands in the background, and get help for commands using the man and whatis commands.

Uploaded by

Shakil Ahmed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Chapter 1 Basic SunOS Commands

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.

1.1 The Command Prompt


Once you've logged in, the screen or window will be empty except for an initial prompt. The
nature of this prompt will vary depending on the shell you are using and on how your system
administrator originally set it up. Since 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 "10.1.4 Changing Your
Command Prompt"in Chapter 10, Customizing Your Working Environment for instructions.

1.1 Entering Commands


When you see the command prompt, it means that the system is waiting for you to enter a
command. Try entering the command date at the prompt, as shown in this example (type date
and press the Return key):

$ 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.

1.1.1 Correcting Typing Mistakes


Suppose you started to type Date, but then realized your mistake before pressing the Return key.
The text you type is not sent to the system until you press Return. Therefore, it is still possible to
correct your mistake. You have two choices:

 Press the Delete or Backspace key to backspace to the error; or


 Type Ctrl-U to erase the entire line and start over. (Hold down the Control key and
press "u".)

Try both of these and see how they work. (The Delete/Backspace key varies on some systems.
Ctrl-U should work on most systems.)

1.1.1 Entering Multiple Commands and Long Commands


You can enter 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:

$ 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.

1.1.3 Repeating Previous Commands

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.

1.1.4 Adding Command Options


Many 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:

$ 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).

1.1.5 Redirecting and Piping Command Output


Unless you indicate otherwise, commands normally display their results on the screen. There are
special symbols that allow you to redirect the output of a command. For example, you may 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 (>):

$ date > sample.file


$

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.

1.1.6 Running Commands in the Background


Often, it is convenient to initiate a command from the command prompt and then place that
command in the background. When a command is not placed in the background, the next
prompt does not appear until the command completes its task. However, some commands can
take a long time to finish, and you might prefer to enter other commands in the meantime.

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
$

1.3 Getting Help with OS Commands


This section describes various on-line help features. These features allow you to view reference
information from your workstation or terminal.

Note -

The features described here are in addition to the OpenWindows help facilities.

1.3.1 Displaying Manual Pages with man


If 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:

$ 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.

1.3.1 Displaying a One-line Summary with whatis


If you want just a one-line summary of the command's function, use the whatis command, as
shown here:

$ 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.

1.3.3 Keyword Lookup with apropos


Suppose you know what you want to do, but you're not sure of the command to use. Then the
apropos command is helpful. This command locates commands by keyword lookup. The
apropos command lists all commands whose one-line summaries contain any keywords you
supply. This can lead to a very lengthy display, as some keywords may appear in many places.

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".)

You might also like