Sunteți pe pagina 1din 596

2

Relevance

Present the following question to stimulate the students and get them thinking about the
issues and topics presented in this module. While they are not expected to know the
answer to the question, the answer should be of interest to them and inspire them to learn
the content presented in this module.

Discussion Passwords are a major key to a secure system. What


characteristics would a good password have?

Additional Resources
Additional resources The following reference can provide additional
details on the topics discussed in this module:

2-2

Solaris Common Desktop Environment: Users Guide,


Starting a Desktop Session, Part Number 802-6485

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

User Accounts
You must have a user account on the system to log in. The user account
is defined in the /etc/passwd file and contains the elements which
identify each unique user to the system.
System administrators are responsible for creating and maintaining
user accounts.

The Root Account


The root account is the system administration account and is set up by
the installation process. The root login account owns all system files
and has access to all files.

Accessing Your System

2-3

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
User Accounts
The /etc/passwd Entry
Each entry in the /etc/passwd file is made up of seven fields
separated by a colon.
Placeholder UID

Comment

user2:x:102:10:JohnDelany:/home/user2:/bin/ksh
Login ID

Figure 2-1

GID

Login directory

Default shell

Example /etc/passwd Entry

Login ID Is the identification required by the operating system


for a successful login. It is the users public name. Depending on
the system administrator, login IDs are usually some combination
of a users first and last names. For example, user Bob Woods
login ID might be bobw, bwood, woodb, or bw2.
The login ID must:

2-4

Be limited to eight alphanumeric characters

Use lowercase characters only

Be unique

Placeholder Maintains the field for the password, which is kept in


the /etc/shadow file. The /etc/shadow file contains encrypted
passwords and password aging information (for example, how
long before a user must change a password and how long a
password must be in use before it can be changed). This file can
only be read by the system administrator.

UID Identifies the user to the operating system.

GID Identifies the primary group to which the user belongs.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
User Accounts
The /etc/passwd Entry

Comment Is usually the full name of the user.

Login directory Is commonly referred to as the home directory,


where users store their files.

Default shell Defines which shell the user will have upon login.

Accessing Your System

2-5

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Password Requirements
Your password protects your account from unauthorized access.
In the Solaris 7 computing environment, a password

Must be six to eight characters in length

Should contain at least two alphabetic characters and one numeric


or special character

Must differ from the login ID

Must differ from the previous password by at least three


characters

May contain spaces

These password requirements do not apply to the system


administrator (superuser).

2-6

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

The Mouse Buttons


The mouse settings can be modified to suit a users preferences. Once
a setting has been modified, that setting can be stored into a userspecific file. This means that any personalized settings will be the
default whenever a CDE session is initiated.

The Left Mouse Button


Most actions use the left mouse button, alternatively known as
button 1 or the SELECT button. This button is used to make selections
in any of the following ways:

Make a window active by clicking the left mouse button while the
mouse pointer is in that window area

Invoke a window menu by clicking on the left mouse button while


the mouse pointer is on the windows menu box area

Select an option from the Front Panel

Select a File or Folder icon while working with the File Manager

Accessing Your System

2-7

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
The Mouse Buttons
The Left Mouse Button

Open an icon by double-clicking the left mouse button while the


pointer is over the icon

Highlight text to be selected by dragging over the text area, while


the left mouse button is being pressed

The Middle Mouse Button


Button 2, also known as the ADJUST button, is used to paste selected
text. The text must have been selected using the left mouse button as
described previously.

The Right Mouse Button


When the right mouse button, or MENU button, is clicked or held
down, a menu of choices will appear. The options available on the
menu will be determined by the position of the mouse pointer when
button 3 was pressed.
Note For the purposes of this course, you will be instructed to left or
right click to perform a specific action. This assumes the standard
right-hand configuration of the buttons. These notes will instruct you
when a double-click is required.

2-8

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
Logging In
Logging in identifies you to the system. Before logging in to your
account, CDE displays the Login Manager.
The host name of your workstation

Menu of login options

You can log in using the login screen shown, or at the command line.

Accessing Your System

2-9

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Logging in
The Options Button
The Options button on the CDE login screen provides a set of choices.

These are
Language Main Language-set Language Sub-set
Session
Common Desktop Environment (CDE)
OpenWindows Desktop
Users Last Desktop
Failsafe Session
Remote Login
Command Line Login
Reset Login Screen

2-10

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
Logging in
The Options Button
If a user chooses to work with a different windowing environment, the
graphics display to the right of the login, and password entry boxes
will display a graphic appropriate to the chosen windowing
environment. The Failsafe session, where only the minimum services
are available, is used for troubleshooting.
As an alternative to the CDE login display, the user can choose to log
in from a conventional login prompt.
Note If the Command Line Login option is chosen, you must press
the Return key within 10 seconds of making this choice, otherwise the
CDE login screen will restart.
When the user successfully logs out from a command-line prompt, the
CDE login screen will be restarted.

Accessing Your System

2-11

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Logging in
Logging in Using the Login Screen
The CDE login screen replaces the usual login prompt.
You must enter your login name into the appropriate boxed area, then
press the Return key or left click on the OK button.
If you log in incorrectly, you must repeat the procedure of entering
your login name and password.
Note If you make a mistake when entering either your login name or
your password, you will be required to reenter both pieces of
information. Alternatively, you can left click on the Start Over button
to return to the login display. The Start Over button will completely
refresh the screen and remove any typed entry.

2-12

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Logging in
Logging in Using the Command Line
To log in at the command line, follow these steps:
1. Display the Options pull-down menu and select Command Line
Login.
2. Press Return to get a prompt for user name entry.
Note You need to press Return fairly quickly or the Login Manager
will restart.
3. Type your user name (login ID) at the prompt and press Return.

Assign user names and have the students log in to their systems.

4. Type your password at the password prompt and press Return.

Accessing Your System

2-13

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
Logging in
Logging in Using the Command Line
Note Your password does not appear as you type it. By default, if
you do not have a password, you are automatically prompted for one
during the initial login.

Exiting From the Command Line


To log out, at the prompt type:
$ exit
This will exit you from the system and display the CDE Login
Manager.

2-14

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Changing Your Password


Changing your password frequently helps prevent unauthorized
access to your system.
To change your password:
1. If you are logged into a CDE session, right click on the background
to bring up the Workspace Manager, click on Programs, and open
a terminal window. (On some systems, the Workspace Manager
will have a menu selection labelled Windows. If that is the case,
click on this instead of Programs to access a terminal window.)
2. Type the passwd command after the system prompt and press
Return.
3. When the prompt Enter login password: appears, type your
current password and press Return.
4. When the prompt New password appears, type your new
password and press Return.
5. When prompted, retype the new password and press Return. (This
is required for verification of the new password by the system.)
Accessing Your System

2-15

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
Changing Your Password
Example
$ passwd
passwd: Changing password for user2
Enter login password:
New password:
Re-enter new passwd:
$

If the users are unable to change their passwords due to cred table errors, use the
following command on the Network Information Service Plus (NIS+) server:
newkey -u username -s nisplus

This puts the user login password in the NIS+ cred table.

2-16

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

The CDE Workspaces


When you log in to a CDE session, four workspaces are available to
you by default. Each workspace is equivalent to a desktop
environment.

You can independently set the characteristics of each workspace and


add more workspaces (desktops).
Alternate among your workspaces by left clicking on the appropriate
workspace button or by using the keyboard metakey (diamond)
combined with the left or right arrow keys. In the illustration above,
workspace One is selected.
Note In some locations the function of the metakey differs. It may be
necessary to use the Alt key or space bar with the arrow keys to
perform the function described here.
Accessing Your System

2-17

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
Managing Windows
Overlapping Windows
When an icon is selected from the Front Panel, a window will open on
your workspace screen. Normally, windows on the workspace will
overlap each other, with the most recently opened window
overlapping previously opened windows.

2-18

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
Managing Windows
Lowering a Window
To choose the window menu, position the mouse pointer on the
window title area and press the right mouse button. One option in the
resulting menu is to lower the window. This option will force the
window to the back of the overlapping windows on your screen
display.
Window title area

The alternative keyboard action is to hold down the Alt key and press
function key 3 (Alt-F3).
Note There is no alternative to raising a window to the front of a set
of overlapping windows. When selected, a window automatically
comes to the front of any overlapping windows in a CDE display. The
Front key on the keyboard will also bring a window to the front of the
display.

Accessing Your System

2-19

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Managing Windows
Moving a Window
To move a window, you can do either of the following:

2-20

Choose the Move option from the window menu. The mouse
pointer will change from an arrow to a small cross. Drag the cross
pointer to move the window. As the cross moves, an outline of the
window will be displayed on your screen. When the outline is in
the desired position, click once with the left mouse button and the
window will move there.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
Managing Windows
Moving a Window

Place the mouse pointer over the windows title area, hold down
the left mouse button, and drag the window to its new screen
location.

When the window is being moved, a pair of numbers will be


displayed on your screen. These are the X and Y axis values which
show the new position of the window on your workspace display. The
number on the left (385) represents the horizontal (X) position. The
number on the right (231) represents the vertical (Y) position.
These numbers are useful to developers and programmers who want
to have a window appear in the same position every time an
application is invoked.

Accessing Your System

2-21

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
Managing Windows
Minimizing a Window
At the top right side of the window is a Minimize button. Clicking on
this button will convert the window into an icon.
Single left click

Double-click left button

The icon of a minimized window will be placed at the left edge of the
workspace display by default. However, it can be moved to any
desktop location by dragging the icon to the desired position.

2-22

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
Managing Windows
Minimizing a Window
Only one click of the left button is required to change a window to an
icon.
To change the icon back into a window, you must double-click on the
icon with the left button.
Clicking once on an icon will invoke the window menu. Selecting
Restore will then change the icon back into a window.

Accessing Your System

2-23

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
Managing Windows
Maximizing a Window
To make a window fill the entire workspace display, you must left
click on the box button at the top right side of the window.
To reduce the full-display window to its previous window size, select
the box button again. .

The box area represents the workspace display area

2-24

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
Managing Windows
Maximizing a Window
When the window is reduced to its previous size, it is placed in its
previous display position on the workspace.
Note When a window occupies all of the workspace display, no
other windows can be seen (as they are covered up). To switch to
another window, you must either lower the full-display window or
reduce it to its previous size.
You can use the F9 and F10 function keys with the Alt key, as keyboard
alternatives to using the mouse.

The Minimize and Maximize buttons are shown along with the
window menu equivalents in the above figure.

Accessing Your System

2-25

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
Managing Windows
Closing a Window
To close a window, double-click with the left mouse button in the
upper left corner of the window. A window can also be closed by
single clicking with the left mouse button in the upper left corner and
then selecting the Close option.

Double-click left button

Single left click

2-26

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
Managing Windows
Closing a Window
The keyboard alternative to close a window is Alt+F4.
Most applications will request that you confirm the closure of a
window that contains unsaved data.

Accessing Your System

2-27

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Leaving the CDE Session


Logging out prevents unauthorized users from gaining access to your
files.

Using the Exit Button


The Exit Button, on the Front Panel, is used to log out from your CDE
session.
By default, you will be asked to confirm that you want to log out.
Confirmation is done by clicking on the OK button or by pressing
Return when the OK button is highlighted.

2-28

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
Leaving the CDE Session
Using the Exit Button
The current CDE session will be saved automatically so that you can
return to the same workspace windows at your next CDE session.
However, any data contained in the current set of open windows will
be lost. You must therefore save all data before exiting from your CDE
session.
It is possible to change the default activities of the Exit button so that
confirmation is not required. This is discussed in a later module.

Single left click

Accessing Your System

2-29

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
Notes

2-30

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
Exercise: Accessing Your System
Exercise objective In this exercise, you will practice logging in on
the command line, changing your password, logging out, and other
basic CDE skills.

Tasks
Complete the following steps:
1. Obtain a user name and password from your instructor.
2. Log in to the system using the Command Line Login option.
3. Change the password to mypass1.
4. Log out of the system.
5. Log back in to the system using the Command Line Login option
and the new password, then log back out.
6. At the CDE login screen, enter the following (incorrect) details:
Login Name: nosuchuser
Password:
wrong
Observe the information displayed on the screen.
7. At the CDE login screen, enter your own (correct) details and log
in to a CDE session.
8. Using the correct mouse and Front Panel buttons, switch from the
default workspace display to Workspace Three. From Workspace
Three, switch back to Workspace One.
9. Click on the Text Note icon on the Front Panel to open a Text Note
window.
10. Once the Text Note window has been opened, convert the window
to an icon.
11. Convert the Text Note icon back to a Text Note window.

Accessing Your System

2-31

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
Exercise: Accessing Your System
Tasks
12. Move the Text Note window to another position on your
workspace display.
13. Make the Text Note window take up all of your workspace display
area.
14. Reduce the Text Note window back to its previous size.
15. Type some text into the Text Note window, then attempt to close
the window.
16. Confirm that you want to close the window without saving the
text.
17. Exit from your current CDE session.
18. Confirm that you want to log out.
19. Once you are back at the CDE Login Screen, log in again using
your allocated login name and password.

Workshop Labs
Use what you have learned so far in this course to work through the
following:
1. A new employee is given a Sun workstation to log in to. After
repeated attempts, the login fails. Why might this have happened?
2. A user would like to be able to do some command-line aliasing to
make issuing commands easier. What would the system
administrator have to have done to make this work every time the
user logs in?

2-32

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
Exercise: Accessing Your System
Exercise Summary
Discussion Take a few minutes to discuss what experiences, issues,
or discoveries you had during the lab exercises.

Manage the discussion here based on the time allowed for this module, which was given
in the About This Course module. If you find you do not have time to spend on
discussion, then just highlight the key concepts students should have learned from the
lab exercise.

Ask students what their overall experiences with this exercise have been. You might want
to go over any trouble spots or especially confusing areas at this time.

Conclusions

Have students articulate any conclusions they reached as a result of this exercise
experience.

Interpretations

Ask students to interpret what they observed during any aspects of this exercise.

Experiences

Applications

Explore with students how they might apply what they learned in this exercise to
situations at their workplace.

Accessing Your System

2-33

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
Exercise: Accessing Your System
Exercise Solutions
2. Log in to the system using the Command Line Login option.
Click on Option button on CDE Login screen. Click on Command Line
Login. Press Return and enter your login name at the prompt, followed
by the assigned password.
3. Change the password to mypass1.
$ passwd
old password:
new password:
re-enter new password:
4. Log out of the system.
$exit

2-34

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
Check Your Progress
Before continuing on to the next module, check that you are able to
accomplish or answer the following:

List the characteristics of an effective password

Change your password

Describe the function of a mouse button

Log in and log out of a system from the command line

Log in and out of a CDE session

Manipulate windows within the CDE

Invoke and use menus and menu bars

Accessing Your System

2-35

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

2
Think Beyond
On a UNIX system, it is not unusual for users to be forced to change
their passwords on a regular basis. What are some reasons for this?

2-36

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Features of the Common Desktop


Environment

Objectives
Upon completion of this module, you should be able to

Describe the arrangement of the Front Panel

Add workspaces to the Front Panel

Remove workspaces from the Front Panel

Rename workspaces

Minimize the Front Panel

Open the Front Panel window from the icon

Lock your workstation

Add an application to a Front Panel subpanel

Customize your workspace

3-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Relevance

Present the following question to stimulate the students and get them thinking about the
issues and topics presented in this module. While they are not expected to know the
answer to the question, the answer should be of interest to them and inspire them to learn
the content presented in this module.

Discussion What tasks do you complete most often? How do you


access the necessary tools?
Does your screen typically provide enough room for you to arrange
your open applications? How do you manage all the applications you
need running or open?

3-2

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
The Front Panel Arrangement
Applications Mail
Links
Cards
Files
subpanel
subpanel subpanel subpanel subpanel

Browser Calendar

Workspace
buttons

Personal
Printers
subpanel

Session Exit

Text Notes
File Manager Mailer

Tools
subpanel

Printer

Workspace
buttons

Display Lock

Hosts
Help
subpanel subpanel

Trash
subpanel

Perf Meter
Trash Can
Style Manager
Help

Features of the Common Desktop Environment

3-3

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

The Front Panel Arrangement


The Front Panel allows you to manage applications, files, and network
services easily. The Front Panel has been organized to include icons for
a web browser, text notes, and a performance meter. The subpanels
contain cascading submenus for ease of navigation. Click on an uparrow button to open a subpanel; click on an item in a subpanel to
run it.
The spinning globe above the Exit button indicates the system is busy.
When it is clicked on, it will prompt you for a uniform resource locator
(URL), pathname, host, email address, and so forth to open.

3-4

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Front Panel Menu Button


At the top left side of the Front Panel is the Front Panel window menu
button. If this is selected, a menu of choices is displayed.

Features of the Common Desktop Environment

3-5

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Front Panel Menu Button
From this menu, it is possible to perform the following actions:

Move the Front Panel to another location on screen. This can also
be done by dragging the Front Panel to a new position by one of
the move handles.

Minimize the Front Panel display.

Lower the Front Panel display behind overlapping windows.

Refresh the entire workspace display.

Log out from the CDE session.

Alternate ways of minimizing, restoring, and logging out are


discussed later in this module.

3-6

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Locking the Display
Lock
Button

Features of the Common Desktop Environment

3-7

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Locking the Display


Left clicking on the Display Lock button on the Front Panel locks the
screen. The backdrop will be blank, by default, and the Password
Prompt box will be displayed for only a short time.
To bring the password prompt back to the display, move the mouse or
press a key on the keyboard. Once the display has been locked, it can
only be unlocked by entering the correct password for the user who
locked the screen.
Note If a user locks the display and has forgotten the password, the
root user (superuser) can enter the root password to unlock the display.
The Style Manager, discussed later, enables you to allocate programs
to run on the screen while the display is locked.

3-8

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Workspace Buttons

Features of the Common Desktop Environment

3-9

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Workspace Buttons
As mentioned in Module 2, Accessing Your System, there are four
workspaces available when you start your first CDE session. You can
add a number of additional workspaces, each of which takes up the
whole display area of the screen.
If you click the right mouse button while the pointer is situated over
the workspace buttons area, you will be given a menu of options. One
of these options is to add a workspace. A limited menu will appear if
the pointer is positioned over the area between the workspace buttons,
instead of over the button itself.
When a new workspace is added, it will be given the name New.

3-10

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Workspace Buttons
You can change the name of a workspace by either of the following
two methods:

Choose the Workspace Buttons Menu option Rename.


or

Double-click on the workspace name in the central area of the


Front Panel display.

Be careful not to give the workspace a name which is too long to be


fully displayed. If the name is too wide for the display, only the leftmost characters will be displayed in the Front Panel display area.
Workspaces can be deleted from the Front Panel area by using the
Workspace Buttons menus Delete option.

Features of the Common Desktop Environment

3-11

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Minimizing the Front Panel

Double-click
to open
the Front
Panel

Single click
to minimize
the Front
Panel

Workspace name

3-12

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Minimizing the Front Panel


Minimize the Front Panel by clicking on the Minimize button at the
top right corner of the Front Panel window. The resulting icon will
show the name of the current workspace immediately below it. To
restore the Front Panel display, double-click on the Front Panel icon.
If the icon is hidden behind another window, you can either:

Lower the overlapping windows until you can see the Front Panel
icon
or

Keep pressing the Alt-Tab keys until the Front Panel icon is
brought to the front of the overlapping windows displayed on
your screen

Features of the Common Desktop Environment

3-13

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
The Workspace Menu

Note The Workspace Menu on your system may look different than
that pictured above.

3-14

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

The Workspace Menu


The Workspace menu provides easy mouse access to all your
applications, tools, and files through cascading submenus. Move the
pointer to the backdrop, then press the right mouse button to display
the Workspace menu; choose any submenu.

Features of the Common Desktop Environment

3-15

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Voice and Text Note Applications

3-16

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Voice and Text Note Applications


The Voice Notes application lets you personalize your mail messages.
Select Voice Note from the Applications subpanel to record voice
input. Note that selecting Voice Note starts up Audio in record mode.
A microphone or voice input device is necessary for this application to
work.
Text Notes lets you create Post-It style notes on your workspace.
Select Text Note from the Applications subpanel to record text input.
The note can then be minimized and left on your workspace as a
reminder. You can drag notes into mail messages as mail attachments.

Features of the Common Desktop Environment

3-17

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Address Manager

3-18

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Address Manager
Address Manager enables you to search corporate name databases and
organize your contacts in electronic cards. You can schedule
appointments, send email, and dial telephone numbers directly from
the electronic cards.

Features of the Common Desktop Environment

3-19

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Customizing Your Workspace With Style Manager

The Style Manager enables you to customize the following workspace


attributes:

3-20

Color Set the color attributes of the windows and the workspace
background

Font Set the size of the font display (in points)

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Customizing Your Workspace With Style Manager

Backdrop Set the workspace backdrop display

Keyboard Set key-click and key-repeat characteristics

Mouse Set mouse button positions, acceleration, and threshold


values

Beep Set the tone and duration of the beep

Screen Set screen blanking characteristics and lock background


programs

Window Set the behavior controls for windows and icons

Startup Set the logout and CDE session startup controls

Features of the Common Desktop Environment

3-21

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Style Manager Options
Color Control

The color controls enable you to select a color system for the backdrop,
window borders, window pane, and menu areas of the display. Each
will be set to a color based on the palette chosen from the list. Once a
palette is chosen, it can be modified to suit your needs by clicking on
Modify. Color changes will apply to all workspaces.

3-22

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Style Manager Options
Font

Changing the font size will alter the display character size of the next
and subsequent windows opened. The text size in the Help Viewer
documents are not affected by changing font size.
Different font sets can be added to the list of Font Groups by clicking
on the Add button. The Attributes button enables you to choose
alternate character sets.

Features of the Common Desktop Environment

3-23

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Style Manager Options
Backdrop

The Backdrop choice enables you to change the background for the
current workspace. Color choices you make will also affect the
backdrop appearance.
Each workspace can have a different backdrop applied to it.

3-24

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Style Manager Options
Keyboard

The Keyboard controls enable you to turn key repeating on or off.


If you want to have the keys make a sound when they are pressed,
you can adjust the click volume to be as loud as possible.
If the value is set to zero (0), the keyclick is effectively turned off.
If any changes have been made to the settings, selecting the Default
button will set the values back to those shown in the Style Manager
illustration (page 3-22).

Features of the Common Desktop Environment

3-25

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Style Manager Options
Mouse

Changing handedness of the mouse will reverse mouse buttons 1 and


3. Button 2 can be used to select text or objects (Adjust) or drag-anddrop objects (Transfer). If Adjust is selected, transfer actions (drag) will
require the use of mouse button 1.
The maximum time between clicks of a double-click can be adjusted.
Changes to this will become effective with a new login session.
Acceleration changes how fast the mouse pointer moves across the
display. Threshold determines the distance in pixels the pointer moves
at slow speed before moving at the accelerated rate.

3-26

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Style Manager Options
Beep

The volume of the beep noise can be set to a value between 0 and 100.
If set to 0, the beep noise will effectively be turned off.
Tone will determine the pitch of the beep, from 82 to 9000 Hertz.
The duration of the beep noise can be set to last up to 2.5 seconds.

Features of the Common Desktop Environment

3-27

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Style Manager Options
Screen

The Screen controls enable you to designate which screensaver


program will run when you lock your workstation display. You can
designate a number of screensavers to run, in succession, and have
each of them run for a period between 0 and 120 minutes.
You can also set the period of screen inactivity (in the above example,
15 minutes) at which the screensaver will automatically be invoked.

3-28

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Style Manager Options
Window

This control allows you to designate how windows and icons can be
manipulated.

Features of the Common Desktop Environment

3-29

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Style Manager Options
Startup

Setting the Home Session saves the current work session windows as
the default windows to open when the next Home session is started. If
you choose Set Home Session, this will override any previously saved
information. You can choose to either return to the session as it is
when you log out (Current session) or to your Home session when
you log back in.
Turning off the Logout Confirmation Dialog option means that you
will automatically be logged out when the Exit button is selected,
without any further confirmation being requested. If the Logout
Confirmation Dialog option is set to on, you will be asked to confirm
that you do want to log out when you choose to exit. When you start
your next work session, the data contained in any windows will either
be gone or be set to default values.

3-30

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Notes

Features of the Common Desktop Environment

3-31

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Customizing Subpanels

Application
Manager
Icon

3-32

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Customizing Subpanels
The subpanels or pull-up menus located on the Front Panel enable you
to add desired applications for easier access. It is easy to add and
delete new action buttons for launching your most frequently used
applications or scripts. You can add applications to the subpanel menu
list by dragging the appropriate icon from the Application Manager
window display and dropping it on the Install Icon area of the
subpanel. Many frequently used applications can be found by clicking
on the Applications icon on the Applications subpanel.
To manipulate an icon on a subpanel or delete it from the subpanel,
right click on the desired icon. This displays a menu of options relating
to the icon. Subpanels can be torn off and placed on the workspace
by using the same method you use to move a window.
You can place the most frequently used icons on your Front Panel
display by clicking on the Promote to Front Panel choice in the menu
of options. This will speed up access to the most commonly used
programs and help to reduce the need to open subpanel lists.

Features of the Common Desktop Environment

3-33

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Application Manager

3-34

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Application Manager
The Application Manager window contains six folders.
Open the Desktop folders to see icons which can be added to a
subpanel. This is achieved by dragging and dropping the desired icon
on the Install Icon area of the subpanel. Once the icon has been added
to the subpanel, that application can be invoked from the subpanel
itself.
Icons can also be added to the Front Panel by right clicking in a blank
area of the Front Panel and then clicking Add Icon.
Note An application icon can be placed on the workspace display in
the same way. The application is then available directly from the
workspace.
The System_Admin folder contains icons which are useful for system
administrators. The OpenWindows folder contains icons which can be
used to open OpenWindows programs while working in a CDE
environment.
Features of the Common Desktop Environment

3-35

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Exercise: Using the Front Panel
Exercise objective In this lab you will customize the Front Panel
using the skills you have learned in this module.

Tasks
Complete these steps:
1. Switch between each workspace by clicking on the appropriate
workspace button.
2. Lock your display so that only you can return to your CDE
session.
3. Invoke the Style Manager and undertake each of the following
tasks:

Increase the size of your font display

Change the backdrop of your current workspace

Change the backdrop of workspace Three

Turn on the keyboard click capability

Change your Startup controls so that you are not requested to


confirm when you log out

Set your Home Session to the current active windows

Set CDE to return to your Home Session

4. Log out from your CDE session, then log back in to see what has
changed.

3-36

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Exercise: Using the Front Panel
Tasks
5. Open the Application Manager from the Applications subpanel
and add the following two objects to the Applications subpanel.
(You will have to find the appropriate icons in the Application
Managers folders.)

Workshop Labs
Use what you have learned so far in this course to work through the
following:
1. Your desktops can be used to display different projects or
programs you work with every day.
a.

Customize your desktops so that their names reflect projects


or programs you work with.

b. Make each backdrop different and make any other


customizations that you prefer (for instance, whether a
window is active when clicked in or when the pointer is in the
window, font size, screen locking characteristics).
c.

Have all minimized icons be displayed in an icon box on the


desktop.

d. Once you have made your changes, log out in such a way that
you will return to your home session and log back in.
2. Add icons for the calculator and a terminal window to a subpanel.
Place the icon you would use the most in this subpanel on the
Front Panel for easier access.
3. Add the calculator icon to the Front Panel.
Features of the Common Desktop Environment

3-37

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Exercise: Using the Front Panel
Exercise Summary
Discussion Take a few minutes to discuss what experiences, issues,
or discoveries you had during the lab exercises.

Manage the discussion here based on the time allowed for this module, which was given
in the About This Course module. If you find you do not have time to spend on
discussion, then just highlight the key concepts students should have learned from the
lab exercise.

Ask students what their overall experiences with this exercise have been. You might want
to go over any trouble spots or especially confusing areas at this time.

3-38

Conclusions

Have students articulate any conclusions they reached as a result of this exercise
experience.

Interpretations

Ask students to interpret what they observed during any aspects of this exercise.

Experiences

Applications

Explore with students how they might apply what they learned in this exercise to
situations at their workplace.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Check Your Progress
Before continuing on to the next module, check that you are able to
accomplish or answer the following:

Describe the arrangement of the Front Panel

Add workspaces to the Front Panel

Remove workspaces from the Front Panel

Rename workspaces

Minimize the Front Panel

Open the Front Panel window from the icon

Lock your workstation

Add an application to a Front Panel subpanel

Customize your workspace

Features of the Common Desktop Environment

3-39

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

3
Think Beyond
What application would you put on your Front Panel? How would
you customize the different workspaces? What are some of the ways
you might customize the Front Panel for your work environment?

3-40

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Getting Help

Objectives
Upon completion of this module, you should be able to:

Describe how to obtain help from the Front Panel

Describe how to obtain application-specific help

Invoke the Help Viewer from the Front Panel

Invoke help from an application window

Display on-line manual pages, including different sections of the


manual

Search the on-line manual pages by keyword

In order for the man -k command to work, the MANPATH variable must be set to:
/usr/local/man:/usr/share/man:/usr/openwin/share/man:/usr/dt/man and the catman
utility must be run by root. Depending on the processor, running this utility may take up
to one hour and should be done before teaching this section.

4-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

4
Relevance

Present the following question to stimulate the students and get them thinking about the
issues and topics presented in this module. While they are not expected to know the
answer to the question, the answer should be of interest to them and inspire them to learn
the content presented in this module.

Discussion How do you typically get information about how to


complete computer tasks?
What types of information do you usually need?

4-2

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Front Panel Help


The Help Manager icon is situated at the right side of the Front Panel.
Clicking on the icon with the left mouse button will open up a Help
Viewer window.

Getting Help

4-3

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

4
Front Panel Help

Help Manager
subpanel

4-4

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

4
Help Viewer

The hypertext links, shown as underlined text or boxed graphics, can


be used to quickly move to a related help page by clicking on the
appropriate area of text in the Help window.
The Backtrack option allows you to retrace the path you followed
through the help screens.

Getting Help

4-5

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

4
Searching the Help Index
The Index Search enables you to see all volumes of help. These
volumes are displayed as hyperlinks, which can be used to reference
any help page. You can also search for specific help items based on a
keyword search.

4-6

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

AnswerBook2
If installed, an icon on the Help subpanel will enable you to access the
AnswerBook2 system.
The AnswerBook2 system enables you to view an on-line
representation of the printed manuals. As with the Help Viewer, there
are hyperlinks that can be used to skip to the relevant pages of the online manual.
By default AnswerBook2 uses the HotJava browser to display
information. You can perform searches of parts of the AnswerBook or
of the entire collection installed on your system.
Due to the amount of disk space which is taken up by the
AnswerBook2 pages, your system administrator may not have
installed AnswerBook2 on the computers hard disk. However, it is
possible to access AnswerBook2 files from a compact disc-read only
memory (CD-ROM) or hard disk device connected to a remote host on
your computer network.

Getting Help

4-7

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

4
AnswerBook2
If AnswerBook2 is accessible through your network, be aware that
there will be a delay between requesting and displaying AnswerBook2
pages. The speed with which the pages are collected from the remote
hard drive or CD-ROM device is dependent on network configuration
and activity.

4-8

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

On Item Help
The On Item Help icon is situated in the subpanel. When this function
is selected, the mouse pointer will change from an arrow pointer to a
question mark with an arrowhead at its base. The pointer can then be
positioned over a Front Panel icon to access the appropriate help page
for that item, which will be displayed in a Help Viewer window. The
mouse pointer will revert back to an arrow pointer at this time.

Getting Help

4-9

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

4
On Item Help
The On-Item Help function will only work on icons or within the
Application Manager windows.

The On Item
Help icon

Note The Information menu item accesses the Application Manager


Information README files.

4-10

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Other Ways to Access Help


Right clicking in any free space on the desktop will display the
Workspace menu. From the Workspace menu, you can select the Help
option from the Programs submenu.
This is another method for invoking the Help Viewer displayed by
clicking on the Front Panel Help icon. Once the Help Viewer has been
invoked, you can use it as described previously.

Getting Help

4-11

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

4
Other Ways to Access Help
Most windows also have a Help menu option specific to the current
application.
Help menu

4-12

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Displaying Man Pages


The UNIX Programmers Manual (also called man pages) describes
what you need to know about the systems on-line commands, system
calls, file formats, and system maintenance. The on-line man pages are
part of the Solaris computing environment.

Using the man Command


Use the man command to display on-line man pages for commands.

Command Format
man name
man -k keyword
man -s section name

Getting Help

4-13

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

4
Displaying Man Pages
Using the man Command Without Options
$ man cd
Reformatting page.

Wait... done

CD(1)

User Commands

CD(1)

NAME
cd, chdir, pushd, popd, dirs - change working directory
SYNOPSIS
/usr/bin/cd

[ directory ]

sh
cd

[ argument ]

chdir [ argument ]
DESCRIPTION
/usr/bin/cd
The cd utility will change the working directory of the
current shell execution environment. When invoked with no
operands, and the HOME environment variable is set to a
non-empty value, the directory named in the HOME environment
variable will become the new working directory.

<Output Omitted>
OPERANDS
The following operands are supported:
directory An absolute or relative pathname of the directory
that becomes the new working directory. The
interpretation of a relative pathname by cd
depends on the CDPATH environment variable.
SEE ALSO
csh(1), ksh(1), pwd(1), sh(1), chdir(2), attributes(5),
environ(5)
SunOS 5.7

4-14

Last change: 28 Mar 1995

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Displaying Man Pages


Scrolling in Man Pages
Use the following keys to control the scrolling capabilities while using
the man command:
Spacebar

Scroll through a manual page one screen at a


time

Return

Scroll through a manual page one line at a time

Move back one screen

Move forward one screen

Quit the man command

/string

Search forward for information

Find the next occurrence of string

Give a description of all scrolling capabilities

Getting Help

4-15

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Displaying Man Pages


Searching Man Pages by Section
There are multiple sections in the man pages. The SEE ALSO part at
the bottom of a man page lists alternate references that pertain to the
topic addressed. When these references are followed by a number
other than 1 in parentheses, it indicates a section of the man pages
which can be accessed using the -s option with the man command.
For example, executing $ man passwd will display information on the
passwd command and give instructions on how to change a password.
The SEE ALSO section of this man page reads in part as follows:
SEE ALSO
finger(1), login(1),
passwd(4)

nispasswd(1),

crypt(3C),

Executing $ man -s 4 passwd will display information on the


/etc/passwd file and $ man -s 3C crypt will display information
on password encryption.

4-16

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

4
Displaying Man Pages
Searching Man Pages by Keyword
If you are not sure of the command name, use the -k option to specify
a keyword as a subject.
an -k calendar
cm (1)
delete
insert
lookup
.cmsd
rade_cm

endar
ftime
ime

- calendar manager, appointment and


resource scheduling tool
cm_delete (1) - delete appointments from Calendar
Manager database
cm_insert (1) - insert appointments into Calendar
Manager database
cm_lookup (1) - look up appointments from Calendar
Manager database
rpc.cmsd (1)
- calendar manager service daemon
upgrade_cm (1) - script for upgrading Calendar Manager
from SVOL to Openwindows
cal (1)
- display a calendar
calendar (1)
- reminder service
difftime (3c) - computes the difference between two
calendar times
mktime (3c)
- converts a tm structure to a calendar
time

Note Using $ whatis command will display the header line from
the manual section. The man page itself can then be displayed with by
using the man command.

Getting Help

4-17

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

4
Exercise: Getting Help
Exercise objective In this lab you will practice using the help
functions available with CDE and the command-line man pages.

Tasks
Complete the following steps:
1. Open a Help Viewer window by clicking on the appropriate Front
Panel icon.
2. In the Help Viewer window, select Index and choose All Volumes.
3. Find information on how to play an audio file. After reading this
information, open the Audio player from the Workspace menu
and play the /usr/demo/SOUND/sounds/spacemusic.au audio
file.
4. Display the on-line manual (man) page for the ls command.
5. Display the on-line manual pages for the passwd command and
the passwd file.
6. Find the on-line manual page that describes how to clear the
terminal screen (use the keyword clear).
7. Display the Help subpanel and determine whether AnswerBook2
has been made available on your system.
8. If you do have AnswerBook2, invoke it from the subpanel and
look through the Solaris CDE Users Guide.
9. When you are finished, close the AnswerBook2 window.

4-18

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

4
Exercise: Getting Help
Workshop Labs
Use what you have learned so far in this course to work through the
following:
1. Using the Calendar Manager, add an appointment for lunchtime
on every Wednesday for the next month. Have the system send
you an email message 30 minutes before the appointment and
place a reminder on your desktop 10 minutes before the
appointment. Use any version of help you need to perform this
task.
2. What meaning would an ampersand & in the gcos field of a
password file entry carry for the system?

Getting Help

4-19

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

4
Exercise: Getting Help
Exercise Summary
Discussion Take a few minutes to discuss what experiences, issues,
or discoveries you had during the lab exercises.

Manage the discussion here based on the time allowed for this module, which was given
in the About This Course module. If you find you do not have time to spend on
discussion, then just highlight the key concepts students should have learned from the
lab exercise.

Ask students what their overall experiences with this exercise have been. You might want
to go over any trouble spots or especially confusing areas at this time.

4-20

Conclusions

Have students articulate any conclusions they reached as a result of this exercise
experience.

Interpretations

Ask students to interpret what they observed during any aspects of this exercise.

Experiences

Applications

Explore with students how they might apply what they learned in this exercise to
situations at their workplace.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

4
Exercise: Getting Help
Exercise Solutions
4. Display the on-line manual (man) page for the ls command.
man ls
5. Display the on-line manual pages for the passwd command and
the passwd file.
man passwd
man -s 4 passwd
6. Find the on-line manual page that describes how to clear the
terminal screen (use the keyword clear).
man -k clear

Getting Help

4-21

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

4
Check Your Progress
Before continuing on to the next module, check that you are able to
accomplish or answer the following:

4-22

Describe how to obtain help from the Front Panel

Describe how to obtain application-specific help

Invoke the Help Viewer from the Front Panel

Invoke help from an application window

Display on-line manual pages, including different sections of the


manual

Search the on-line manual pages by keyword

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

4
Think Beyond
Which type of help would you be most likely to use? Would this
change depend on what you needed help on?

Getting Help

4-23

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Accessing Files and Directories

Objectives
Upon completion of this module you should be able to:

Contrast absolute and relative pathnames

Access files and directories within the file structure using absolute
and relative pathnames

Identify and describe the parts of a command line

Access files and directories within the file structure using


pathname abbreviations

List the contents of directories and their file types

Identify various metacharacters

Enter more than one command on a single command line

Demonstrate the use of wildcard characters

5-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Relevance

Present the following question to stimulate the students and get them thinking about the
issues and topics presented in this module. While they are not expected to know the
answer to the question, the answer should be of interest to them and inspire them to learn
the content presented in this module.

Discussion How does the Solaris system know how to find files and
directories?

Additional Resources
Additional resources The following reference can provide additional
details on the topics discussed in this module:

5-2

Solaris Users Guide, Part Number 802-6499

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
File System Structure
Figure 5-1 shows a typical Solaris system file structure; you will refer
to this again later in this course.

home

user2

dir1

dir3

file1

practice

dante_1
dir2

beans

fruit

planets

fruit2

fruit

file2

flowers

recipes

trees

beans

file3

dir4

dante

coffees

file4

notes

nuts

mars

Figure 5-1

pluto

Solaris File System Structure

Accessing Files and Directories

5-3

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Pathnames
A pathname uniquely identifies a particular file or directory by
specifying its location. Pathnames are similar to a road map or a set of
directions that tells you how to get from one place in the directory
hierarchy to another.
Note Depending on the setup of your system, home directories can
be found in either /home or /export/home. For the purposes of this
discussion, /home is used.
The slashes within the pathnames are delimiters between object
names. A slash in the first position represents the / (root) directory.
For example:
/home/user2/dir1/coffees

root directory
Delimiters
Figure 5-2
5-4

Pathname With Delimiters

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Notes

The concept of pathnames is critical to the students understanding of how to access files
in the file structure. Pathnames identify every file in the file structure.

Briefly describe the Solaris file structure in terms of a hierarchy of directories,


subdirectories, and files. The file cabinet analogy works well with the Solaris computing
environment file structure. If the file cabinet analogy does not work for everyone, you
might draw a tree structure. Use root (/) and some directories to illustrate the root,
branches, limbs, and so on.

At some point it should be noted that this is not what the students file structure will look
like back at the office. In other words, the file names, and possibly the location of the
home directory, will be different in their work environment. The structure shown is an
example only.

If the classroom lab is set up in such a way that students home directories are under
/export/home, explain that when home directories reside on the local system they are put,
by convention, under /export/home. When home directories are provided by a home
directory server, by convention, they are found under /home.

Accessing Files and Directories

5-5

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Pathnames
There are two types of pathnames: absolute and relative.

Absolute Pathname
An absolute pathname specifies a file or directory in relation to the entire
Solaris file hierarchy. The hierarchy begins at the / (root) directory.
Absolute pathnames always:

5-6

Start at the root (/) directory and list each directory along the path
to the destination file (or directory)

Use a slash (/) between each directory name in the path to indicate
different directories

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Pathnames
Absolute Pathname
Refer to Figure 5-1 on page 5-3 for a visual representation of the
following pathnames:

Absolute pathname to user2


/home/user2

Absolute pathname to dir1


/home/user2/dir1

Absolute pathname to coffees


/home/user2/dir1/coffees

Accessing Files and Directories

5-7

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Pathnames
Relative Pathname
A relative pathname describes the location of a file or directory as it
relates to the current directory. If you are in a directory and you want
to move down the directory tree, it is not necessary to type the
absolute pathname. You can just type the path starting with the name
of the next directory in the directory structure. If a pathname does not
begin with a slash, it is a relative pathname.
Relative pathnames are useful because they are shorter than absolute
pathnames.

5-8

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Pathnames
Relative Pathname
Use Figure 5-1 on page 5-3 to support these examples:

The current directory


/home

Relative pathname to user2


user2

Relative pathname to dir1


user2/dir1

Relative pathname to coffees


user2/dir1/coffees

Accessing Files and Directories

5-9

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Command-Line Syntax
When using a terminal window, a shell prompt appears on the screen.
For the Bourne and Korn shells, the shell prompt for a user is a dollar
sign ($). For a C shell user, the prompt is a percent sign (%).
At the shell prompt, you can type commands. Commands are
instructions which tell the system to perform an action.
The general format for Solaris 7 commands is:
$ command [option(s)] [argument[s]]

5-10

command

Executable (specifies what you want the system to do)

options

Modify the executable (specifies how you want the


command run)

argument

File or directory, including the path name, or text. If a


pathname is not specified for a file or directory
argument, then the operating system will use the
current directory.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Command-Line Syntax

A space must be used as a delimiter between each part of the


command line.

Up to 256 characters can be entered on a single command line.

Many commands do not require all three parts.

Some examples are:


$
$
$
$
$

cal
cal 1987
date
date -u
banner "hi there"

Accessing Files and Directories

(Command
(Command
(Command
(Command
(Command

only)
and argument)
only)
and option)
and argument)

5-11

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Changing Directories Using the cd Command


Files you need to access are often stored in subdirectories below your
home directory. Because of the way in which a UNIX file system is set
up, it is often desirable to change directory locations.
Use the cd command to change to a new current directory. This
command, like all UNIX commands, accepts both absolute and relative
pathnames.

Command Format
cd [directory_name]

5-12

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Changing Directories Using the cd Command
Moving Around the Directory Hierarchy
You can use cd with:

An absolute pathname
$ cd /home

A relative pathname
$ cd user2/dir1

Use the cd command without a directory name to return to your home


directory.
$ cd

Accessing Files and Directories

5-13

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Displaying the Current Directory Using the pwd Command


Remembering which directory you are currently working in is often
difficult. Use the pwd (print working directory) command to display
the absolute pathname of your current directory.

Command Format
pwd

5-14

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Displaying the Current Directory Using the pwd Command
Determining Your Current Directory
$ pwd
/home/user2
$
$ cd /home
$ pwd
/home
$
$ cd
$ cd practice
$ pwd
/home/user2/practice
$

Directories always contain a link to their parent directory (..) and a link to themselves (.).

Accessing Files and Directories

5-15

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Displaying the Current Directory Using the pwd Command
Pathname abbreviations are a form of shorthand when moving
between or referring to directories.
Table 5-1

5-16

Pathname Abbreviations

Symbol

Meaning

Current (working) directory

..

Parent directory; the directory directly


above the current directory

Users home directory (Korn and C


shells)

~-

The full path to the previous working


directory (Korn shell only)

~logname

The home directory of the user


specified by logname

The symbol ~+ refers to the current working diretory ($PWD). It is used mostly when
writing scripts.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Displaying the Current Directory Using the pwd Command
Use pathname abbreviations with the cd command to move around
the file structure. For example:
$ pwd
/home/user2/dir1
$ cd ..
$ pwd
/home/user2
$
$
/

cd ../..
pwd

$ cd ~/practice
$ pwd
/home/user2/practice
$
$
/

cd ~pwd

$ cd ~guest
$ pwd
/home/guest

Accessing Files and Directories

5-17

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Using the ls Command


To determine the contents of a directory, use the ls command. This
command will display a listing of all files and directories within
specified directories. If no pathname is given as an argument, ls will
display the contents of the current directory.

Command Format
ls [-option(s)] [pathname[s]]

5-18

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Using the ls Command
Listing the Contents of a Directory
$ cd
$ pwd
/home/user2
$
$ ls
dante
dante_1
$

dir1
dir2

dir3
dir4

file1
file2

file3 practice
file4

user4

user5

$ ls dir1
coffees fruit trees
$
$ ls /var/mail
user1
user2 user3
$

Have the students try using absolute and relative pathnames.

Displaying Hidden Files


File names that begin with a dot (.) are called hidden files. Hidden files
are frequently used to customize a users work environment. They are
not shown by default because they are infrequently edited.
Use ls -a to list all files in a directory, including hidden (.) files.

Using ls to Display Hidden Files


$ pwd
/home/user2
$ ls -a
.
.kshrc
..
dante
$

dante1 dir2
dir1
dir3

Accessing Files and Directories

dir4
file1

file2 file4
file3 practice

5-19

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Using the ls Command
Displaying File Types
Use ls -F to display file types. The various file types are displayed
using the following symbols:
Table 5-2

File Type Symbols

File Type

Symbol

Directory

Executable

Plain text file/ASCII

(none)

Symbolic link

Showing File Type


$ pwd
/home/user2
$
$ ls -F
dante dir1/ dir3/
dante_1 dir2/ dir4/
$
$ ls -F /etc
cron@ asppp.cf*
<output omitted>
$

5-20

file1
file2

file3
file4

practice/

shadow uucp/

Links will be discussed more fully later in the course. If necessary, introduce symbolic
links here by explaining that they are a way to give an alternate name to a file. Further
discussion of both hard and symbolic links, along with how to create them, is contained in
Module 14, File and User Information Utilities."

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Using the ls Command
Displaying a Long Listing
To see detailed information about the contents of a directory use the
ls -l command.

Getting Detailed Information Using the ls Command


$ ls -l
total 8
-rw-r--r--rw-r--r-drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
-rw-r--r-$

1
1
5
4
3
3
1

user2
user2
user2
user2
user2
user2
user2

staff
staff
staff
staff
staff
staff
staff

320Dec
368Dec
512Dec
512Dec
512Dec
512Dec
0Dec

7
7
4
4
4
4
2

11:43
11:45
13:43
13:36
13:44
13:44
09:05

dante
dante_1
dir1
dir2
dir3
dir4
file1

total 8 indicates the number of 512-byte blocks used at this level of the directory
structure.

This command provides the following file information:


File type ( for regular file or d for directory, for example)
Permissions
Links
Owner
Group
Size
Last modification date and time
File name

drwxr-xr-x
-rw-r--r--

5 user2
1 user2

staff 512
staff
0

Dec 4 13:43
Dec 2 09:05

dir1
file1

Note Using ls -t will list files with the most recently modified at
the top of the list.
Accessing Files and Directories

5-21

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Using the ls Command
Listing Individual Directories
Use ls -ld to display detailed information about a directory, but not
its contents. This is useful when you want to see the permissions on a
directory and not the information about its contents. (Permissions are
discussed in detail in Module 8.)

Obtaining Detailed Directory Information


$ cd
$ ls -l dir1
total 6
drwxr-xr-x 2 user2
drwxr-xr-x 2 user2
drwxr-xr-x 2 user2
$ ls -ld dir1
drwxr-xr-x 5 user2
$

other 512 Dec 9 11:10 coffees


other 512 Dec 9 11:10 fruit
other 512 Dec 9 11:10 trees
other 512 Dec 4 13:43 dir1

Use ls -R to display the contents of a directory and all of its


subdirectories.

Displaying a Recursive Listing


$ pwd
/home/user2
$ ls -R dir1
coffees fruit

trees

dir1/coffees:
beans
nuts
dir1/fruit:
dir1/trees:
Note The R (or sometimes r) option is commonly used with many
UNIX commands to indicate a recursive action. Recursive generally
refers to the contents of a directory and all of its subdirectories.

5-22

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Metacharacters
Metacharacters are keyboard characters with special meaning to the
shell. They are a powerful feature of any shell. A general definition of
a metacharacter is any keyboard character that is not alphanumeric;
for example:
; $ % ! ~ * ? [] < > |
It is very important not to use metacharacters when naming files and
directories. The dot (.) and underscore (_) are the only two nonalphanumeric characters that are not metacharacters. This is why you
can use the dot (.) and the underscore (_) in file names. A hyphen (-),
even though it is a metacharacter (used to delineate options in a
command line), can also be used in file names.

Accessing Files and Directories

5-23

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Metacharacters
Asterisk
The asterisk (*) represents zero or more characters, except the leading
dot on a hidden file. The asterisk is often referred to as a wildcard
character.

5-24

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Metacharacters
Asterisk
Examples
$ ls
dante
dante_1
$ ls d*
dante
dir1:
coffees
dir2:
beans
dir3:
planets
dir4:
flowers

dir1
dir2

dir3
dir4

file1
file2

file3
file4

fruit
fruit2

practice

dante_1
fruit

trees

notes

recipes

Accessing Files and Directories

5-25

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Metacharacters
Question Mark
The question mark (?) matches any single character, except for the
leading dot on a hidden file.

5-26

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Metacharacters
Question Mark
Examples
$ ls
dante
dante_1

dir1
dir2

dir3
dir4

file1
file2

file3
file4

fruit
fruit2

practice

$ ls dir?
dir1:
coffees

fruit

trees

dir2:
beans

notes

recipes

dir3:
planets
dir4:
flowers
$
The following example illustrates the message you will receive if no
file name matches the wildcard character:
$ ls z?
z?: No such file or directory
$

Accessing Files and Directories

5-27

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Metacharacters
Square Brackets
Use square brackets ([ ]) to match a set or range of characters for a
single character position. The characters inside the brackets do not
generally need to be in any order; for example, [abc] is the same as
[cab]. However, if you are looking for a range of characters, they
must be in proper order (for example, [az] or [39]). If you want to
search for all alphabetic characters, whether lowercase or uppercase,
use [Az] for the pattern to match. You can use alphabetic or numeric
characters for the search pattern.

5-28

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Metacharacters
Square Brackets
Examples
$ ls [b-f]*
dante
dir1
dante_1
dir2
$
$ ls [af]*

file1

file2

dir3
dir4

file3

file1
file2

file4

file3
file4

fruit

fruit
fruit2

practice

fruit2

Accessing Files and Directories

5-29

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Metacharacters
Semicolon
The semicolon (;) enables you to enter multiple commands on a single
command line. The semicolon is also referred to as the command
separator.

Command Format
command;command

5-30

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Metacharacters
Semicolon
Using the Semicolon
$ cd;ls
dante
dante_1
$

dir1
dir2

dir3
dir4

file1
file2

file3
file4

fruit
fruit2

practice

$ date;cal;pwd
Sun Jul 18 11:05:39 MDT 1999
July 1999
S M Tu W Th F S
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
/home/user2
$

Accessing Files and Directories

5-31

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
File System Structure
/

home

user2

dir1

dir3

file1

practice

dante_1
dir2

beans

fruit

fruit

file2

flowers

notes

nuts

mars

Figure 5-3

5-32

planets

fruit2

recipes

trees

beans

file3

dir4

dante

coffees

file4

pluto

Solaris File System Structure

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Exercise: Accessing Files and Directories
Exercise objective In this lab you will use the commands discussed
in this module to change directories and list directories.

Tasks
Use Figure 5-3 on page 5-32 to identify the pathnames for the
following objects:
1. Specify the absolute pathnames for:

user2_____________________________________________

coffees_______________________________________________

dir4__________________________________________________

Assume /home/user2 is the current directory for the next two


questions.
2. Specify the relative pathnames for:

dir3___________________________________

flowers___________________________________________

recipes___________________________________________

3. Specify the relative pathnames for the dir1 subdirectories and


files.
__________________________________________________
__________________________________________________
__________________________________________________
__________________________________________________
__________________________________________________

Accessing Files and Directories

5-33

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Exercise: Accessing Files and Directories
Tasks
Using Figure 5-3 on page 5-32 as reference, perform each of the
following tasks on your system. Use pathname abbreviations
whenever possible.
4. Change to the your home directory.
5. Change to the dir1 directory.
6. Change to the fruit directory.
7. Change to the planets directory.
8. Change to the your home directory.
9. Change to the /etc directory.
10. Change to the recipes directory.
11. Change to the flowers directory.
Use the ls and cd commands to complete the following steps. Refer to
Figure 5-2 on page 5-4 for the first six steps as needed.
12. Return to your home directory.
13. Change to the dir1 directory.
14. List the contents of the dir1 directory.

5-34

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Exercise: Accessing Files and Directories
Tasks
15. Display a recursive listing of the contents of the dir2 directory.
16. Use the ls command to display a detailed listing of your home
directory, including hidden files.
17. Use the ls option that will recursively display all subdirectories in
your home directory.
Is there a directory in the root directory (/) called kernel?
_________
Is there a directory in /var/spool called cron?
18. Without changing directories, type the ls command that will
display all file names that end with the number 1 in your home
directory.
19. On one command line, change to your home directory and list the
contents of the directory.
20. Issue an ls command that will display file and directory names of
any length beginning with the letters d or f.
21. Issue an ls command that will display all files starting with file
followed by any one character.

Accessing Files and Directories

5-35

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Exercise: Accessing Files and Directories
Workshop Labs
Use what you have learned so far in this course to work through the
following:
1. The system administrator has created a common project directory
called Projects. This directory is a subdirectory to the root
directory. You would like to display a listing of the files in this
directory and see when they were last accessed. The default display
would be for when each file was last modified. How can you get
the desired display?
2. User commands generally reside in the /usr/bin directory. A few
days ago the system administrator showed you how to display a
calendar and you remember that the command started with a c.
You need to use this command again to find out what day of the
week the first of January 2000 falls on. Using the skills you have
learned, find the information you require.

5-36

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Exercise: Accessing Files and Directories
Exercise Summary
Discussion Take a few minutes to discuss what experiences, issues,
or discoveries you had during the lab exercises.

Manage the discussion here based on the time allowed for this module, which was given
in the About This Course module. If you find you do not have time to spend on
discussion, then just highlight the key concepts students should have learned from the
lab exercise.

Ask students what their overall experiences with this exercise have been. You might want
to go over any trouble spots or especially confusing areas at this time.

Conclusions

Have students articulate any conclusions they reached as a result of this exercise
experience.

Interpretations

Ask students to interpret what they observed during any aspects of this exercise.

Experiences

Applications

Explore with students how they might apply what they learned in this exercise to
situations at their workplace.

Accessing Files and Directories

5-37

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Exercise: Accessing Files and Directories
Exercise Solutions
Use Figure 5-3 on page 5-32 to identify the pathnames for the
following objects:
1. Specify the absolute pathnames for:

user2
/home/user2

coffees
/home/user2/dir1/coffees

dir4
/home/user2/dir4

Assume /home/user2 is the current directory for the next two


questions.
2. Specify the relative pathnames for:

dir3
dir3

flowers
dir4/flowers

recipes
dir2/recipes

3. Specify the relative pathnames for the dir1 subdirectories and


files.
dir1/coffees; dir1/coffees/nuts; dir1/coffees/beans
dir1/fruit; dir1/trees

5-38

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Exercise: Accessing Files and Directories
Exercise Solutions
Using Figure 5-3 on page 5-32 as reference, perform each of the
following tasks on your system. Use pathname abbreviations
whenever possible.
4. Change to your home directory (~).
cd or cd ~
5. Change to the dir1 directory.
cd dir1
6. Change to the fruit directory.
cd fruit or cd ~/dir1/fruit
7. Change to the planets directory.
cd ~/dir3/planets or cd ../../dir3/planets
8. Go back to your home directory (~).
cd or cd ~
9. Change to the /etc directory.
cd /etc
10. Change to the recipes directory.
cd ~/dir2/recipes or cd /home/user2/dir2/recipes
11. Change to the flowers directory.
cd ../../dir4/flowers or cd ~/dir4/flowers

Accessing Files and Directories

5-39

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Exercise: Accessing Files and Directories
Exercise Solutions
Use the ls and cd commands to complete the following steps. Refer to
Figure 5-3 on page 5-32 for the first six steps as needed.
12. Return to your home directory.
cd or cd ~
13. Change to the dir1 directory.
cd dir1
14. List the contents of the dir1 directory.
ls
15. Display a recursive listing of the contents of the dir2 directory.
ls -R ../dir2 or ls -R ~/dir2
16. Use the ls command to display a detailed listing of your home
directory, including hidden files.
ls -la ~
17. Use the ls option that will recursively display all subdirectories in
your home directory.
ls -R ~
Is there a directory in the root directory (/) called kernel?
Yes; ls -F / or ls -ld /kernel
Is there a directory in /var/spool called cron?
Yes; ls -F /var/spool
18. Without changing directories, type the ls command that will
display any file names that end with the number 1 in your home
directory.
ls ~/*1

5-40

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Exercise: Accessing Files and Directories
Exercise Solutions (Continued)
19. On one command line, change to your home directory and list the
contents of the directory.
cd;ls
20. Issue an ls command that will display file and directory names of
any length beginning with the letters d or f.
ls [df]*
21. Issue an ls command that will display all files starting with file
followed by any one character.
ls file?

Accessing Files and Directories

5-41

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Check Your Progress
Before continuing on to the next module, check that you are able to
accomplish or answer the following:

5-42

Contrast absolute and relative pathnames

Access files and directories within the file structure using absolute
and relative pathnames

Identify and describe the parts of a command line

Access files and directories within the file structure using


pathname abbreviations

List the contents of directories and their file types

Identify various metacharacters

Enter more than one command on a single command line

Demonstrate the use of wildcard characters

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

5
Think Beyond
In your own work environment, what subdirectory structure would be
useful for your home directory? What kinds of files do you work with
most often?

Accessing Files and Directories

5-43

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Directory and File Commands

Objectives
Upon completion of this module, you should be able to

Control screen output using control characters

Determine a files type with the file command

Display the contents of text files using the cat, more, head, and
tail commands

Determine word, line, and character count using the wc command

Compare the contents of text files using diff and cmp

Create empty files or update access time of existing files using the
touch command

Create and remove directories using mkdir and rmdir

Manage files and directories using the mv, cp, and rm commands

Save the output from a command into a file

Pass output from one command to another using a pipe

Use the tee command within a pipeline to create text within a file

6-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Relevance

Present the following question to stimulate the students and get them thinking about the
issues and topics presented in this module. While they are not expected to know the
answer to the question, the answer should be of interest to them and inspire them to learn
the content presented in this module.

Discussion What tasks do you need to complete to manage your


files and directories?

Additional Resources
Additional resources The following reference can provide additional
details on the topics discussed in this module:

6-2

Solaris Users Guide, Part Number 802-6499

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Control Characters
Control characters are used to perform specific tasks such as stopping
and starting screen output. When displayed on the screen, the Control
key is represented by the caret symbol (^).
To enter a sequence of control characters, hold down the Control key
and press the appropriate character on the keyboard.

The Control-s and Control-q characters were originally needed by teletype operators and
are rarely used today.

Directory and File Commands

6-3

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Control Characters
The following control characters can be used:
Table 6-1

6-4

Control Characters

Control Characters

Purpose

Control-s

Stops screen output

Control-q

Resumes screen output

Control-c

Interrupts current activity

Control-d

Indicates end-of-file or exit

Control-u

Erases the command line

Control-w

Erases the last word on the line

The actual character in the shell appears as ^C, even though you press the Control key
and the c key at the same time.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Determining File Type


There are many types of files found on a Solaris system. The type of
file can be determined by using the file command. This information
can be important when a user is attempting to open or read a file.
Determining the file type can help a user decide which program or
command to use to open the file.
The output from this command will most often be one of the
following:

Text Examples include ASCII text, English text, commands text,


and executable shell scripts. The text file type also includes
executable shell scripts. This type of file can be read using the cat
or more commands, which are discussed in this module, and
edited using vi or another editor.

The file command determines file type by referencing the first two bytes of the file. See
the contents of /etc/magic.

Directory and File Commands

6-5

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Determining File Type

Executable or Binary Examples include 32-bit executable and


extensible linking format (ELF) code files and other dynamically
linked executables. This file type indicates that the file is a
command or program. The strings command, shown on the next
page, will print out readable characters in this type of file. (The
output produced by strings is easily interpreted by someone
with a programming background. The command is introduced
here solely as a method for demonstrating the printable characters
of an executable file.)

Data Data files are those which are created by an application


running on the system. In some cases the type of file is indicated;
for example, FrameMaker document. When the application in
which this file was created cannot be determined by the file
command, the output will simply indicate data file. The only way
to read a data file is to determine which application created it and
open the document with that application. If you have many
applications on your system, this can be a time consuming
process.

For information on other file types, see the man pages.

Command Format
file filename(s)

Example Text File


$ file dante
dante:

6-6

English text

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Determining File Type
Example Data File
$ cd /home/user2/dir1/coffees
$ file beans
beans:
Frame Maker Document
FrameMaker must be used to read the beans file.

Example Executable File


$ file /usr/bin/cat
/usr/bin/cat: ELF 32-bit MSB executable SPARC
Version 1, dynamically linked,stripped
The strings command must be used to read /usr/bin/cat. For this
example, use strings followed by the file name as the command
format.
$ strings /usr/bin/cat
SUNW_OST_OSCMD
usvtebn
usage: cat [ -usvtebn ] [-|file] ...
cat: Cannot stat stdout
cat: cannot open %s
cat: cannot stat %s
cat: input/output files %s identical
cat: close error
<some output omitted>

Directory and File Commands

6-7

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Displaying Files
Using the cat Command
The cat (concatenate) command displays the contents of a text file on
the screen. It is often used to display short text files; because cat
flashes through the entire file rapidly without pausing, it is unsuitable
for files longer than one screen in length. The cat command is more
often used to join two or more files into one large file.

Command Format
cat filename(s)

6-8

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Displaying Files
Using the cat Command
Using the cat Command to Display a Short Text File
$ cat dante
The Life and Times of Dante
by Dante Pocai
Mention Alighieri and few may know about whom you
are talking. Say Dante, instead, and the whole world
knows whom you mean. For Dante Alighieri, like Raphael
.
.
.
$
If the file fills more than one screen, the data scrolls off the screen
unless you are using a scrolling window, such as a terminal window,
within the CDE environment.

Directory and File Commands

6-9

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Displaying Files
Using the more Command
Use the more command to display the contents of a text file to the
screen one screen at a time. If the information in a file is longer than
one screen, the following message appears at the bottom of the screen:
--More--(n%)
where n is the percentage of the file already displayed.
The on-line manual pages use the more utility for display purposes, so
the scrolling keys in the following table are the same ones you used to
display man pages.
Note Using cat or more to read executable or binary files can cause
a terminal or window to hang.

6-10

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Displaying Files
Using the more Command
Command Format
more filename(s)
At the --More-- prompt, you can use the following keys to control the
scrolling capabilities:
Table 6-2

Scrolling Keys

Scrolling Keys

Purpose

Spacebar

Scroll to the next screen

Return

Scroll one line at a time

Move back one screen

Move forward one screen

Display a Help menu of more features

Quit and return to the shell prompt

/string

Search forward for string

Find next occurrence of string

Directory and File Commands

6-11

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Displaying Files
Using the head Command
Use the head command to display the first n lines of one or more files.
The first 10 lines are displayed by default if the -n option is omitted.

Command Format
head [ -n ] filename(s)

6-12

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Displaying Files
Using the head Command
Displaying a Specific Number of Lines at the Beginning of a File
$ head -6 /usr/dict/words
10th
1st
2nd
3rd
4th
5th
$
In this example, the head -6 command displays the first six lines of
the /usr/dict/words file.

Directory and File Commands

6-13

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Displaying Files
Using the tail Command
Use the tail command to display the last n lines of a file. The last 10
lines are displayed by default if the -n option is omitted.

Command Format
tail [ -n ] filename(s)
tail [ +n ] filename(s)

6-14

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Displaying Files
Using the tail Command
Displaying a Specified Number of Lines at the End of a File
$ tail -5 /usr/dict/words
zounds
zs
zucchini
Zurich
zygote
$
In this example, the tail -5 command displays the last five lines of
the /usr/dict/words file.

Displaying Lines From a Specific Point in the File


$ tail +23 /usr/dict/words
<Output not shown>
$
In this example, the tail +23 command displays lines 23 through the
end of the /usr/dict/words file.

Directory and File Commands

6-15

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Displaying Files
Using the wc Command
Use the wc command to display a line, word, or character count of a
file. This command is useful when trying to determine characteristics
of a file. Whereas the size can be determined in bytes by using the
ls -l command, much more information is obtained with wc.

Command Format
wc [options] filename(s)
Options

6-16

-l

Counts lines

-w

Counts words

-c

Counts bytes

-m

Counts characters

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Displaying Files
Using the wc Command
Using wc Without Options
$ wc dante
33

223

1320

dante

Using wc without options will give a line, word, and byte count of
the contents of the file.

Determining the Number of Lines in a File


$ wc -l dante
33 dante

Directory and File Commands

6-17

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Comparing Files
Locating Text Differences With the cmp Command
Comparing files to determine differences between them can be done
using the cmp command. This command produces no output if the
files are exactly the same, or it provides the byte and line numbers at
which the first difference occurred if there are discrepancies between
the files.

Command Format
cmp file1 file2

6-18

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Comparing Files
Locating Text Differences With the cmp Command
Using the cmp Command to Compare Files That Appear to be the
Same
You would:
1. Do a long listing and compare the file sizes.
-rw-r--r--1 user2 edu 3528 July 6 16:19 /home/user2/cshrc
-rw-r--r- 1 user2 edu 3528 July 6 16:19 /home/user2/.cshrc
2. From the long listing, identify the date the files were last changed.
If this date signifies that the files are the same, use the cmp
command.
$ cmp ~/cshrc ~/.cshrc
cshrc /home/user2/cshrc differ: char 1638, line 42
This output identifies the first occurrence of a difference between
the two files. The difference occurred at the 1,638th character
position and was found on line 42.
You can now manually locate any further discrepancies and take
whatever action you deem necessary.
Note The cmp command is quite useful when comparing binary files,
but less useful for text files. For more information on this command,
see the man pages.

Directory and File Commands

6-19

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Comparing Files
Using the diff Command
Another command used for finding differences between files is the
diff command. The output of this command will display line-by-line
differences between two text files.

Command Format
$ diff [option] file1 file2

6-20

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Comparing Files
Using the diff Command
Options
-i

Ignores the case of letters; for example, A is equal to


a.

-c

Produces a listing of differences with three lines of


context. With this option, output format is modified
slightly: output begins with identification of the
files involved and their creation dates. Following a
line of a dozen *s, the line numbers of file1 that
are to be displayed are listed. The actual lines from
file1 are then displayed, appended by a for
those lines that are different from file2. The same
display follows as it applies to file2, with a +
appended for those lines that are different from
file1.

Directory and File Commands

6-21

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Comparing Files
Using the diff Command
Using diff to Compare Files
$ diff -c fruit fruit2
*** fruit
Fri May 8 11:32:49
--- fruit2
Fri May 8 14:55:21
************
***2, 8****
orange
apple
banana
-pear
-mango
tomato
pomegranate
---2, 8---orange
apple
banana
tomato
+guava
+mango
pomegranate
$ cat fruit
lemon
orange
apple
banana
pear
mango
tomato
pomegranate
$ cat fruit2
lemon
orange
apple
banana
tomato
guava
mango
pomegranate

6-22

1998
1998

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

File and Directory Naming Conventions


These include:

File names are made up of a maximum of 255 alphanumeric


characters.

Some non-alphanumeric characters, such as underscores (_),


hyphens (-), and periods (.), are allowed.

While the shell will allow asterisks (*), ampersands (&), pipes (|),
quotes ( ), and dollar signs ($) to be used in a file name, this is
not recommended, as these characters have special meaning to the
shell.

File names may contain one or more extensions, usually appended


to file by an application. Extensions are usually one to three
characters that are appended to the end of a file name and are
preceded by a period (.). You may choose to use this convention
when naming files, but it is not a necessary part of a file name.

Directory and File Commands

6-23

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
File and Directory Naming Conventions

Directory names generally do not contain extensions, but there are


no rules against it.

Note To help distinguish between files and directories, some site


administrators prefer their users to start filenames with lowercase
letters and directory names with capital letters.

6-24

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Creating Files
You can create new, empty files using the touch command.

Command Format
touch filename(s)
Absolute and relative pathnames can be specified when creating
files or directories.

Creating Empty Files


$ cd ~/practice
$ touch mailbox project research
$ ls
mailbox project research

Note The touch command creates an empty file if the file name
specified does not exist. Otherwise, the access/modification time of
the existing file is updated.

Directory and File Commands

6-25

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Creating and Appending Using the tee Command


Suppose you want to create a file which contains the names and phone
numbers of your co-workers. You can use the tee command as
follows:
$ tee
Bill
Bill
Fred
Fred
^D

phone_list.txt
O. - 808-555-9876
O. - 808-555-9876
P. - 808-555-6543
P. - 808-555-6543

When the first line is entered, the system searches for a file named
phone_list.txt. If the file exists, the system overwrites its contents
with the new information. If the file does not exist, it is created and the
content is written into it.

6-26

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Creating and Appending Using the tee Command
Each line is entered by pressing the Return key. The line of text is
duplicated in the shell, showing you it has been written to the output
file. Use Control-d to end the input of content.
The -a option for the tee command allows you to append to a files
current contents without overwriting the current contents.

Directory and File Commands

6-27

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Creating Directories
Use the mkdir command to create directories. Directories can be
created using either an absolute or a relative pathname. You can
specify more than one directory name on the same line to create more
than one new directory.

Command Format
mkdir [-p] directory_name

6-28

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Creating Directories
Creating Directories
$ pwd
/home/user2
$ mkdir Reports
$ ls -dl Reports
drwxr-xr-x 2 user2 staff 512 Jan 28 16:24 Reports
$ mkdir Reports/Weekly
$ ls Reports
Weekly
$ cd Reports/Weekly
$ mkdir dir1 dir2 dir3
$ ls -F
dir1/ dir2/ dir3/
$ mkdir ~/games
$ cd
$ ls -F
Reports/ dir1/ dir4/
dante
dir2/ file1
dante_1 dir3/ file2

file3
file4
fruit

fruit2
tutor.vi*
games/
practice/

Note Remember that the tilde (~) is used only by the Korn and C
shells.

Directory and File Commands

6-29

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Creating Directories
You must have the appropriate permissions to create a directory.
(Permissions are covered later in the course.) If you do not have the
correct permissions on a file or directory, you will receive an error
message similar to this one:
$ mkdir /home/Olympic
mkdir: Failed to make directory "/home/Olympic";
Permission denied
You can create multiple levels of directories at one time by using the
-p option.
$ cd
$ mkdir -p practice/dir1/admin
$ ls -R practice
practice:
dir1
mailbox

project

research

practice/dir1:
admin
practice/dir1/admin:

6-30

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Copying Files
Use the cp command to copy files.

Command Format
cp [-i] source_file destination_file
cp [-i] source_file(s) destination_directory

Directory and File Commands

6-31

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Copying Files
Copying a File to Another Within a Directory
The following example demonstrates how to copy one file to a new file
in the same directory:
$ cd
$ pwd
/home/user2
$ cp file3 feathers
$ ls
Reports dir1 dir4
file2
dante
dir2 feathers file3
dante_1 dir3
file1
file4
$ cp feathers feathers_6

fruit practice
fruit2 tutor.vi
games

Copying Multiple Files


The following example demonstrates how to copy multiple files into a
directory other than the current directory:
$ pwd
/home/user2
$ ls dir1
coffees fruit
trees
$ cp feathers feathers_6 dir1
$ ls dir1
coffees
feathers feathers_6

fruit

trees

Preventing Overwriting an Existing File When Copying


Use cp -i as a security measure. The -i option prompts you if you
are about to overwrite an existing file.
$ cp -i feathers file3
cp: overwrite file3 (yes/no)? n
$

6-32

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Copying Directories
Use the cp -r (recursive) command to copy a directory and its
contents to another directory. If the directory does not exist, it is
created by the cp command.

Command Format
cp -r[i] source_directory(s)

destination_directory

Without the -r option, the files and subdirectories contained within a


directory are not copied. When used with the -i option, cp prompts
for verification before overwriting an existing file.

Directory and File Commands

6-33

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Copying Directories
Copying the Contents of a Directory to a New Directory
The following example demonstrates how to copy a directory and all
of its files to a new directory in the current directory and the error that
results from not using the -r option:
$ cd
$ pwd
/home/user2
$ ls dir3
planets
$ cp dir3 ski.places
cp: dir3: is a directory
$ cp -r dir3 ski.places
$ ls ski.places
planets
$
The following example demonstrates how to copy a directory to
another directory that is not in the current directory:
$ cd
$ pwd
/home/user2
$ cd dir3
$ cp -r planets ../dir1/constellation
$ cd
$ cp -r dir1 ski.places /tmp
$ ls -F /tmp
dir1/ ski.places/
$

6-34

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Moving and Renaming Files


Use the mv command to move or rename files and directories.

Command Format
mv [-i] source target_file
mv [-i] source target_directory
You can use the mv -i option, which prompts for confirmation
whenever the move would overwrite an existing target. A y answer
means that the move should proceed. Any other answer prevents mv
from overwriting the target.

Directory and File Commands

6-35

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Moving and Renaming Files
Renaming Files in the Current Directory
The following example demonstrates renaming a file in the current
directory:
$ cd ~/dir1/coffees
$ ls
beans
nuts
$ mv nuts brands
$ ls
beans
brands
$

Moving Files to Another Directory


The following example demonstrates moving a file into another
directory:
$ pwd
/home/user2/dir1/coffees
$ ls
beans
brands
$ mv brands ~
$ ls
beans
$ ls ~/b*
/home/user2/brands
$

6-36

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Moving and Renaming Files
Renaming Directories
The following example demonstrates using the mv command to
rename directories within the current directory:
$ pwd
/home/user2/dir1/coffees
$ cd
$ mkdir maildir
$ ls
Reports
dir2
file1
brands
dir3
file2
dante
dir4
file3
dante_1
feathers file4
dir1
feathers_6 fruit
$ mv maildir monthly
$ ls
Reports
dir2
brands
dir3
dante
dir4
dante_1
feathers
dir1
feathers_6
$

file1
file2
file3
file4
fruit

fruit2
tutor.vi
games
maildir
practice
ski.places

fruit2
tutor.vi
games
monthly
practice
ski.places

Moving a Directory and Its Contents


The following example demonstrates using the mv command to move
a directory and its contents into another directory:
$ pwd
/home/user2
$ mv practice letters
$ ls letters
dir1
mailbox
project
$

Directory and File Commands

research

6-37

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Moving and Renaming Files
Renaming in a Non-Current Directory
The following example demonstrates how to use the mv command to
rename a file in a non-current directory:
$ pwd
/home/user2
$ mv letters/project letters/project2
$ ls letters
dir1
mailbox
project2 research
$

6-38

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Removing Files
Use the rm command to remove files.

Command Format
rm [-i] filename(s)

Directory and File Commands

6-39

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Removing Files
You can remove several files.
$ cd ~/letters
$ pwd
/home/user2/letters
$ ls
dir1
mailbox
project2 research
$ touch projection
$ ls
dir1
mailbox
project2
projection
$ rm research project2
$ ls
dir1
mailbox
projection

research

Use the rm -i command as a precaution. The -i option prompts you


for confirmation before removing any file.
$ rm -i projection
rm: remove projection: (yes/no) ? y
$ ls
dir1
mailbox

6-40

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Removing Directories
Use the rm and rmdir commands to remove directories. The rmdir
command only deletes empty directories. If the directory to be
removed is your current directory, you will not be able to remove it
with either of these commands.

Command Format
rmdir directory_name(s)
rm -r [i] directory_name(s)

Directory and File Commands

6-41

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Removing Directories
Removing Directories
Use the rmdir command to remove an empty directory.
$ cd
$ pwd
/home/user2
$ mkdir -p newdir/empty
$ cd newdir
$ ls -F
empty/
$ rmdir empty
$ ls
$
Use rm -r to remove a directory that is not empty.
$ cd
$ pwd
/home/user2
$ rm -r letters
$ ls
Reports
dir2
brands
dir3
dante
dir4
dante_1
feathers
dir1
feathers_6

file1
file2
file3
file4
fruit

fruit2
tutor.vi
games
monthly
newdir
ski.places

Use rm -ir to interactively remove directories.


$ mkdir -p ~/practice/dir1
$ ls ~/practice
dir1
$ rm -ir
rm: examine files in directory practice (yes/no)? y
rm: examine files in directory practice/dir1
(yes/no)? y
rm: remove practice/dir1: (yes/no)? y
rm: remove practice: (yes/no)? y

6-42

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Redirection
Overview
All central processing unit (CPU) operations have input and/or output
(I/O). The keyboard, for example, provides standard input while the
monitor displays standard output and standard error.

Figure 6-1

Input, CPU, and Output

Directory and File Commands

6-43

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Redirection
Overview
These are defined as follows:

Input Sending data to a command

Output Receiving data from a command

Error - Errors generated by a command


Standard
input

Command

Standard
output

The Solaris computing environment enables command I/O to be


controlled using redirection. This is useful when attempting to save
the output of a command to a file for later viewing, sending the
contents of a file as an email message, or redirecting error messages to
a file for use when debugging a program.
The format for the redirection of standard input, standard output, and
standard error is:

command > file


command < file
command 2> file

6-44

or

command >> file

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Redirection
Angle Brackets ( >, <, 2> )
Use the right-angle bracket (>) to redirect the output of a command to
a file rather than to the screen.
Use the left-angle bracket (<) to redirect the input to a command from
a file rather than from the keyboard.
Use the number 2 and the right-angle bracket (2>) to redirect error
from a command to a file rather than to the screen.

Redirecting Output From a Command to a File


$ ls /etc > etc.list

Caution If the name of the file already exists, you will overwrite it.
In the Korn shell, an option called noclobber can be set to prevent
overwriting of files during redirection. This can be done on the
command line by using $ set -o noclobber.

Redirecting the Input of a File to a Command


$ mailx user2@saturn < dante

Note This example illustrates redirection of input using the mailx


command. This is the standard command-line mail program and is
addressed in more detail in Appendix B.

Redirecting Standard Error to a File


$ Date 2> errorfile
$ cat errorfile
ksh:
Date: not found

Directory and File Commands

6-45

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Redirection
Angle Brackets ( >> )
Appending Output
Use the double right-angle bracket (>>) to append the output of a
command to an existing file.
$ cal 10 2000> mon00
$ cat mon00
October 2000
S M Tu W Th F S
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
$ cal 1 2001 >> mon00
$ cat mon00
October 2000
S M Tu W Th F S
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
January
S M Tu
1 2
7 8 9
14 15 16
21 22 23
28 29 30

6-46

2001
W Th
3 4
10 11
17 18
24 25
31

F
5
12
19
26

S
6
13
20
27

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Piping
One of the most powerful metacharacters is the pipe (|). The pipe
takes the standard output of one command and passes it as standard
input into a following command. In effect, pipes enable you to build a
miniature program.
You must always have a command on each side of a pipe.

Directory and File Commands

6-47

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Piping
Displaying Command Output One Screen at a Time
One of the most common uses of the pipe metacharacter is to send the
output of an ls command to the more command to enable you to see a
long directory listing one screen at a time.
$ ls -l /etc | more
The standard output from the command to the left of the pipe becomes
the standard input for the command on the right side of the pipe.

Using the tee Command in a Pipeline


Syntax for a pipe requires that there be a command on both sides of
the pipe. If output to a file is desired in the middle of a pipeline, the
tee command can be used. The following command creates a file
containing a listing of the home directory from the output of the ls
command, without disturbing the flow of the output to the lp
command:
$

ls ~ | tee homedir | lp

Note lp is the UNIX command-line print command used to print


text files. Printing is covered in Module 13.

6-48

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Exercise: Using Directory and File Commands
Exercise objective In this lab you will use the commands introduced
in this module to display the contents of files; compare files; determine
file type, and create, move, and remove files and directories.

Tasks
Complete or answer the following:
1. Determine the file type of /etc/passwd and display the contents
of the file.
2. Display the contents of the file /usr/dict/words one screen at a
time. Exit after displaying two screens.
3. What command would you most likely use to read the contents of
/usr/bin/cp ?
4. Return to your home directory (if you need to) and list the
contents.
5. Copy the dir1/coffees/beans file into the dir4 directory and
call it roses.
6. Create a directory called vegetables in dir3.
7. Move the dir1/coffees/beans file into the dir2/recipes
directory.
8. Copy dir3/planets/mars to the practice directory and name
the file addresses.
9. Create a directory called play in your practice directory and
move the practice/addresses file to that play directory.
10. Copy the play directory in the practice directory to a new
directory in the practice directory called appointments.
11. Recursively list the contents of the practice directory.

Directory and File Commands

6-49

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Exercise: Using Directory and File Commands
Tasks
12. Change to your home directory and with one command, create a
directory called house with a subdirectory of furniture in your
home directory.
13. Create an empty file called chairs in the new directory
furniture.
14. Using one command, create three directories called letters,
memos, and misc in your home directory.
15. Using one command, delete the directories called memos and misc
in your home directory.
16. Try to delete the directory called house/furniture with the rm
(no options) command. What happens?
__________________________________________________
17. Identify the command to delete a directory that is not empty.
Delete the directory house/furniture. List the contents of house
to verify that furniture has been deleted.
18. From your home directory, redirect the output of the ls command
to a file called file.list.
19. Display the contents of file.list using the cat command.
20. Append the output of the date command to file.list.
21. Display a calendar and using the tee command, append the
output to file.list.
22. Use the tee command to create a file with the names of five of the
students in the class in it. Examine the contents of your class list
with the cat command.

6-50

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Exercise: Using Directory and File Commands
Workshop Labs
Use what you have learned so far in this course to work through the
following:
1. What shell has the system administrator set up for you?
2. Create a directory in which to place all of your personal executable
files and place a copy of any executable file that currently exists in
your home directory into this new directory.
3. While performing a keyword search on shell you find many
commands that you want to learn more about in your spare time.
Since your time is valuable you would like to save a listing of the
commands revealed by the search in a file and refer to it when you
have a free moment. Place this file in your home directory to be
used for reference later.

Directory and File Commands

6-51

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Exercise: Using Directory and File Commands
Exercise Summary
Discussion Take a few minutes to discuss what experiences, issues,
or discoveries you had during the lab exercises.

Manage the discussion here based on the time allowed for this module, which was given
in the About This Course module. If you find you do not have time to spend on
discussion, then just highlight the key concepts students should have learned from the
lab exercise.

Ask students what their overall experiences with this exercise have been. You might want
to go over any trouble spots or especially confusing areas at this time.

6-52

Conclusions

Have students articulate any conclusions they reached as a result of this exercise
experience.

Interpretations

Ask students to interpret what they observed during any aspects of this exercise.

Experiences

Applications

Explore with students how they might apply what they learned in this exercise to
situations at their workplace.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Exercise: Using Directory and File Commands
Exercise Solutions
1. Determine the file type of /etc/passwd and display the contents
of the file.
file /etc/passwd
cat /etc/passwd
2. Display the contents of the file /usr/dict/words one screen at a
time. Exit after displaying two screens.
more /usr/dict/words
To exit, type q or Control-c
3. What command would you most likely use to read the contents of
/usr/bin/cp ?
strings /usr/bin/cp
4. Return to your home directory (if you need to) and list the
contents.
cd; ls
5. Copy the dir1/coffees/beans file into the dir4 directory and
call it roses.
cp dir1/coffees/beans dir4/roses
6. Create a directory called vegetables in dir3.
mkdir dir3/vegetables
7. Move the dir1/coffees/beans file into the dir2/recipes
directory.
mv dir1/coffees/beans dir2/recipes
8. Copy dir3/planets/mars to the practice directory and name
the file addresses.
cp dir3/planets/mars practice/addresses

Directory and File Commands

6-53

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Exercise: Directory and File Commands
Exercise Solutions
9. Create a directory called play in your practice directory and
move the practice/addresses file to that play directory.
mkdir practice/play
mv practice/addresses practice/play
10. Copy the play directory in the practice directory to a new
directory in the practice directory called appointments.
cp -r practice/play practice/appointments
11. Recursively list the contents of the practice directory.
ls -R practice
12. Change to your home directory and with one command, create a
directory called house with a subdirectory of furniture in your
home directory.
cd; mkdir -p house/furniture
13. Create an empty file called chairs in the new directory
furniture.
touch house/furniture/chairs
14. Using one command, create three directories called letters,
memos, and misc in your home directory.
mkdir letters memos misc
15. Using one command, delete the directories called memos and misc
in your home directory.
rmdir memos misc
16. Try to delete the directory called house/furniture with the rm
(no options) command. What happens?
rm house/furniture
rm: house/furniture is a directory

6-54

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Exercise: Directory and File Commands
Exercise Solutions
17. Identify the command to delete a directory that is not empty.
Delete the directory house/furniture. List the contents of house
to verify that furniture has been deleted.
rm -r house/furniture; ls house
18. From your home directory, redirect the output of the ls command
to a file called file.list.
ls > file.list
19. Display the contents of file.list using the cat command.
cat file.list
20. Append the output of the date command to file.list.
date >> file.list
21. Display a calendar and using the tee command, append the
output to file.list.
cal | tee -a file.list
22. Use the tee command to create a file with the names of five of the
students in the class in it. Examine the contents of your class list
with the cat command.
$ tee classlist
name1
name1
name2
name2
name3
name3
name4
name4
name5
name5
ctrl-d
$ cat classlist

Directory and File Commands

6-55

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Check Your Progress
Before continuing on to the next module, check that you are able to
accomplish or answer the following:

6-56

Control screen output using control characters

Determine a files type with the file command

Display the contents of text files using the cat, more, head, and
tail commands

Determine word, line, and character count using the wc command

Compare the contents of text files using diff and cmp

Create empty files or update access time of existing files using the
touch command

Create and remove directories using mkdir and rmdir

Manage files and directories using the mv, cp, and rm commands

Save the output from a command into a file

Pass output from one command to another using a pipe

Use the tee command within a pipeline to create text within a file

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

6
Think Beyond
Why is rm -r * such a dangerous command? What might you do to
prevent use of this command?

Directory and File Commands

6-57

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Managing Files With File Manager

Objectives
Upon completion of this module, you should be able to:

Describe the basic concepts of the File Manager

Demonstrate the drag-and-drop capability of File Manager

Create and remove folders

Execute actions from the File Managers menu options

Move a file or a folder onto the workspace backdrop

Find a file using File Managers Locate facility

Customize the manner in which file and folder information is


displayed in the File Manager window

7-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
Relevance

Present the following question to stimulate the students and get them thinking about the
issues and topics presented in this module. While they are not expected to know the
answer to the question, the answer should be of interest to them and inspire them to learn
the content presented in this module.

Discussion File manipulation is frequently done by using the


graphical user interface. What alternatives to using the command line
does working within the GUI provide?

7-2

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
The File Manager

Front
Panel
File Manager
icon

File
Manager
window
display

File
Manager
icon

Managing Files With File Manager

7-3

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

The File Manager


The File Manager enables you to graphically organize files into a
hierarchical structure of folders and subfolders (directories).
Directories are displayed with folder icons. Files are displayed with
appropriate icons.
The File Manager, by default, opens a view of a folder which is the
current directory. From that folder, you can change to other folders,
both up and down in the hierarchy, to view each directorys contents.
The path to the current folder is always displayed in the top area of
the File Manager window.

The path to the


current folder
The pathname of
the current folder

7-4

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
File and Folder Icons

Audio file

Binary file

Core file

Graphic file

PostScript (text) file

Standard file

Folder icon

Managing Files With File Manager

7-5

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
File and Folder Icons
To help you identify files and directories more easily, the File Manager
displays differing icons depending on the content of the file.
The most common file icon you will see will be the standard file icon.

If a file is a data file associated with a particular application, that


application will be automatically started when you double-click on the
icon.
If you double-click on a folder icon, the File Manager moves you into
that directory and displays its contents. You can only move down
through the file system hierarchy in this way.
There is always a special icon displayed in the upper left corner of the
File Manager display.

Double-clicking on this (go up) icon will move you to the next level up
in the hierarchy.

7-6

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
Moving and Copying Files Using Drag-and-Drop

File is
selected
then
dragged
to the
appropriate
folder
icon

Managing Files With File Manager

7-7

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
Moving and Copying Files Using Drag-and-Drop
Select + Drag + Drop
To move a file from one folder to another, position the mouse pointer
over the file icon, hold down the left mouse button and drag the icon
to the appropriate folder icon.
Once the file icon is positioned over the folder icon, release the mouse
button and the file will be moved to that folder.

Control + Select + Drag + Drop


If you press the Control key before the file icon has been selected and
keep it held down while the drag-and-drop process takes place, the file
will be copied rather than just moved to the other folder.
Note You cannot move or copy file icons to the path icon display in
the top part of the File Manager window display.
If you want to move or copy files to the parent directory of the current
folder, you can drag and drop the file icon to the (go up) icon.

7-8

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
File Menu Options

The File Menu options enable you to perform the following tasks:

Create a new folder (directory)

Create a new file

Change to your home directory (if your current folder is different


from your home folder)

Go up one level of folder in the hierarchy

Change to a specified directory

Find files based on their name or content

Open a Terminal window (in which to give UNIX commands)

Note There are keyboard mnemonics which can be used as shortcuts


to the File menu options.

Managing Files With File Manager

7-9

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
Creating a New Folder

7-10

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Creating a New Folder


When the New Folder option is chosen, a separate window is
displayed. Type the name of the new directory.
Once the name has been applied, you have the choice of left clicking
either OK or Apply.

Clicking OK adds the new folder with the name you just typed,
and closes the New Folder window.

Clicking Apply adds the new folder, and keeps the New Folder
window on the screen display, ready for you to type in the name
of another new folder.

If you want to create several new directories, click Apply for all new
folder names except the last. When the last folder name has been
typed, click OK to remove the New Folder window.
Note When you click Apply, the name is retained in the typing area
of the New Folder window. You must remove the previous folder
name using the Backspace key or the equivalent mouse action.
Managing Files With File Manager

7-11

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
Creating a New File

As with the New Folder option, a window will be displayed in which


you must type the name of the file to be created.
If you click OK, the file will be created, with the name you typed, and
the New File window will close.
However, if you click Apply, the file will be created and the New File
window will stay on the screen so you can create another new file. By
clicking Apply after each file name has been typed, you can add
several new files from the same New File window.
7-12

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
Folder or File Name Conflicts

If you attempt to create a folder or file with the same name as an


existing folder or file, you will be notified by the File Manipulation
Error window.
Click OK, then type an alternative name for the folder or file which is
to be created.

Managing Files With File Manager

7-13

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
Changing Folders

The Go To option on the File Managers File menu enables you to


specify which folder to change to by specifying a path name.
Enter a valid pathname into the appropriate entry box, then click OK.
If there are any permission controls which prevent you from changing
to the specified folder, you will be notified with the following window
display:

7-14

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
Finding Folders and Files

Managing Files With File Manager

7-15

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
Finding Folders and Files
The Find menu option enables you to search through the file system
hierarchy using search criteria. The criteria can be either the name of
the folder or file or, in the case of a file, the contents.
Wildcard characters can be used when specifying the name of the file
to find. For example:
a*

Finds folder or file names which start with the letter a

*s

Finds folder or file names which end with the letter s

??a

Finds three-character folder or file names, where the last


character in the name is the letter a

[Aa]*

Finds folder or file names which start with the letter a


(either uppercase or lowercase)

The search folder name is the starting point when searching the file
system hierarchy.
Note If you start at the root of the file system (the / directory), the
Find operation may take a considerable amount of time to complete.

7-16

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
Selected Menu Options
The Selected Menu With a Folder Chosen

Managing Files With File Manager

7-17

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
Selected Menu Options
The Selected Menu With a File Chosen

7-18

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Selected Menu Options


File and Folder icons can be selected by clicking with the left mouse
button. Once selected, the File Manager menu options enable you to:

Move the selected object to another folder location.

Copy the selected object to another folder location or to a different


named folder or file.

Link the folder or file to another folder or file name. (This option
creates a symbolic link with the same name as the original file or
folder. Links are covered in Module 14.)

Place the object on the workspace area. This placement makes that
object available whether or not you have a File Manager window
open.

Place the object in the trash can. An alternative to this option is to


drag and drop the object over the Trash Can icon on the Front
Panel display.

Managing Files With File Manager

7-19

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
Selected Menu Options

Change the permissions of a folder or file. (Permissions are


covered in Module 8.)

Select or deselect all objects in the current folder. Once selected,


they can be moved, copied, or deleted as a complete group of
objects.

Open a folder or file. This menu option is the same as doubleclicking on the object icon.

Print the file. This is same as using drag and drop with the Print
Manager icon on the Front Panel.

Note Different options display in the Selected menu, depending on


the type of file or folder selected.

7-20

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
View Menu Options

Clicking on Open New View in the View menu will open another File
Manager window. This facilitates moving files between different
directory hierarchies.
The File Manager window can be set to Show Hidden Objects,
allowing viewing of all objects in a directory. Setting the Filter Options
enables you to decide what objects will be hidden objects if you choose
not to have these objects displayed.
The Update option of the View menu will redraw the File Manager
window screen. This is useful if objects have been hidden or moved
around during the current File Manager session.

Managing Files With File Manager

7-21

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
View Menu Options
Set View Options enables you to choose the way in which the File
Manager information is displayed in the window.
The choices are as follows:

You can change the ordering of the display by name, file type, date, or
size.

7-22

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
View Menu Options
Tree Display for Folders

Managing Files With File Manager

7-23

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
View Menu Options
By using the Tree display for your folders, it becomes easier to move
around the file system hierarchy.
When a folder is selected by double-clicking, another File Manager
window will automatically be invoked and the contents of the selected
folder will be displayed in the new File Manager window.
Note For every folder which is selected, a new File Manager window
will be invoked. Close the File Manager windows if you have finished
working with the contents of the folder; otherwise, the performance of
your workstation will begin to degrade.

7-24

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
Exercise: Managing Files With File Manager
Exercise objective In this lab you will use the commands introduced
in this module to create, move, and remove files and directories.

Tasks
Complete the following exercises:
1. Open a File Manager window.
2. Create a new folder and a new file. Try giving the new file the
same name as the new folder. (Correct as necessary.)
3. Change the View to a Tree view then back to the original view.
4. Use the (go up) icon to change to the root folder (/).
5. Change to your home folder by double-clicking on the appropriate
folder objects.
6. Use the Go To menu option change to the root folder.
7. Use the appropriate menu option to change to your home folder.
8. Delete your new file by dragging and dropping the new file object
onto the Trash Can icon on the Front Panel.

Managing Files With File Manager

7-25

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
Exercise: Managing Files With File Manager
Exercise Summary
Discussion Take a few minutes to discuss what experiences, issues,
or discoveries you had during the lab exercises.

Manage the discussion here based on the time allowed for this module, which was given
in the About This Course module. If you find you do not have time to spend on
discussion, then just highlight the key concepts students should have learned from the
lab exercise.

Ask students what their overall experiences with this exercise have been. You might want
to go over any trouble spots or especially confusing areas at this time.

7-26

Conclusions

Have students articulate any conclusions they reached as a result of this exercise
experience.

Interpretations

Ask students to interpret what they observed during any aspects of this exercise.

Experiences

Applications

Explore with students how they might apply what they learned in this exercise to
situations at their workplace.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
Check Your Progress
Before continuing on to the next module, check that you are able to
accomplish or answer the following:

Demonstrate the drag-and-drop capability of File Manager

Create and remove folders

Execute actions from the File Managers menu options

Move a file or a folder onto the workspace

Find a file using File Managers Locate facility

Customize the manner in which file and folder information is


displayed in the File Manager window

Managing Files With File Manager

7-27

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

7
Think Beyond
Now that you know how to manipulate files and directories on the
command line and within CDE, which method are you most likely to
use? In what situations might your choice be different?

7-28

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

File Security

Objectives
Upon completion of this module, you should be able to:

Display file permissions

Define permission types (read, write, and execute)

Set and change file permissions using symbolic and octal notation

Display the umask value of a file or directory

8-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Relevance

Present the following question to stimulate the students and get them thinking about the
issues and topics presented in this module. While they are not expected to know the
answer to the question, the answer should be of interest to them and inspire them to learn
the content presented in this module.

Discussion What types of protection would you like to be able to


place on files and directories? How would you group people you
work with and who would have access to your files and directories?

Additional Resources
Additional resources The following reference can provide additional
details on the topics discussed in this module:

8-2

Solaris Advanced Users Guide, Part Number 801-6615-10

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Security Overview
The primary function of a systems security feature is to deny access to
unauthorized users. Keeping computer information secure is
important to the user and the system administrator. By protecting their
files and accounts from unauthorized use, users are also protecting
their job and reputation.
Standard Solaris environment security features include user
passwords, which restrict access to the system; file and directory
protection with permissions; files that control remote logins and
commands on individual workstations; and other features that enable
system administrators to check for security breaches.

File Security

8-3

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Permissions
The Solaris operating system has two default levels of security. First,
users must supply a login ID and password in order to access a Sun
workstation. Second, files and directories are automatically protected
by permissions when they are created.

Superuser
Solaris provides a special user account called root that has total
access to the system. All permissions placed on files and directories
can be overridden by the root user. This accounts user is also called
the superuser.
The superuser account is used to run system administration
commands and to edit critical system files such as the password file.

8-4

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Permissions
The ls -l Command
The ls -l command displays the following permissions:

File type This includes directories and ordinary files.

User (owner) The user who created the file or directory

Group Class of users defined by the system administrator

Others (public) All other users

File Security

8-5

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Permissions
The ls -l Command
$ ls -l .profile

-rw-r--r--

1 user2 staff 560 Jun 11 11:23 .profile

-rw-r--r-File type
User
Group
Others
Figure 8-1

8-6

Permissions for Each Class of User

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Permissions
Permission Categories
File Type
The first character is called the file type. An ordinary file is represented
by a dash (), and a directory is represented by a d. A dash anywhere
else in a permission set indicates no permission. The interpretation of
permissions is slightly different for files and directories.

User (Owner)
The next three characters are the user or owner permissions. They show
the type of access the owner of the file or directory has. When you
create a new file or directory, it is owned by you.
The owner of the file .profile in the example is user2.

File Security

8-7

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Permissions
Permission Categories
Group
The second set of three characters, called group permissions, identifies
the permissions of the group that owns the file. A user group (system
group) is a set of users with common file access needs. System
administrators define system groups and determine which users
belong to which groups.
Users in the same group can access each others files based on the
group permissions.
The group owner of the file .profile in the example is the group
staff.

Others (Public)
The last set of characters, called others permissions, are the permissions
everyone else has. Others is anyone who is neither the file owner nor a
member of the group that owns the file, but who has access to the
system.
Files you create are owned by you and the group association on these
files is your primary group. Access is determined by the highest
category to which you belong. If you are the user (owner), even
though you are a member of the group, only the user category of
permissions applies. The others permissions only apply to someone
who is neither the owner nor a member of the group.

8-8

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Permissions
How File and Directory Access Is Determined
UID and GID
All files and directories have a user identifier (UID) and group
identifier (GID) number associated with them. The kernel uses these
numbers to identify ownership of files, rather than the user or group
name familiar to the user.
$ ls -an
drwxr-xr-x 2
-rw-r--r-- 1

101 10
101 10

512
0

May 24 17:25 mickey


May 24 17:25 .profile

Note The -n option displays the UID and the GID.

File Security

8-9

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Permissions
Process For Determining Permissions
Every system process also has a UID and GID. When a process
attempts to read, write, or execute a file, the process system data
information is compared to the files or directorys UID, and then to
the GID. If neither matches, then the other category of permissions is
used.
System process=File or directory
Yes
UID=UID

Use user
permissions

No

GID=GID

Yes

Use group
permissions

No
Use other
permissions

Figure 8-2

8-10

Process for Determining Permissions

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Permissions
Default Permissions
When a user accesses the system, files and directories are protected by
default permissions. These are put in place automatically when a file
or directory is created.
$ mkdir secure; touch pluto
$ ls -l
drwxr-xr-x 2 user2 staff
-rw-r--r-- 1 user2 staff

File Security

512 May 24
0 May 24

17:25 secure
17:25 pluto

8-11

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Permissions
Types of Permissions
Every file or directory has a set of permissions that determines who can
do what with it.
Permissions are represented by characters that control who may read,
write, and execute the contents of a file or directory.

8-12

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Permissions
Types of Permissions
Table 8-1

Permissions and Corresponding Symbols

Read

Permission
Symbol
r

Write

Execute

Permission

Plain File

Directory

File can be
displayed or
copied.
File contents can
be modified.

Contents can be
listed with the
ls command.a
Files can be
added or
deleted.b
Access to the
directory is
controlled.c

File can be
executed (shell
scripts or
executables
only).

a. To display a long listing (ls -l), you must also have execute (access) permission
on the directory.
b. To add or delete files, you must have execute permission on the directory.
c. To copy a file from a directory, you must have execute permission on the
directory. To use the mv command to place a new file in a directory or move a file
from a directory, you must also have execute permission on the directory. You must
also have read permission on the file itself for either of these actions to be performed.

Note As can be seen from Table 8-1, in order for a directory to be of


any practical use, at least read and execute permissions must be set.
As seen from previous examples, you may see a dash () in place of r,
w, or x. This indicates no permission.
The following are samples of different types of permissions on files
and directories:

The file is read/write/execute for owner only.

-rwx-----

The directory is read/execute for owner and group.

dr-xr-x---

File Security

8-13

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Permissions
Types of Permissions

The file is read/write/execute for owner, and read/execute for


group members and others.
-rwxr-xr-x

The directory is read/write/execute for owner, read/execute for


group, and execute for others.
drwxr-x--x

8-14

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Changing Permissions
Overview
The chmod command is used by a files owner (or superuser) to change
file permissions.
The two modes of operation with the chmod command are symbolic
and octal.

Symbolic mode uses combinations of letters and symbols to add or


remove permissions from various categories of users.

Octal mode uses octal numbers to represent file permissions. Octal


mode is also referred to as absolute or numeric mode.

File Security

8-15

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Changing Permissions
Symbolic Mode
The command format for symbolic mode uses letters and symbols.

Command Format

chmod mode filename

who

op

permission(s)

r Read
w Write
x Execute

= Set permissions
- Remove access
+ Give access

u
g
o
a

8-16

User or owner of the file


Group to which the file belongs
Others outside owner and group
All of the above

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Changing Permissions
Symbolic Mode
Changing Permissions With Symbolic Mode
You can:

Remove group read permission

$ ls -l dante
-rw-r--r-- 1 user2
$ chmod g-r dante
$ ls -l dante
-rw----r-- 1 user2

staff

staff

Jun 11 1:44

Jun 11

dante

1:44 dante

Jun 11 1:44

dante

Add execute permission for owner, and read permission for group
and others
$ chmod u+x,go+r dante
$ ls -l dante
-rwxr--r-- 1 user2
staff

Deny read permission to others


$ chmod o-r dante
$ ls -l dante
-rw------- 1 user2

staff

Jun 11 1:44

dante

There is no space after u+x and before go+r,although there is a comma between them.

Set permissions to read and write for everyone


$ chmod a=rw dante
$ ls -l dante
-rw-rw-rw- 1 user2

File Security

staff

Jun 11 1:44

dante

8-17

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Changing Permissions
Octal (Absolute) Mode
Octal mode is based on the base eight numbering system (07 are the
available numerals).

Command Format
chmod octal_mode filename
Each permission has an octal value as shown in Table 8-2.
Table 8-2

8-18

Permissions for Each Octal Value

Octal Value

Permissions

Read

Write

Execute

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Changing Permissions
Octal (Absolute) Mode
The octal values for the permission set are shown in Table 8-3.
Table 8-3

Octal Values for Permission Sets

Octal Value

Permissions

r w x

r w -

r - x

r - -

- w x

- w -

- - x

- - -

File Security

8-19

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Changing Permissions
Octal (Absolute) Mode
Octal values are combined to identify the octal_mode that is used
with the chmod command.
Table 8-4

Combined Values and Permissions

Octal Value

Permissions

644

rw-r--r--

751

rwxr-x--x

775

rwxrwxr-x

777

rwxrwxrwx

The first position defines the user (owner) permissions, the second
position defines the group, and the last position defines others.
Default permissions on files are 644, and default permissions on
directories are 755.
Note When using octal mode with the chmod command, you must
list all three numbers, one for each category of user: user, group, and
others.

8-20

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Changing Permissions
Octal (Absolute) Mode
Changing Permission With Octal Mode
You can:

Give user, group, and others read and execute access


$ ls -l dante
rw-rw-rw- 1 user2 staff
$ chmod 555 dante
$ ls -l dante
-r-xr-xr-x 1 user2 staff

2 Jun 11 11:54 dante

Change user and group permissions to include write access


$ chmod 775 dante
$ ls -l dante
-rwxrwxr-x 1 user2 staff

2 Jun 11 11:54 dante

2 Jun 11 11:54 dante

Change group permission to read and execute


$ chmod 755 dante
$ ls -l dante
-rwxr-xr-x 1 user2 staff

File Security

2 Jun 11 11:54 dante

8-21

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Default Permissions
The umask Filter
The umask filter determines the default permissions for files and
directories. The permissions are assigned during the creation of new
files and directories.

Displaying Your umask


$ umask
022
The default permissions which will be assigned to a newly created file
or directory are determined by the application of the umask filter
against the maximum system assignable file (666) and directory (777)
permissions. Each digit in the umask value represents permission
categories which are to be denied, or masked out,, from the
maximum permissions.

8-22

Depending up the shell, the umask value will display differently as either 0022, 022, or 22.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Default Permissions
The umask Filter
As an example, in the case of a newly created file, the maximum
system assignable file permissions are represented by the octal value
666. This corresponds to read/write (42-) access for the user,
read/write (42-) access for the group, and read/write (42-) access for
all others. This can be represented as:
42-42-42rw-rw-rwThe default umask filter value is octal 022, which corresponds to no
access denial (---) for the user, a denial of write (-2-) access for the
group, and a denial of write (-2-) access for all others. This can be
represented as:
----2--2----w--wWhen the access categories to be denied are masked out from the
maximum system assignable values, the default permissions which are
assigned to a newly created file are left.
42-42-42- Maximum system assignable file permissions
----2--2-

Default umask filter value

42-4--4-- Default permissions assigned to a newly created file


rw-r--r-Note Execute permissions can be placed on files by the user but are
not assigned by the system when a file is created.

File Security

8-23

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Default Permissions
This same process can be applied when determining what the default
permissions will be when creating new directories. In this case, the
maximum system assignable permissions are represented by the octal
value 777. This corresponds to read/write/execute access for the user,
group, and others.
421421421 Maximum system assignable directory permissions
rwxrwxrwx

----2--2----w--w4214-14-1
rwxr-xr-x

Default umask filter value

Default permissions assigned to a newly created directory

Another way to look at the meaning of the umask value is to subtract


each digit of the umask from the maximum assignable file and
directory permissions to determine the octal value of the permissions
assigned to newly created files and directories.

8-24

666
022
644

Maximum system assignable file permissions


umask value
Octal value of permissions assigned to a newly created file

777
022
755

Maximum system assignable directory permissions


umask value
Octal value of permissions assigned to a newly created directory

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Default Permissions
The umask Filter
The umask value is set in the kernel but an alternate value can be
placed in /etc/profile by the system administrator. Users can set
their own umask value. A more secure umask than the default (022)
would be 027, which gives no permissions to others.
Table 8-5

umask Settings

umask Setting

File

Directory

022

Gives read and write


permission to the
owner of the new file
and read permission
to group and others

Gives all permissions


to the owner and read
and execute
permissions to group
and others

027

Gives read and write


permission to the
owner of a new file,
read permission to
group, and no
permissions to others

Gives all permissions


to the owner, read and
execute permissions to
group, and no
permissions to others

File Security

8-25

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Default Permissions
Changing the umask Value
The umask value can be changed at the command line or with a umask
command in the users startup (.profile) file.

Changing umask for the Current Shell and its Subshells


You would:
1. Verify the current umask.
$ umask
022
2. Change the umask value to 027 and verify.
$ umask 027
$ umask
027
The new umask value will be lost when you log out of the system
unless the umask command is placed in the .profile file. This file is
discussed in detail in Module 11, Initialization Files.

8-26

Caution If terminal window is opened from the Front Panel, umask may display
incorrectly due to a known bug. This problem can be circumvented by opening a terminal
window from the Workspace Manager instead.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Exercise: Changing File Permissions
Exercise objective The purpose of this lab is to give you practice
reading permissions on files and changing permissions using symbolic
or octal notation.

Tasks
Complete or answer the following:
1. Execute the following commands:
$ mkdir ~/perm
$ cd /etc
$ cp group passwd motd vfstab dumpdates shadow ~/perm
$ cd
$ cp -r /etc/skel perm
When trying to copy /etc/shadow an error message was
displayed. Why?
___________________________________________________________
___________________________________________________________
2. Change directory to perm and complete the following table:
File or
Directory

User
Permissions

group

rw-

passwd
vfstab

Group
Permissions

Other
Permissions

Octal Value

r-rw-

skel

755
3. Create a new file and a new directory.

What are the default permissions given to the new file?


_______________________________________________________

What are the default permissions given to the new directory?


_______________________________________________________

File Security

8-27

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Exercise: Changing File Permissions
Tasks
4. In a directory with permissions of drwxr-xr--, who can perform
the following actions with the files shown below? Put an X next to
each allowed action.
-rw-r--r-user:
read___
group: read___
others: read___

modify____
modify___
modify___

delete___
delete___
delete___

execute___
execute___
execute___

-rwxrwxr-x
user:
read___
group: read___
others: read___

modify____
modify___
modify___

delete___
delete___
delete___

execute___
execute___
execute___

5. Using symbolic mode, add write permission for group to the motd
file.
___________________________________________________________
6. Using symbolic mode, remove group read on the file dumpdates.
___________________________________________________________
7. Using octal mode, change the permissions on the file motd to
rwxrw----.
___________________________________________________________
8. Using octal mode, change the permissions on the file group to add
write permission for others.
___________________________________________________________
9. Why is execute not a default permission for a newly created file?
___________________________________________________________
___________________________________________________________
10. Create a new file called memo in your practice directory.
___________________________________________________________

8-28

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Exercise: Changing File Permissions
Tasks
11. Remove the read permission for the owner from the file memo in
the practice directory. Use either symbolic or octal mode.
___________________________________________________________
What happens when you try to use the cat command to view the
memo file?
___________________________________________________________
What happens when you try to copy the memo file?
___________________________________________________________
___________________________________________________________

Workshop Labs
Use what you have learned so far in this course to work through the
following:
1. Make a directory containing some of your files available to
coworkers in your group but not to others.
2. Create a directory under your home directory called Textfiles.
3. Put a copy of four of the text files from your home directory into
the new directory.
4. Change permissions appropriately so that other users in your
group can copy files from the Textfiles directory.
5. Create a file in the directory which lists the names of all of the four
text files in the directory. Make the file modifiable by someone in
your group.

File Security

8-29

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Exercise: Changing File Permissions
Exercise Summary
Discussion Take a few minutes to discuss what experiences, issues,
or discoveries you had during the lab exercises.

Manage the discussion here based on the time allowed for this module, which was given
in the About This Course module. If you find you do not have time to spend on
discussion, then just highlight the key concepts students should have learned from the
lab exercise.

Ask students what their overall experiences with this exercise have been. You might want
to go over any trouble spots or especially confusing areas at this time.

8-30

Conclusions

Have students articulate any conclusions they reached as a result of this exercise
experience.

Interpretations

Ask students to interpret what they observed during any aspects of this exercise.

Experiences

Applications

Explore with students how they might apply what they learned in this exercise to
situations at their workplace.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Exercise: Changing File Permissions
Exercise Solutions
Complete the following steps:
1. Execute the following commands:
$ mkdir ~/perm
$ cd /etc
$ cp group passwd motd vfstab dumpdates shadow ~/perm
$ cd
$ cp -r /etc/skel perm
When trying to copy /etc/shadow an error message was
displayed. Why? Because, as a user who is not part of the sys group,
you have no permissions on this file.
2. Change directory to perm and complete the following table:
$ cd perm
$ ls -l
File or
Directory

User
Permissions

Group
Permissions

Other
Permissions

Octal Value

group

rw-

r--

r--

644

passwd

rw-

r--

r--

644

vfstab

rw-

r--

r--

644

skel

rwx

r-x

r-x

755

3. Create a new file and a new directory.

What are the default permissions given to the new file?


rw-r--r--

What are the default permissions given to the new directory?


rwxr-xr-x

File Security

8-31

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Exercise: Changing File Permissions
Exercise Solutions
4. In a directory with permissions of drwxr-xr--, who can perform
the following actions with the files shown below? Put an X next to
each allowed action.
-rw-r--r-user: read X
group:read X
others: read___

modify X delete X execute___


modify___ delete___ execute___
modify___ delete___ execute___

-rwxrwxr-x
user: read X
group: read X
others: read___

modify X delete X execute X


modify X delete___ execute X
modify___ delete___ execute___

5. Using symbolic mode, add write permission for group to the motd
file.
$ chmod g+w motd
6. Using symbolic mode, remove group read on the file dumpdates.
$ chmod g-r dumpdates
7. Using octal mode, change the permissions on the file motd to
rwxrw----.
$ chmod 760 motd
8. Using octal mode, change the permissions on the file group to add
write permission for others.
$ chmod 646 group
9. Why is execute not a default permission for a newly created file?
Most files are not binary or executable scripts. Having execute as a
default permission for a file would cause the system to see all new files as
executables.

8-32

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Exercise: Changing File Permissions
Exercise Solutions (Continued)
10. Create a new file called memo in your practice directory.
$ touch ~/practice/memo
11. Remove the read permission for the owner from the file memo in
the practice directory. Use either symbolic or octal mode.
$ chmod u-r ~/practice/memo or
chmod 244 ~/practice/memo
What happens when you try to use the cat command to view the
memo file?
You cannot use the cat command because the read permission has been
removed for the user. (Even though you are part of the group, the
permissions are looked at in the order they appear.)
What happens when you try to copy the memo file?
You cannot copy the file because, as in step 4, the user has no read
permission.

File Security

8-33

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Check Your Progress
Before continuing on to the next module, check that you are able to
accomplish or answer the following:

8-34

Display file permissions

Define permission types (read, write, and execute)

Set and change file permissions using symbolic and octal notation

Display the umask value of a file or directory

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8
Think Beyond
In your work environment, is file security an important issue? What
advantages or disadvantages are there to working in a secure
computing environment?

File Security

8-35

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

8-36

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Using the viEditor

Objectives
Upon completion of this module, you should be able to:

Differentiate between the three modes of vi and identify the


commands that belong to each mode

Start vi

Position and move the cursor in vi

Create text in vi

Delete text in vi

Copy or move text in vi

Set vi options

Exit the vi editor

Perform search and replace functions within vi

9-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

9
Relevance

Present the following question to stimulate the students and get them thinking about the
issues and topics presented in this module. While they are not expected to know the
answer to the question, the answer should be of interest to them and inspire them to learn
the content presented in this module.

Discussion Editing system files is a powerful tool for customizing


the Solaris environment. What tools would you use to edit system
files?

Additional Resources
Additional resources The following reference can provide additional
details on the topics discussed in this module:

9-2

Solaris Users Guide, Part Number 802-6499

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Introduction to vi
The visual display (vi) editor is an interactive editor that is used to
create and/or modify text files.
The vi editor uses a screen display, but you cannot use the mouse to
position the cursor.
All editing with the vi editor is done within a buffer. Changes can be
written to the disk or discarded.
It is important for users who are learning to become system
administrators to know how to use vi. It is the only full screen editor
that can be used to edit crucial system files. This skill is also needed in
case the windowing system is not available.

Depending on the instructors style, this module may be best taught by covering the basic
modes and commands of vi contained in the lecture parts of this module in a summary
fashion. The purpose of the lab for this module is to allow the students to learn vi by
using it. The lab covers in a practical fashion much of what is covered in the module,
along with some things that are not.

Using the vi Editor

9-3

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

vi Modes
There are three modes of operation in vi:

Command mode

Entry mode

Last-line mode

When you open a file with vi, you are in command mode. In this mode,
you can enter positioning and editing commands to perform functions.
While in command mode you can do advanced editing commands by
typing a colon (:), which places you at the bottom line of the screen.
This is called last-line mode. However, all commands are initiated from
command mode.

9-4

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

9
vi Modes
You must be in entry mode to enter text. To enter text, you must type a
vi insert command such as i, o, or a. This takes vi out of command
mode and puts it into entry mode. In this mode, text will not be
interpreted as editing commands. When you finish entering text in
your file, press the Escape key to return to command mode.

Return
Last-line
mode

Figure 9-1

Command
mode

i a o

Escape
Entry
mode

vi Modes

Using the vi Editor

9-5

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

9
Invoking vi
Command Format
vi [option(s)] [filename]
view [filename]

Example
To create a new file, invoke vi with a new file name by typing
$ vi filename
Table 9-1 contains commands you can use to create, edit, or view a file.
Table 9-1

vi Commands

Command

Meaning

vi filename

Open or create a file

vi

Open a new file to be named later

vi -r filename

Recover a crashed file

view filename

Open a file as read-only

vedit filename

Runs vi with set showmode automatically set. (See


Note.)

Note Running vi with set showmode displays which mode you are
in on the screen (command, insert or append mode). Caution should
be taken when using this on older dumb terminals, as some do not
consistently display the mode, even with showmode turned on.

9-6

Consider having students run vi with set showmode set from the beginning.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

9
Input Commands
To append or insert text, use the following options:
Table 9-2

Append and Insert Commands

Command

Meaning

Append text after the cursor

Append text at the end of the line

Insert text before the cursor

Insert text at the beginning of the


line

Open a new line below the cursor

Open a new line above the cursor

Using the vi Editor

9-7

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

9
Positioning Commands
The following pages list the vi editors editing and positioning
commands, which are used to make changes.
The vi editor is case sensitive, so use the specified case when using the
editing and positioning commands.
The Table 9-3 shows the key sequences for character movement:.
Table 9-3

9-8

Key Sequences

Command

Meaning

h, , or Back Space

Move left one character

j or

Move down one line

k or

Move up one line

l,, or Space bar

Move right (forward) one character

Move forward one word (including punctuation)

Move forward one word (past punctuation)

Move back one word (including punctuation)

Move back one word (past punctuation)

Move to end of current word

Move to end of line

0 (zero) or ^

Move to beginning of line

Return

Move down to beginning of next line

Move to top of screen

Move to middle of screen

Move to bottom of screen

Control-f

Page forward one screen

Control-d

Scroll down one-half screen

Control-b

Page back one screen

Control-u

Scroll up one-half screen

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

9
Editing Commands
Deleting Text
To delete text, use the following options:
Table 9-4

Text Deletion Commands

Command

Meaning

x (lowercase)

Delete character at the cursor

X (uppercase)

Delete character to the left of the cursor

dw

Delete word (or part of word to right of cursor)

3dw

Delete three words

dd

Delete line containing the cursor

3dd

Delete three lines

Delete line to right of cursor (from cursor position to


the end of the line)

dG

Delete to end of file

d1G

Delete from beginning of file to cursor

:5,10d

Delete lines 5 through 10

Using the vi Editor

9-9

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

9
Editing Commands
Undoing, Repeating, and Changing Text Commands
To change text or to cancel or repeat edit functions, use the following
commands. Many of these commands change you to Insert mode until
you press Escape.
Table 9-5

9-10

Editing Commands

Command

Meaning

cw

Change word (or part of word) at the cursor


location to the end of the word

3cw

Change three words

Overwrite or replace characters on line

Change from cursor to end of line

Substitute string for character(s)

Replace character at cursor with one other character

i (Return)

Break line

Join current line and line below

xp

Transpose character at cursor and character to the


right

Change case of letter (upper or lower) at cursor

Undo previous command

Undo all changes to current line

:u

Undo previous last-line command

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

9
Editing Commands
Copying and Pasting Text
To copy and paste text, use the following options:
Table 9-6

Copy and Paste Commands

Command

Meaning

yy

Yank a copy of line

Yank a copy of line

Put yanked or deleted line below current line

Put yanked or deleted line above current line

:1,3 co 5

Copy lines 1 through 3 and put after line 5

:4,6 m 8

Move lines 4 through 6 to line 8 (line 6 becomes line


8; line 5 becomes line 7, and line 4 becomes line 6)

Note Both delete and yank write to a buffer. When yanking, deleting,
and pasting, the put commands insert the text differently depending
on whether you are pasting a word(s) or a line(s).

Using the vi Editor

9-11

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

9
Editing Commands
Saving and Quitting Files
To save and quit a file, use the following options:
Table 9-7

9-12

Save and Quit Commands

Command

Meaning

:w

Save changes (write buffer)

:w new_filename

Write buffer to new_filename

:wq

Save changes and quit vi

ZZ

Save changes and quit vi

:q!

Quit without saving changes

:wq!

Save changes and quit vi (The ! will override read


only permissions if you are the owner of the file.)

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

9
Advanced Editing Options
The vi editor includes options for customizing your edit sessions,
such as:

Displaying line numbers

Displaying invisible characters such as tab and end-of-line


characters

The set command is used from last-line mode to control these options.
These options can also be placed in a file the user creates in their home
directory called .exrc. The set options are placed in this file, without
the preceding colon, one command to a line. Once the .exrc file exists,
it is read by the system each time a vi session is opened.
Table 9-8

Edit Session Customization Commands

Command

Meaning

:set nu

Show line numbers

:set nonu

Hide line numbers

:set ic

Instruct searches to ignore case

:set noic

Instruct searches to be case sensitive

:set list

Display invisible characters such as tab and


end-of-line

:set nolist

Turn off the display of invisible characters

:set showmode

Display current mode of operation

:set noshowmode

Turn off mode display

:set

Display all vi variables set

:set all

Display all possible vi variables and their current


settings

Using the vi Editor

9-13

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

9
Advanced Editing Options
To find a line or to search and replace and do advanced editing, use
the following options:
Table 9-9

Advanced Editing/Search Commands

Command

Meaning

Go to last line of file

1G

Go to first line of file

:21

Go to line 21

21G

Go to line 21
To clear the screen or insert files, use the following options:

Table 9-10 Clearing/Insertion Commands


Command

Meaning

Control-L

Clear (refresh) scrambled screen

:r filename

Insert (read) file at line after cursor

:34 r filename

Insert file after line 34

To search and replace text, use the following options:


Table 9-11 Search and Replace Commands

9-14

Command

Meaning

/string

Search forward for string

?string

Search backward for string

Find next occurrence of string

Find previous occurrence of string

:%s/old/new/g

Search and replace globally

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

9
Creating and Saving a File
To create a file using the vi editor:
1. Type vi filename to create the file.
2. Type i to insert text.
3. Press the Escape key to change to command mode.
4. Type :wq to write the file and exit vi.
Note The Escape key always puts you in command mode. Use the
Escape key if you are not sure what mode you are in. If you press the
Escape key while you are in command mode, the workstation beeps as
a reminder that you are already in command mode.

Using the vi Editor

9-15

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

9
Exercise: Using the vi Editor
Exercise objective In this exercise you will practice creating and
editing using vi.

Tasks
Complete the following step:
1. In your home directory there should be a file called tutor.vi.
Make sure that you are currently in your home directory, then
open this file with the command:
$ vi tutor.vi
this will open up a vi tutorial. Complete the lessons outlined in
this tutorial.

9-16

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

9
Exercise: Using the vi Editor
Exercise Summary
Discussion Take a few minutes to discuss what experiences, issues,
or discoveries you had during the lab exercises.

Manage the discussion here based on the time allowed for this module, which was given
in the About This Course module. If you find you do not have time to spend on
discussion, then just highlight the key concepts students should have learned from the
lab exercise.

Ask students what their overall experiences with this exercise have been. You might want
to go over any trouble spots or especially confusing areas at this time.

Conclusions

Have students articulate any conclusions they reached as a result of this exercise
experience.

Interpretations

Ask students to interpret what they observed during any aspects of this exercise.

Experiences

Applications

Explore with students how they might apply what they learned in this exercise to
situations at their workplace.

Using the vi Editor

9-17

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

9
Check Your Progress
Before continuing on to the next module, check that you are able to
accomplish or answer the following:

9-18

Differentiate between the three modes of vi and identify the


commands that belong to each mode

Start vi

Position and move the cursor in vi

Create text in vi

Delete text in vi

Copy or move text in vi

Set vi options

Exit the vi editor

Perform search and replace functions within vi

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

9
Think Beyond
Under what conditions might it be necessary for you to use the vi
editor in your work environment?

Using the vi Editor

9-19

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Bourne and Korn Shell Variables

10

Objectives
Upon completion of this module, you should be able to:

Set and unset shell and environment variables for the Bourne and
Korn shells

Change the PATH environment variable for the Bourne and Korn
shells

Use the which command to determine which version of a


command is being used

Use the whereis command to search for instances of a command


on a system

10-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

10
Relevance

Present the following question to stimulate the students and get them thinking about the
issues and topics presented in this module. While they are not expected to know the
answer to the question, the answer should be of interest to them and inspire them to learn
the content presented in this module.

Discussion How would it be useful to customize Bourne and Korn


shells?

Additional Resources
Additional resources The following references can provide
additional details on the topics discussed in this module:

10-2

Solaris Users Guide, Part Number 802-6499

Solaris Advanced Users Guide to System and Network Tasks,


Chapters 1 and 3, Part Number 801-4415-10.

Man pages for sh(1), ksh(1), and csh(1)

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

10

Introduction
A variable is a placeholder for information to be used by the system or
user. Information such as the default printer or a pathname to a
directory can be set up as a variable.
Two categories of variables are discussed in the following section:

Local (shell)

Global (environment)

Two key environment variables are the PATH and ENV variables.
This module covers setting and unsetting shell and environment
variables. The focus will be on the Bourne and Korn shells. Appendix
A, Features of the C Shell, covers how variables are set in the C
shell.

Bourne and Korn Shell Variables

10-3

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

10

Shell Variables
Overview
When you first log in to the host, you are placed in a predefined shell.
If you type sh (Bourne shell), ksh (Korn shell), or csh (C shell) on the
command line, a subshell is created. This process can be repeated to
create additional shells. To change to the previous shell, type exit.
Shell variables (local and global) can be either user-defined or built-in,
and can be customized by the user or predefined by the system.
Initially, when a variable is created, it is only available to its shell of
origin. This is a local variable. If a new subshell is created, the
variables created in the parent shell are not available. However, the
parent shell is still running, and when the subshell is exited, the
variables will be available again. When the shell where the variables
were created is exited, the variables of that shell are terminated. Local
variables are available only to the specific shell where they are created.

10-4

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

10
Shell Variables
Overview
To make a local variable available in all subshells, it must be exported,
either by adding it to an initialization file, as discussed in Module 11,
Initialization Files, or by exporting it on the command line.
Note See the man pages on ksh, csh, and sh for variable definitions.

Bourne and Korn Shell Variables

10-5

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

10

Shell Variables
Local Shell Variables
A user-defined variable enables you to determine both the name of the
variable and its value. For example, a pathname could be assigned for
the on-line dictionary used in text editing programs.
By convention, the Bourne and Korn shells use capital letters for shell
variable names. The first command format in the following examples
sets the variable based on a name and value selected by the user, while
the unset command removes the variable from the current shell and
subshells:

Command Format
VARIABLE=value
unset VARIABLE

10-6

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

10
Shell Variables
Local Shell Variables
Setting a Local Variable
$ DT=/usr/dict
$ echo $DT
/usr/dict
$ cd $DT
$ pwd
/usr/dict

$ unset DT
$ echo $DT
$ cd
$ cd $DT
$ pwd
/home/user2

The echo command simply echoes back to the screen whatever is


passed to it as an argument. The dollar sign ($) metacharacter
preceding a variable name enables the system to use the value of the
variable and not the name of the variable. In the above example, the
echo command with $DT displays the value of DT to the screen. Since
this is a local variable, if a new subshell is opened, the variable DT is
not available.

Bourne and Korn Shell Variables

10-7

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

10
Shell Variables
Displaying Shell Variables
Variables and their values can be displayed by typing the set
command.

Command Format
set

Displaying Variables
$ set
DISPLAY=:0.0
ERRNO=13
FCEDIT=/bin/ed
HELPPATH=/usr/openwin/lib/locale:/usr/openwin/lib/help
HOME=/home/guest
HZ=100
IFS=
LANG=C
LINENO=1
LOGNAME=guest
MAIL=/var/mail/guest
MAILCHECK=600
MANPATH=/usr/openwin/share/man:/usr/man
NOSUNVIEW=0
OPENWINHOME=/usr/openwin
PATH=/usr/openwin/bin:/usr/bin:
PPID=867
PS1=$
PWD=/home/guest
RANDOM=4188
SHELL=/bin/ksh
TERM=sun-cmd
TZ=PST8PDT
USER=guest

10-8

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

10

Environment Variables
Your computing environment is composed of special information, such
as the location of your mailbox and the type of terminal you have. The
SunOS 5.x system software provides several default environment
variables such as PS1, HOME, LOGNAME, SHELL, and PATH. These
variables have been defined by the shell to have a specific function.
The values of these customizable variables can be changed to suit the
users needs.
You can temporarily change your environment variables at the
command line. This affects only the current shell. When you exit the
shell where the environment variable has been assigned, that
environment variable is terminated or set back to its default value.
Permanent changes are made by modifying the initialization files,
discussed in Module 11, Initialization Files.
For more information on environment variables, refer to the sources
listed in the Additional Resources section of this module.
The Bourne and Korn shells use the same format for setting
environment variables.

Bourne and Korn Shell Variables

10-9

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

10
Environment Variables
Note Any shell variable can be made available as an environment
variable.

Exporting Variables
Exporting variables in an initialization file enables the variables to be
used by the system, processes, scripts, users, and all shells. Exporting
variables at the command line makes the variables available to the
current shell and all of its child processes. A variable set in a subshell
and exported will be available to any shells opened afterwards but
will not be exported to the parent shell. It is good practice to use the
echo command to check if a value for a variable already exists before
setting a new one. This protects accidental overwriting of a previously
set value.

Command Format
VARIABLE=value;export VARIABLE or
export VARIABLE=value

Creating Environment Variables


$ LPDEST=staffp; export LPDEST
$ echo $LPDEST
staffp

$ EXINIT=set showmode; export EXINIT


$ echo $EXINIT
set showmode

$ unset LPDEST
$ echo $LPDEST
$

10-10

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

10
Environment Variables
The LPDEST variable defines the default printer. EXINIT sets a last line
option for vi.
Note Setting the EXINIT variable will override any settings saved in
a .exrc file to customize the behavior of the vi editor.

Bourne and Korn Shell Variables

10-11

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

10
Environment Variables
Displaying Environment Variables
Environment variables and their values can be displayed by typing the
env command.

Command Format
env

Listing Environment Variables


$ env
_=/usr/bin/env
MANPATH=/usr/openwin/share/man:/usr/man
LANG=C
HELPPATH=/usr/openwin/lib/locale:/usr/openwin/lib/help
HZ=100
NOSUNVIEW=0
PATH=/usr/openwin/bin:/usr/bin:.
WINDOW_TERMIOS=
OPENWINHOME=/usr/openwin
LOGNAME=user1
MAIL=/var/mail/user1
TERMCAP=sun-cmd:te=\E[>4h:ti=\E[>4l:tc=sun:
DISPLAY=:0.0
SHELL=/bin/ksh
HOME=/home/user1
TERM=sun-cmd
PWD=/opt
TZ=US/Pacific
ENV=/export/home/user1/.kshrc
XINITRC=/usr/openwin/lib/Xinitrc

10-12

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

10
Environment Variables
The PATH Variable
The shell uses the PATH variable to locate commands in directories in
the order specified by the PATH statement.

Command Format
PATH=directory:directory:directory
export PATH

Setting the PATH Variable


$ PATH=/usr/bin:/usr/openwin/bin:/etc:.
$ export PATH
$ echo $PATH
/usr/bin:/usr/openwin/bin:/etc:.

The dot (.) in the PATH variable enables the system to search the
current working directory for commands.
You can also add to the existing path by typing the following:
$ PATH=$PATH:/usr/ucb
$ echo $PATH
/usr/bin:/usr/openwin/bin:/etc:.:/usr/ucb
$ export PATH

Bourne and Korn Shell Variables

10-13

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

10
Environment Variables
The which Command
An incorrectly defined PATH variable can result in users not being able
to access the right version of a command or software. Many user
problems can be traced to an incorrectly defined PATH variable.
The which command displays the pathname leading to an accessible
command based on your search path. The output will be the name of
the first directory in the PATH variable that contains the command you
are looking for. This can be very useful if a command is not giving the
expected output. Sometimes the reason for this can be that the system
is using an unexpected version of the command. If the pathname is not
displayed or is incorrect, based on your requirements, modify the PATH
variable accordingly.

Command Format
which filename

Determining the PATH Location


$ which vi
/usr/bin/vi

The whence command, which is built into the Korn shell, does the same thing as which.

The whereis Command


The whereis command can be used to add appropriate directories to
your PATH variable. Unlike which, which searches the directories
found in your PATH statement, the whereis command searches all of
the directories on the system that usually have executable files located
in them. The whereis command will display all directories where the
command is located, including the appropriate man page.

Command Format
whereis filename

10-14

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

10
Environment Variables
The whereis Command
Using the whereis Command
$ /usr/ucb/whereis vi
vi: /usr/bin/vi /usr/ucb/vi /usr/man/man1/vi.1
If the whereis command is not found, use /usr/ucb/whereis to run
the command.

Bourne and Korn Shell Variables

10-15

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

10
Exercise: Using Bourne and Korn Shell Variables
Exercise objective In this exercise, you will use the concepts taught
in this module to determine the settings of local and environmental
variables and create a custom variable.

Tasks
Complete the following steps:
1. Create a shell variable, NAME, with your name as its value. Display
the value of the new variable.
2. Start another Korn shell.
Does the subshell recognize the variable NAME? Why or why not?
___________________________________________________________
3. Exit the subshell. Display the value of the NAME variable. Is the
variable set?
___________________________________________________________
4. Make the NAME variable an environmental variable and open
another subshell. Does the subshell recognize the value of NAME
this time?
___________________________________________________________
5. List all of the environment variables. Is NAME an environmental
variable?
___________________________________________________________
6. Determine how your current PATH variable is set.
7. Add the /usr/ucb directory to your path and export the variable.

10-16

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

10
Workshop Labs
Use what you have learned so far in this course to work through the
following:
1. Making new directories many levels down in the heirarchy can
require a lot of typing. Using the information presented in this
module about system variables, create a subdirectory in the
coffees directory.

Bourne and Korn Shell Variables

10-17

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

10
Exercise: Using Bourne and Korn Shell Variables
Exercise Summary
Discussion Take a few minutes to discuss what experiences, issues,
or discoveries you had during the lab exercises.

Manage the discussion here based on the time allowed for this module, which was given
in the About This Course module. If you find you do not have time to spend on
discussion, then just highlight the key concepts students should have learned from the
lab exercise.

Ask students what their overall experiences with this exercise have been. You might want
to go over any trouble spots or especially confusing areas at this time.

10-18

Conclusions

Have students articulate any conclusions they reached as a result of this exercise
experience.

Interpretations

Ask students to interpret what they observed during any aspects of this exercise.

Experiences

Applications

Explore with students how they might apply what they learned in this exercise to
situations at their workplace.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

10
Exercise: Using Bourne and Korn Shell Variables
Exercise Solutions
Complete the following steps:
1. Create a shell variable, NAME, with your name as its value. Display
the value of the new variable.
$ NAME=name
$ echo $NAME
2. Start another Korn shell.
$ ksh
Does the subshell recognize the variable NAME? Why or why not?
$ echo $NAME
No, because the variable was only local to the shell it was created in.
3. Exit the subshell. Display the value of the NAME variable. Is the
variable set?
$ exit
$ echo $NAME
Yes, as this is the shell in which the variable was originally set.
4. Make the NAME variable an environmental variable and open
another subshell. Does the subshell recognize the value of NAME
this time?
$ export NAME
$ ksh
$ echo $NAME
Yes
5. List all of the environment variables. Is NAME an environmental
variable?
$ env
Yes, NAME should be an environmental variable.

Bourne and Korn Shell Variables

10-19

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

10
Exercise: Using Bourne and Korn Shell Variables
Exercise Solutions
6. Determine how your current PATH variable is set.
$ echo $PATH
7. Add the /usr/ucb directory to your path and export the variable.
$ PATH=$PATH:/usr/ucb; export PATH

10-20

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

10
Check Your Progress
Before continuing on to the next module, check that you are able to
accomplish or answer the following:

Set and unset shell and environment variables for the Bourne and
Korn shells

Change the PATH environment variable for the Bourne and Korn
shells

Use the which command to determine which version of a


command is being used

Use the whereis command to search for instances of a command


on a system

Bourne and Korn Shell Variables

10-21

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

10
Think Beyond
Setting variables at the command line every time you log in can be
tedious. How could you make these variable definitions a permanent
part of your environment? How might a system administrator define
variables for all users on a system?

10-22

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Initialization Files

11

Objectives
Upon completion of this module, you should be able to:

Name the different initialization files for the Bourne, Korn, and C
shells

Identify the initialization file used by the Common Desktop


Environment

Define the purpose of initialization files

Describe where the initialization files are located and what types
of settings can be defined

Set the ENV variable to enable the .kshrc file to be read

11-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

11
Relevance

Present the following question to stimulate the students and get them thinking about the
issues and topics presented in this module. While they are not expected to know the
answer to the question, the answer should be of interest to them and inspire them to learn
the content presented in this module.

Discussion Certain types of information, such as your default


printer, are set each time you log in. What other types of customizable
settings could be set at the beginning of each session?

Additional Resources
Additional resources The following references can provide
additional details on the topics discussed in this module:

11-2

Solaris Users Guide, Part Number 802-6499

Solaris Advanced Users Guide to System and Network Tasks,


Chapters 1 and 3, Part Number 801-4415-10

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

11

Features of Initialization Files


Overview
Initialization files contain a series of commands and variable settings
that are executed when a shell is started. These files customize the
environment for the system and the user.
There are two levels of initialization files. The first level is systemwide. System initialization files are maintained by a system
administrator and reside in the /etc directory.

Initialization Files

11-3

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

11
Features of Initialization Files
Overview
The second level is user-specific initialization files that reside in a
users home directory. These files are listed in Table 11-1.
Table 11-1 User-Specific Initialization Files
Shell

System-Wide
(Read First)

User-Specific
(Read Second)

Bourne

1. /etc/profile

2. $HOME/.profile

Korn

1. /etc/profile

2. $HOME/.profile
ENV=$HOME/.kshrc;export ENV
3. $HOME/.kshrc

1. /etc/.login

2. $HOME/.login
3. $HOME/.cshrc
4. $HOME/.logout

Note ENV is a variable that is set in the .profile file to direct the
system to read an alternate initialization file. $HOME is the users home
directory.
When a predefined environment variable is placed in one of the
system-wide initialization files, it is recognized globally in any shell or
subshell. Users can customize many of these variables for their own
environment by placing them in the initialization files in their home
directory. To make the customizations available to all subsequent
shells, the variable must be exported. Unlike variables, commands
cannot be exported. If commands are used in the initialization files,
they must be placed in the secondary initialization files in order to be
read each time a subshell is opened.

11-4

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

11

Features of Initialization Files


The /etc/profile Script
When a Bourne or Korn shell user logs in, the system reads the
/etc/profile file first, and then it reads the users .profile file,
and, for Korn shell users, the .kshrc file. This means that the users
preferences for variable settings can override the default settings that
appear in the /etc/profile file.
The /etc/profile file:

Exports environment variables such as LOGNAME for login name

Exports PATH for the default command path

Sets the variable TERM for the default terminal type

Displays the contents of the /etc/motd file

Sets the default file creation permissions

Checks if you have mail and will print a mail message upon login

This file is maintained by the system administrator.


Initialization Files

11-5

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

11

User-Specific Initialization Files


Login Sequence
When you log in to your system, the system and users initialization
files for the appropriate shell are read, and the tasks defined in the
initialization files are executed.
The initialization files provide great flexibility to the user for
customizing their environment. Generally, these files are set up as
templates by the system administrator, and then modified by the user.

11-6

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

11
User-Specific Initialization Files
Login Sequence
The user-specific initialization file(s) are stored in the home directory
of the user. These initialization files can perform all or part of the
following:

Set the default prompt

Define the default printer

Set default permissions

Set the default terminal type used by vi and other tools

Tell the shell where to look for new mail

Set noclobber to prevent overwriting of files during redirection

Set the command path to the users specification

Set up custom commands

Initialization Files

11-7

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

11
User-Specific Initialization Files
Login Sequence

Log in
/etc/profile

Log out

$HOME/.profile
$HOME/.kshrc

exit

ksh

Open

subshell

$HOME/.kshrc
exit

ksh

Open

subshell

$HOME/.kshrc
ksh

Figure 11-1

11-8

exit

Solaris Login Sequence

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

11
User-Specific Initialization Files
Login Sequence
When you first log in to the system, you are placed in the default shell
as defined by the /etc/passwd entry for your account.
As described in Module 10, Bourne and Korn Shell Variables, if a
new subshell is created by entering the command sh (Bourne shell),
ksh (Korn shell), or csh (C shell), a subshell is created. This process
can be repeated to create additional subshells. To change to the
previous shell, type exit or press Control-d.
The initialization files are read as shown in Table 11-2. The .profile,
.kshrc, .login, and .cshrc files are assumed to be in the users
home directory.
Table 11-2 Initialization Files Read Process
Shell

Read During Login

Bourne

/etc/profile and .profile

Korn

/etc/profile, .profile, and


.kshrc

.kshrc

/etc/.login, .cshrc, and .login

.cshrc

Initialization Files

Read Opening Shell

11-9

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

11

User-Specific Initialization Files


The .dtprofile
For CDE users there is another initialization file called .dtprofile
which resides in the users home directory and determines settings for
CDE. This file is generally set up to be standard system wide and is
created in a users home directory the first time the user logs in to
CDE. In versions of CDE shipped with Solaris 2.6 and later, the
.dtprofile causes the system to read a Korn shell users .kshrc file
each time a terminal window is opened within CDE, and the
.profile and .kshrc files each time a console window is opened.
Both initialization files are also read when CDE initially starts up.
For versions of CDE shipped with versions of Solaris earlier than 2.6, it
was necessary to make changes to the .profile or .login files as
recommended within the standard .dtprofile, and then uncomment
(remove the # sign from in front of) the line reading
DTSOURCEPROFILE=true.

11-10

If DTSOURCEPROFILE line is commented out, none of the initialization files are read (with the
exception of .dtprofile).

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

11

User-Specific Initialization Files


Shells
The login shell is assigned by the system administrator as part of
creating a user account. The login shell determines which initialization
files are read during login.

Bourne Shell
The Bourne shell uses .profile, a user-specific initialization file to
set the users environment. The .profile file is only read once during
login.

Initialization Files

11-11

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

11
User-Specific Initialization Files
Shells
Korn Shell
The Korn shell uses two user-specific environment files to set the
users environment:

.profile

.kshrc

When you log in to the system, the .profile file is read. Then, if the
ENV variable in the .profile file is assigned and exported, the
.kshrc file is read. The .profile file is only read once, while the
.kshrc file is read every time a new Korn shell is opened.
Many Korn shell commands cannot be executed by the Bourne shell
and therefore should not be placed in the .profile file. These Korn
shell specific commands and features should be placed in the .kshrc
file.
The contents of the .kshrc file, discussed in detail in Module 12,
Basic Features of the Korn Shell, can include

A customized prompt

Custom variables

Aliases

To have the system reread the .kshrc or .profile file after changes
have been made, the user can either log out and log back in, or type
the following from the command line:
$ . ~/.kshrc
$ . ~/.profile

11-12

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

11
User-Specific Initialization Files
Shells
C Shell
The C shell uses two user-specific environment files to set the users
environment:

.login

.cshrc

Both files are located in the users home directory. The .login file is
read only when a user logs in to the system, whereas the .cshrc file is
read each time a user invokes the C shell.
To have the system reread the .login or .cshrc file after changes
have been made, the user can either log out and log back in, or type
the following from the command line:
% source ~/.login
% source ~/.cshrc

Initialization Files

11-13

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

11

The ENV Environment Variable


The ENV variable defines the path to the .kshrc file. This variable must
be stored in the .profile file to inform the system that the.kshrc file
exists and is to be read when creating a Korn shell.

Command Format
ENV=$HOME/filename; export ENV

Setting the .kshrc Variable


$ ENV=$HOME/.kshrc; export ENV

This command sets the environment variable to point to the .kshrc


file in the $HOME directory. HOME is a variable that is defined by the
system to be the absolute path to the users login directory. Preceding
the HOME variable with the dollar sign ($) metacharacter enables the
system to use the value of HOME in the specified location.

11-14

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

11
The ENV Environment Variable
When the ENV variable is placed in the .profile file and read by other
shells (such as the Bourne shell), it does not act as a pointer to the
.kshrc file. This variable has no meaning outside of the Korn shell.

Initialization Files

11-15

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

11
Exercise: Setting Initialization Files
Exercise objective In this exercise, you will demonstrate an
understanding of the concepts covered in this module.

Tasks
Write the information requested in the space provided.
1. What is an initialization file?
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
2. Where are the user-specific initialization files stored?
___________________________________________________________
3. Name the user-specific initialization files for the Korn and C shells.
___________________________________________________________
___________________________________________________________
4. What is the initialization file for CDE called?
___________________________________________________________
5. Describe or name at least three settings that can be stored in the
.profile or .login initialization file for each shell.
___________________________________________________________
___________________________________________________________
___________________________________________________________
6. Describe or name at least two settings that can be stored in the
.kshrc or .cshrc file.
___________________________________________________________
___________________________________________________________

11-16

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

11
Exercise: Setting Initialization Files
Exercise Summary
Discussion Take a few minutes to discuss what experiences, issues,
or discoveries you had during the lab exercises.

Manage the discussion here based on the time allowed for this module, which was given
in the About This Course module. If you find you do not have time to spend on
discussion, then just highlight the key concepts students should have learned from the
lab exercise.

Ask students what their overall experiences with this exercise have been. You might want
to go over any trouble spots or especially confusing areas at this time.

Conclusions

Have students articulate any conclusions they reached as a result of this exercise
experience.

Interpretations

Ask students to interpret what they observed during any aspects of this exercise.

Experiences

Applications

Explore with students how they might apply what they learned in this exercise to
situations at their workplace.

Initialization Files

11-17

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

11
Exercise: Setting Initialization Files
Exercise Solutions
Write the information requested in the space provided.
1. What is an initialization file?
An initialization file is an environment file that generally resides in the
users home directory and is used to customize the users environment.
2. Where are the user-specific initialization files stored?
User-specific initialization files are stored in the users home directory.
3. Name the user-specific initialization files for the Korn and C shells.
.profile and .kshrc (Korn shell) and .login and .cshrc (C shell)
4. What is the initialization file for CDE called?
.dtprofile
5. Describe or name at least three settings that can be stored in the
.profile or .login initialization file for each shell.
Time zone, terminal type, PATH, users login name, default printer, local
language, and where shell should look for new mail and environment
variables.
6. Describe or name at least two settings that can be stored in the
.kshrc or .cshrc file.
Aliases, history, and a customized prompt.

11-18

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

11
Check Your Progress
Before continuing on to the next module, check that you are able to
accomplish or answer the following:

Name the different initialization files for the Bourne, Korn, and C
shells

Identify the initialization file used by the Common Desktop


Environment

Define the purpose of initialization files

Describe where the initialization files are located and what types
of settings can be defined

Set the ENV variable to enable the .kshrc file to be read

Initialization Files

11-19

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

11
Think Beyond
What kinds of settings and customizations would you put into your
initialization files at work?

11-20

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Basic Features of the Korn Shell

12

Objectives
Upon completion of this module, you should be able to:

Use basic shell quoting

Customize the Korn shell

Customize commands in the Korn shell using the alias command

Review previously executed commands in the Korn shell using the


history command

Set the command-line editor and edit previously issued


commands

12-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12
Relevance

Present the following question to stimulate the students and get them thinking about the
issues and topics presented in this module. While they are not expected to know the
answer to the question, the answer should be of interest to them and inspire them to learn
the content presented in this module.

Discussion What customizations do you perform repetitively that


you would like to set automatically?

Additional Resources
Additional resources The following references can provide
additional details on the topics discussed in this module:

12-2

Solaris Users Guide, Part Number 802-6499

Solaris Advanced Users Guide to System and Network Tasks,


Chapters 1 and 3, Part Number 801-4415-10

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12

Korn Shell Overview


The Korn shell uses the Bourne shell as a basis for its features. These
shared features include a login initialization file and variables. In
addition, the Korn shell provides command tracking, command-line
editing, and command substitution.
The initialization file used for storing this information is the .kshrc
file.
To learn about comparable features in the C shell, see Appendix A,
Features of the C Shell.
Note The Bourne shell does not offer history, command-line editing,
or aliasing features.

Basic Features of the Korn Shell

12-3

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12
Korn Shell Features
Quoting in Shells
Use a dollar sign ($) to expand the value of a variable.
$ echo $PATH
/usr/bin:/usr/ucb:/etc:.
Use back quotation marks (`. . .`) to substitute the output of a
command rather than reading the enclosed text literally.
$ WO=`uname -n`
$ echo $WO
venus
$
Use single quotation marks (...) to identify text literally. Single
quotes do not enable command substitution or variable expansion.
$ echo ***host is $WO*** `date`***
***host is $WO***`date`***
$
Use double quotation marks (. . .) to identify text literally and also to
enable variable expansion and command substitution.
$ echo "***host is $WO*** `date`***"
***host is venus*** Jul 4 11:05:31 PDT 1999***
$
Use a backslash (\) to prevent the shell from interpreting the next
character (including a <return>).
$ echo \$WO
$ $WO
or
$ echo "This is Fred, \<return>
> he works here."
$ This is Fred, he works here.

12-4

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12

Korn Shell Features


Custom Prompts
PS1 is a predefined prompt variable that users can customize. PS1 can
include a wide range of expressions such as character strings,
commands, or other variables.

Command Format
PS1=value

Customizing Your Prompt


$ PS1="Good morning$ "
Good morning$ PS1="`uname -n` !$ "
saturn 41$ MSG="Had coffee yet?"
saturn 42$ PS1="$MSG "
Had coffee yet? PS1="$ "
$

Basic Features of the Korn Shell

12-5

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12
Korn Shell Features
Custom Prompts
The first line of this example assigns the prompt to the conventional $
with a character string (Good morning). The second line demonstrates
using a command (uname -n) with the history line indicator (!) for a
unique prompt. This command will show the name of the host on
which you are working. The third line sets a variable and the fourth
line uses the variables value for the prompt.
The prompt can also be customized to reflect the current working
directory.
$ pwd
/home/user2
$ PS1=$PWD $
/home/user2 $
The variable PS1 is a shell variable. Any change in the variable setting
will remain until the shell is exited or until a subshell is opened. To
make the customized prompt available from session to session, place
the PS1 variable in the .kshrc file.

12-6

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12

Korn Shell Features


Aliases
Aliases provide an excellent way to:

Substitute a short command for a long one

Create a single command for a series of commands

Create alternate forms of existing commands

Change a command set

Command Format
alias aliasname=value

Basic Features of the Korn Shell

12-7

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12
Korn Shell Features
Aliases
Creating Aliases
$
$
$
$
$
$

alias
alias
alias
alias
alias

h=history
c=clear
home=cd;ls
ls=ls -l
copy=cp -i

When set from the command line, aliases are only activated for the
shell in which they are created. Add aliases to your .kshrc file to
activate them upon login or whenever a new window or shell is
opened.
To display aliases, use the alias command with no argument.

Displaying All Aliases Set for the Current Session


Some of the aliases are set system wide as part of the Korn shell.
$ alias
autoload=typeset -fu
bye=exit
c=clear
copy=cp -i
functions=typeset -f
h=history
history=fc -l
home=cd;ls
integer=typeset -i
ls=ls -l
r=fc -e -
stop=kill -STOP
suspend=kill -STOP $$
type=whence -v
$

12-8

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12
Korn Shell Features
Aliases
Removing an Alias in the Current Shell
You can unset a previously defined alias with the unalias command.

Command Format
unalias aliasname

Unsetting a Previously Defined Alias


$ unalias bye
$ alias
autoload=typeset -fu
copy=cp -i
functions=typeset -f
h=history
history=fc -l
home=cd;ls
integer=typeset -i
ls=ls -l
r=fc -e -
stop=kill -STOP
suspend=kill -STOP $$
type=whence -v
$
To temporarily bypass an alias, use a backslash.
$ \ls dir1/coffees
$ nuts brands

Basic Features of the Korn Shell

12-9

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12

History in the Korn Shell


Overview
The history feature records commands typed in the Korn shell.
In the Korn shell, history is automatically set up as a default when
the user first enters the shell. Whenever the user types in a command,
this function records it on a history list. The history list is stored in the
users home directory in a file named ~/.sh_history.
By default, the Korn shell keeps a record of the last 128 commands
entered.
The default history file variables are

12-10

HISTFILE=$HOME/.sh_history

HISTSIZE=128

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12
History in the Korn Shell
Overview
You can change the defaults and place them in the .profile file.
Remember that even though these changes are placed in the .profile
file, they are specific to the Korn shell only, since the Bourne shell does
not have a history feature.
Note The HISTFILE and HISTSIZE variables are encoded in the
/bin/ksh program. Unless you change the default settings, no output
is given for the value of these variables.

Basic Features of the Korn Shell

12-11

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12

History in the Korn Shell


The history Command
The history command displays previously entered commands to the
screen. The default display length is 16 commands.

Command Format
history [options]
Specifying a number preceded by a dash as an option will display that
number of lines. Specifying a number without a dash will show the
history lines from that number to the last command entered.

12-12

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12
History in the Korn Shell
The history Command
Displaying History
$ history
11
pwd
12
cat dante
13
ls ~/dir1
14
cat feathers
15
cd dir1
16
ls
17
cd ../dir3
18
ls planets
19
ls vegetables
20
cd
21
pwd
22
ls
23
cd /usr/dict
24
cd
25
more /etc/passwd
26
history
$ history -3
24
cd
25
more /etc/passwd
26
history
27
history -3

Basic Features of the Korn Shell

12-13

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12

History in the Korn Shell


Re-Executing Commands
The r is a custom command (alias) in the Korn shell. This enables the
user to re-execute commands from the history list.

Command Format
r [argument(s)]
The argument passed to the r command is the history line number of
a particular command, or a letter indicating the most recent command
in the history list that started with that letter.

12-14

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12
History in the Korn Shell
Re-Executing Commands
$ pwd
/home/user2
$ r
pwd
/home/user2
$ history 27
27 cd /usr/dict
28 history 23
29 history 22 24
30 pwd
31 pwd
32 cd ~
$ r 27
cd /usr/dict
$ pwd
/usr/dict
$ pwd
/usr/dict
$ r p
pwd
/usr/dict

Basic Features of the Korn Shell

12-15

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12

History in the Korn Shell


Editing the Command Line
The in-line edit mode enables you to edit a previous command on the
current command line. Use vi commands to move and edit the
previous command line.

Command Format
set [-+]o vi
Using set -o vi turns command-line editing on, while set +o vi
turns it off. Once the editing has been turned on, pressing the Esc key
activates the in-line editor. You then have access to vi commands.

12-16

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12
History in the Korn Shell
Editing the Command Line
$ more /usr/dict/worfs
/usr/dict/worfs: No such file or directory
$ set -o vi
(Press the Esc key and then the k key until the
desired command displays then edit
appropriately.)
$ more /usr/dict/words
The following vi commands can be used to edit a command line. In
the above example, the user used the editing feature to change worfs
to words. The Return key is pressed after all changes are made.
Table 12-1 Command Line Edit Commands
vi Command

Meaning

Move backward through history list

Move forward through history list

Move to the right one character

Move to the left one character

Replace one character

cw

Change word

Delete one character

Note The arrow keys cannot be used to reposition the cursor during
in-line editing.

Basic Features of the Korn Shell

12-17

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12
Additional Features of the Korn Shell
Table 12-2 identifies some of the features of each shell available in the
Solaris 7 environment.
Table 12-2 Solaris Shell Features
Feature

Bourne

Korn

Use aliases

No

Yes

Yes

Support command-line editing

No

Noa

Yes

Support history list

No

Yes

Yes

Ignore Control-d (ignoreeof)

No

Yes

Yes

Separate initialization file from


.profile

No

Yes

Yes

Have job control (ability to move job to


and from the background and
foreground for processing; ability to
suspend a job)b

No

Yes

Yes

Logout file

No

Yes

No

Protect files from overwriting


(noclobber)

No

Yes

Yes

The C shell has a form of command-line editing called command substitution. It is not
capable of editing a full line, but rather substitutes one character for another.
bCovered in detail in Module 16, System Processes & Memory Management.

The set command can be used with the ignoreeof and noclobber
arguments as shown previously with command-line editing. Use
set -o to turn a feature on and set +o to turn it off.

12-18

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12
Exercise: Using the Basic Features of the Korn Shell
Exercise objective In this exercise, you will use the Korn shell
features discussed in this module to create aliases; display, re-execute,
and edit previously entered commands; and customize your .kshrc
file.

Tasks
Be sure you do the following exercises in the Korn shell:
1. Create an alias that changes to your home directory and then
prints the absolute pathname of the directory.
2. Test the alias created in step 1.
3. Create an alias called del that will prompt for confirmation
whenever you delete a file.
4. Test the alias created in step 3 by deleting the memo file in the
~/practice directory.
5. Create an alias that will display a long listing of directory contents.
6. Type the command that displays your list of aliases.
7. Delete the alias called del.
8. Change to your home directory. Be sure you are in the Korn shell.
9. Type an ls command and the appropriate option that will display
the file and directory names of any length that end with the
letter s.
10. Display the history list and then re-execute the previous ls
command.
11. Use the ls command and output redirection to create a file called
dir.list.
12. Use the cat command to display the file created in step 11.

Basic Features of the Korn Shell

12-19

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12
Exercise: Using the Basic Features of the Korn Shell
Tasks
13. Use in-line editing (set -o vi) to change the cat command in
the previous command to ls.
14. Create an alias called star that will change the current directory
to ~/dir3/planets and list its contents.
15. Alter your PATH statement in the appropriate initialization file to
include your personal binary directory.

Workshop Labs
Use what you have learned so far in this course to work through the
following:
1. Create a .kshrc file, if one does not already exist. Put the
following into it:
a.

A feature that keeps the system from overwriting a file during


redirection.

b. Two aliases to shortcut commands that you use frequently.


c.

A feature that sets command-line editing for future login


sessions.

2. Make sure the appropriate variable is in the .profile file so that


the .kshrc is read when you log in to the system.
3. Have the system reread the two initialization files and test your
new aliases and PATH statement.

12-20

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12
Exercise: Using the Basic Features of the Korn Shell
Exercise Summary
Discussion Take a few minutes to discuss what experiences, issues,
or discoveries you had during the lab exercises.

Manage the discussion here based on the time allowed for this module, which was given
in the About This Course module. If you find you do not have time to spend on
discussion, then just highlight the key concepts students should have learned from the
lab exercise.

Ask students what their overall experiences with this exercise have been. You might want
to go over any trouble spots or especially confusing areas at this time.

Conclusions

Have students articulate any conclusions they reached as a result of this exercise
experience.

Interpretations

Ask students to interpret what they observed during any aspects of this exercise.

Experiences

Applications

Explore with students how they might apply what they learned in this exercise to
situations at their workplace.

Basic Features of the Korn Shell

12-21

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12
Exercise: Using the Basic Features of the Korn Shell
Exercise Solutions
Be sure you do the following exercises in the Korn shell.
1. Create an alias that changes to your home directory and then
prints the absolute pathname of the directory.
$ alias home=cd;pwd
2. Test the alias created in step 1.
$ home
3. Create an alias called del that will prompt for confirmation
whenever you delete a file.
$ alias del=rm -i
4. Test the alias created in step 3 by deleting the memo file in the
~/practice directory.
$ del ~/practice/memo
5. Create an alias that will display a long listing of directory contents.
$ alias long=ls -l
6. Type the command that displays your list of aliases.
$ alias
7. Delete the alias called del.
$ unalias del
8. Change to your home directory.
$ cd

12-22

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12
Exercise: Using the Basic Features of the Korn Shell
Exercise Solutions
9. Type an ls command and the appropriate option that will display
the file and directory names of any length that end with the
letter s.
$ ls -d *s
10. Display the history list and then re-execute the previous ls
command.
$ history
$ r command_number or $ r l
11. Use the ls command and output redirection to create a file called
dir.list.
$ ls > dir.list
12. Use the cat command to display the file created in step 11.
$ cat dir.list
13. Use in-line editing (set -o vi) to change the cat command in
the previous command to ls.
$ set -o vi
Press the Esc key and then press k twice. Change cat to ls.
14. Create an alias called star that will change the current directory
to ~/dir3/planets and list its contents.
$ alias star=cd ~/dir3/planets;ls
15. Alter your PATH statement in the appropriate initialization file to
include your personal binary directory.
$ vi .profile
add a line that reads
PATH=$PATH:$HOME/bin

Basic Features of the Korn Shell

12-23

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12
Check Your Progress
Before continuing on to the next module, check that you are able to
accomplish or answer the following:

12-24

Use basic shell quoting

Customize the Korn shell

Customize commands in the Korn shell using the alias command

Review previously executed commands in the Korn shell using the


history command

Set the command-line editor and edit previously issued


commands

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

12
Think Beyond
What advantages/disadvantages can you think of for changing your
prompt and adding aliases? In your work environment, are any aliases
already preset by your system administrator?

Basic Features of the Korn Shell

12-25

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Printing

13

Objectives
Upon completion of this module, you should be able to:

Use command-line commands to print a file, check print queue


status, and cancel a print request

Print using the Print Manager in CDE

Determine and change the default printer

Set print options

Demonstrate the major functions of the Print Manager

13-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13
Relevance

Present the following question to stimulate the students and get them thinking about the
issues and topics presented in this module. While they are not expected to know the
answer to the question, the answer should be of interest to them and inspire them to learn
the content presented in this module.

Discussion What printing-related tasks do you need to do besides


sending a single file to a printer?

13-2

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13

Command Line Printing


Printing of ASCII text or PostScript files can be done from the
command line. Do not use this method to print data files (files created
in applications like FrameMaker) or binary files.
The function of the lp command is to queue data for printing.

The Solaris computing environment supports the lp print spooler.

Command Format
lp [ -options] [filename(s)]
Options
-d

Specifies the desired printer. (If you are printing


to your default printer, the -d option is not
necessary.)

-o nobanner

Specifies that banner page is not to be printed.

-n

Prints a specified number of copies.

-m

Sends mail message to user after job is complete.

Printing

13-3

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13
Printing a File
Sending Files to a Printer
Print the file feathers in your home directory on the default printer.
$ lp ~/feathers
request id is printer1-7 (1 file(s))
$
Use the -d option to specify another printer (if one is available).
$ lp -d staffp ~/feathers
request id is staffp-8 (1 file(s))
$

13-4

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13

Displaying Printer Status and Queues


Use the lpstat command to display the status of the printer queue.

Command Format
lpstat [-options]
Options
-p

Prints status of all printers

-o

Prints the status of all output requests

-d

Prints which printer is the system default

-t

Prints complete status information for all


printers

-s

Prints a status summary for all printers

-a

Prints which printers are accepting requests

Printing

13-5

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13
Displaying Printer Status and Queues
Note When a print request has been sent to the printer, the output of
lpstat may show the print request as filtered. (This is not the case in
the lab environment for this course.) Filtering indicates a print request
is in the process of printing. The name of the print request does not
appear when the lpstat command is used.

Displaying the Status of All of Your Output Requests


$ lpstat -o
printer1-7 user2 391 Dec 10 16:30 on printer1
staffp-2 user2 551 Dec 10 16:45 filtered
$

Displaying Requests on a Specific Printers Queue


$ lpstat staffp
staffp-2 user2 551 Dec 10 16:45
staffp-3 user3 632 Dec 10 16:47
$

Determining the Status of All Configured Printers


$ lpstat -t
scheduler is running
system default destination: printer1
system for printer1: venus
system for staffp: mars
printer1 accepting requests since Wed May 6 08:20:00 EST 1998
staffp accepting requests since Mon May 25 09:43 EST 1998
$

13-6

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13
Displaying Printer Status and Queues
Determining Which Printers Are Configured on Your System
$ lpstat -s
scheduler is running
system default destination: printer1
system for printer1: venus
system for staffp: mars
$

Displaying Which Printers Are Accepting Requests


$ lpstat -a
printer1 accepting requests since Wed May 6 08:20:00 EST 1998
staffp accepting requests since Mon May 25 09:43:19 PST 1998
$

Printing

13-7

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13

Removing a Print Request


The cancel command enables you to cancel print requests previously
sent with the lp command. To do this, you must first use the lpstat
command to identify the request-ID.

Command Format
cancel request-ID

Canceling a Print Request


$ lpstat staffp
staffp-2 user2 551
Dec 10 16:45 on staffp
staffp-3 user3 632
Dec 10 16:47
$ cancel staffp-3
request "staffp-3" cancelled
$

13-8

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13
Removing a Print Request
Canceling a Print Request
Use the cancel -u username (login ID) to remove all requests
owned by you.
$ cancel -u user2
request "staffp-2" cancelled
$
Note You cannot remove another users print request. Only the
superuser can remove a print request sent by another user. When
using the CDE Printer Manager, it appears you can cancel anothers
print job, but the job is immediately reinstated.

Printing

13-9

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13

Printer Jobs
The Printer Jobs window displays a list of the current printer and any
outstanding print requests in the print queue.
Only one printer icon will be displayed in the Printer Jobs window.
This represents the printer chosen by the user (which may or may not
be the same as the system default printer).

13-10

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13
Printer Jobs
Printer Jobs

Printing

13-11

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13

Viewing Printer Properties


When the printer icon is selected, you can display the properties of
your default printer by choosing the Selected Properties menu
option. A window will be displayed which provides details regarding
that printer.

13-12

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13
Viewing Printer Properties
You can change the label name associated with the printer using the
Printer Properties window. Also, if the printer has been disabled, or
there is a problem with the printer, this window will display
information regarding the problem.

Printing

13-13

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13
Setting Printer Job Options
The View Set Options menu choice enables you to configure how the
print queue requests are displayed.

13-14

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13
Setting Printer Job Options
You can also set the time interval that the Print Manager uses to check
the current print queue, as shown in the following illustration:

Printing

13-15

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13

Printing From the File Manager


You can print a file from the File Manager window by dragging and
dropping it on the Print Manager icon or dropping the object directly
into the Print Manager window.
Once the file object has been dropped into the Print Jobs window,
another window will be displayed in which you can:

Designate an alternative printer to print the file

Designate the number of copies of the file to be printed

Set a banner title (which will be displayed in the Print Manager


window alongside the print object)

Select specific pages to print

Designate which UNIX print command options should be used as


an alternative to the default print command.

Once the Print button is selected, the file will be sent to the
appropriate printer queue.

13-16

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13
Printing From the File Manager

Printing

13-17

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13
Displaying the Banner Page Title
When a banner page title has been entered for a print request, that text
will be displayed in the Print Manager window. The name of the user
who submitted the print request will be displayed below the banner
text.

13-18

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13

Canceling a Print Request


To cancel a print request, you must first select the Print Manager
display object corresponding to that print request.
Once the object has been selected, use the Selected Cancel menu
options.
You will be asked to confirm that you want to have the print request
cancelled, as shown in the following illustration. Again, you can only
cancel your own print requests.

Printing

13-19

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13
Canceling a Print Request
If you attempt to cancel another users print job from the Print
Manager, the print job will reappear in the printer queue.

13-20

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13
Exercise: Printing Files
Exercise objective In this exercise you will use the print commands
learned in this module to print a file.

Tasks
Complete or answer the following:
1. Files can be printed by dragging a File Manager file object on to
the Default Printer icon (on the Front Panel) or into the Printer
Jobs window, true or false?
___________________________________________________________
2. Print requests can only be sent to the system default printer, true
or false?
___________________________________________________________
3. Only the system administrator can cancel print requests, true or
false?
___________________________________________________________
4. From the command line, what command would you use to see if a
printer was accepting requests?
___________________________________________________________
5. An alternate printer can be designated from the command line,
true or false?
___________________________________________________________
6. Using the lp command, print the dante file on the default printer.
7. From the command line, check the status of the previously sent
print request.

Printing

13-21

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13
Exercise: Printing Files
Exercise Summary
Discussion Take a few minutes to discuss what experiences, issues,
or discoveries you had during the lab exercises.

Manage the discussion here based on the time allowed for this module, which was given
in the About This Course module. If you find you do not have time to spend on
discussion, then just highlight the key concepts students should have learned from the
lab exercise.

Ask students what their overall experiences with this exercise have been. You might want
to go over any trouble spots or especially confusing areas at this time.

13-22

Conclusions

Have students articulate any conclusions they reached as a result of this exercise
experience.

Interpretations

Ask students to interpret what they observed during any aspects of this exercise.

Experiences

Applications

Explore with students how they might apply what they learned in this exercise to
situations at their workplace.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13
Exercise: Printing Files
Exercise Solutions
1. Files can be printed by dragging a File Manager file object on to
the Default Printer icon (on the Front Panel) or into the Printer
Jobs window, true or false?
True
2. Print requests can only be sent to the system default printer, true
or false?
False; If other printers are available to your system, you can designate the
printer for each print job.
3. Only the system administrator can cancel print requests, true or
false?
False; A user can cancel his or her own job.
4. From the command line, what command would you use to see if a
printer was accepting requests?
$ lpstat -a
5. An alternate printer can be designated from the command line,
true or false?
True
6. Using the lp command, print the dante file on the default printer.
lp dante
7. From the command line, check the status of the previously sent
print request.
lpstat

Printing

13-23

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13
Check Your Progress
Before continuing on to the next module, check that you are able to
accomplish or answer the following:

13-24

Use command-line commands to print a file, check print queue


status, and cancel a print request

Print using the Print Manager in CDE

Determine and change the default printer

Set print options

Demonstrate the major functions of the Print Manager

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

13
Think Beyond
What kinds of printers do you have access to in your environment?
For what kinds of jobs would you use a printer other than your default
printer?

Printing

13-25

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

File and User Information Utilities

14

Objectives
Upon completion of this module, you should be able to:

Describe some advantages of using file systems

List the inode number of a file

Link files using hard and symbolic links

Employ the find command to locate files by specific criteria

Search for text within a document using the grep command

Identify which users are logged on to your system

Switch to a new user ID and identify the user ID you are currently
using

Identify your effective and real UID when switching users

Use the sort command to sort ASCII files in alphabetical and


numerical order

Use the sort command to perform multilevel sorts on ASCII data

14-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
Relevance

Present the following question to stimulate the students and get them thinking about the
issues and topics presented in this module. While they are not expected to know the
answer to the question, the answer should be of interest to them and inspire them to learn
the content presented in this module.

Discussion What utilities do you need for daily computer use?


Do you need to search for items, such as files? What other searches do
you need to do?

Additional Resources
Additional resources The following references can provide
additional details on the topics discussed in this module:

14-2

Solaris Advanced Users Guide, Part Number 801-6615-10

Solaris System Administrator AnswerBook

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14

File Systems
When the UNIX operating system was first developed, hard disks
could store what is now considered a very small amount of data.
When disks larger than 300 Mbytes arrived on the market the
operating system could not address such a large amount of space. This
necessitated the development of logical partitions of the hard drive to
allow the kernel to access smaller, addressable parts of the drive.

File and User Information Utilities

14-3

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
File Systems
Today, with hard drives being sold with up to a Tbyte or more of space
on them, the kernel can access all available space. Despite this, the
convention of partitioning a hard drive into logical partitions has
persisted for various reasons. Partitioning allows an administrator to
functionally organize data so that user files are on a different logical
partition than executables or applications. One of the main advantages
to this is that daily backups can be done only to those partitions on
which the data changes frequently, without having to back up all
information on the disk. Logical partitioning also cuts down on seek
time: if the disk is partitioned, when a user specifies a file to search for
or a directory to change to, the name of the directory gives the kernel
information about where the information is stored. This prevents the
system from having to seek the information over the entire disk.
These logical partitions are referred to as file systems. They are
transparent to a user and therefore appear to be just part of the
directory hierarchy. The most common file systems on a UNIX system
are /usr, where binary and executables are stored, /opt, where third
party applications are usually located, and root (/), where the files
that pertain to the operation of the system are kept.

14-4

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14

Inode Numbers
Inode numbers are identifiers of a file on a file system. Similar to the
way in which a passport number is unique for each person in a
country, an inode number is unique for each file in a file system.
Each file and directory has an inode number assigned to it by the
system. These numbers can be seen by using the following ls
command:
$ ls -i ~
12110
12115
67773

dante
dante_1
dir1

68349 dir3
68451 dir4
12169 file1

12118
12119
68552

file3
file4
practice

The numbers to the left of the file name are the inode numbers. These
are sometimes referred to as index numbers, as the kernel keeps an
index of the files and directories by the inode number and can
therefore refer to them faster.
Note Inode numbers are unique on each file system, even when file
names are identical.
File and User Information Utilities

14-5

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14

Linking Files and Directories


Links
Links are used to create alternate names or aliases for files and
directories on a system. In this way, different users can refer to the
same file or directory by names they are more comfortable with or
names that are shorter. Many system administrators set up links to
commands, giving them names more familiar to users of different
operating systems.
There are two kinds of links, hard and symbolic (or soft).

14-6

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14

Linking Files and Directories


Links
Hard Links
Hard links are used to link files on the same file system. Files that are
hard linked share the same inode number and, therefore, refer to the
same data on the hard disk. Hard links are not used to link directories
and cannot cross file systems, as the inode number is only unique for
that file in its current file system. A completely different file may have
the same inode number on a different file system.

File and User Information Utilities

14-7

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
Linking Files and Directories
Links
Hard Links
The output of the ls -l command shows a link count following the
permissions. This is a count of how many files are hard linked to the
same inode number as the file listed.
$ ls -l ~
-rw------- 1 torey
-rw------- 1 torey
drwx--x--x 5 torey
drwx--x--x 4 torey
<output omitted>

staff
staff
staff
staff

1320
368
512
512

Oct
Oct
Oct
Oct

19
19
19
19

dante
dante_1
dir1
dir2

The link count on directories includes a link to the current directory (.)
and from the parent (..) directory, and a number for each file or
subdirectory included in the directory.
The structure of a hard link is as follows:
File1
File2
File3

Inode number

Data

Display

All hard-linked files share the same inode number and therefore the
same data. This data can be displayed using an appropriate command;
for example, cat or more. In the case of hard links, as long as one file
that refers to the inode number remains, the data remains available on
the system. For this reason, File1 and File3 could be deleted, leaving
the information referred to intact, as File2 would still exist.
Note Hard links cannot be used to link directories; only symbolic
links can be used to do so.

14-8

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14

Linking Files and Directories


Links
Symbolic Links
Symbolic links are used for two main reasons: to link a file or directory
across file systems, or for backwards compatibility. Since symbolically
linked files do not share a single inode, these links can cross file
system boundaries. There are also many cases where commands, files,
or directories that have existed as part of the UNIX operating system
for years are given different names. In order to avoid having to retrain
the multitude of UNIX users in the world, symbolic links are
employed to refer to these files by both their old and new names. This
is referred to as backwards compatibility.

File and User Information Utilities

14-9

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
Linking Files and Directories
Links
Symbolic Links
The following commands indicate that the file symlink is a
symbolically linked file:
$ ls -l Test
-rw-r--r-- 1 torey staff 35 May 8 linktest
lrwxrwxrwx 1 torey staff 8 May 12 symlink--> linktest
$ ls -F
linktest
symlink@
The structure of a symbolic link is as follows:
File1
File2

inode number
inode number

Data
Display
Absolute pathname to File1

The data contained in File2 is the absolute pathname to File1, but


displaying either File1 or File2 will produce the same output. If
File2 is deleted, there is no effect on File1. If File1 is deleted File2
will still exist, but it will point to an invalid file name and therefore be
of no practical use.

14-10

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
Linking Files and Directories
The ln Command
Use the ln command to create hard or symbolic links.

Command Format
ln [-s] source_file target_file
By default, the ln command will create a hard link. The -s option is
used to create a symbolic link. The source_file is the existing file
and the target_file is the new file to be linked to the
source_file.

Creating Links
You can link two files with a

Hard link
$ ln /export/home/user2/dante essay
$ ls -i /export/home/user2/dante
89532 dante
$ ls -i essay
89532 essay

Symbolic link

$ ln -s tutor.vi symlink
$ ls -l symlink
lrwxrwxrwx 1 torey staff

File and User Information Utilities

May

symlink--->tutor.vi

14-11

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14

Finding Files
The find Command
The find command is one of the most powerful and useful of the
commands available to a UNIX environment user. This command can
be used to find files based on specific criteria. Once a file or group of
files that matches a search criterion is found, another command can be
executed on the matching files. The find command can be used for
many purposes including deleting, backing up, or printing files.

14-12

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
Finding Files
The find Command
Command Format
find path expression [action]

path

Names the directory where the search begins.

expression

The search criteria is specified by one or more values. If


more than one expression is specified, find treats the
statement as an and request and all listed expressions
must be verified as true or present. Many search
expressions will require a value to match and in some
cases metacharacters, or wildcards, may be used for the
arguments.

Search Expressions

Definition

-name filename

Search for all files matching the specified filename.


Metacharacters are acceptable but will be interpreted
literally unless placed inside quotes.

-type filetype

Search for all files matching the specified filetype.

-mtime [+|-]n

Search for all files whose modification time either


matches, is older than (+), or is newer than () n days.

-atime [+|-]n

Search for all files whose access time either matches, is


older than (+), or is newer than () n days.

-inum n

Search for the files with the inode number of n.

-user loginid
-group groupid

Search for all files that match the ownership of


loginid or group of groupid.

-perm mode

Search for all files that match the permission setting of


mode. (Octal notation only)

-size [+|-]n[c]

Search for all files whose size either matches, is larger


than (+), or is smaller than () n. The n represents 512
byte blocks, or characters (bytes) if followed by a c.

File and User Information Utilities

14-13

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
Finding Files
The find Command
The expressions used with the find command evaluate as true or
false.
Actions
-exec command {} \; The exec option must be terminated by
{ } \; which allows find to apply the
specified command to each file that it
identifies from the search criteria.
-ok command {} \;

Interactive form of -exec. This option is


used with commands that require input
from the user; for example, rm -i.

-ls

Prints the current path name using the


long listing format. This expression is
most commonly used in conjunction with
a redirection of output to a file in order for
the listing to be examined at a later time.

Note Releases of the Solaris environment previous to 2.5 required the


-print action in order to see the output from the find command on
the screen.
The find command has several additional features that can be used to
further define search criteria. Consult man pages for further details.
Some additional features:

14-14

-o

Allows for an or type of criteria definition

-a

Allows for an and type of criteria definition

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
Finding Files
Using the find Command
You can:

Search for openwin starting at the /usr directory


$ find /usr -name openwin
/usr/openwin
/usr/openwin/bin/openwin

Search for files ending in tif starting at the /usr directory


$ find /usr -name *tif
/usr/openwin/demo/kcms/images/tiff/ireland.tif
/usr/openwin/demo/kcms/images/tiff/new_zealand.tif

Search for core files starting at the users home directory and
delete them
$ find ~ -name core -exec rm {} \;

Look for all files, starting at the current directory, that have not
been modified in the last 90 days
$ find . -mtime +90
<find output omitted>

Find files larger than 400 blocks (512-byte blocks) starting at /etc
$ find /etc -size +400
<find output omitted>

File and User Information Utilities

14-15

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
Finding Files
Additional Features of the find Command
You can:

Find files with open permissions starting at the users home


directory
$ find ~ -perm 777 -depth > holes

Find files owned by a specific user or group in the current directory


hierarchy, list them, and put the listing in a file for later viewing
$ find . -user billw -o -group staff -ls > review

Find files, starting at /etc, which share the same inode number
$ find /etc -inum 769
<find output omitted>

14-16

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14

The grep Command


Use the grep command to search a file for a specified text string. A
string is one or more characters; it can be a character, a word, or a
sentence. A string can include white space or punctuation if these are
enclosed in quotations.
The grep command searches a file for a character string and prints all
lines that contain that pattern to the screen. The grep command can be
used as a filter with other commands.
The grep command is case sensitive. You must match the pattern with
respect to uppercase and lowercase letters, unless you use the -i
option.

File and User Information Utilities

14-17

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
The grep Command
Command Format
grep [option(s)] string filename
Options
-i

Ignore case of string when searching

-v

Search for all lines that do not match string

The following examples show how to search lines in a file or standard


output
$ grep root /etc/passwd
root:x:0:1:Super-User:/:/sbin/sh

$ ls -la | grep -i jun 11


drwxr-xr-x 3 user1 staff

512 Jun 11 13:13 dir4

If the date is a single numeral date, the grep string needs to have two
spaces between the month and the numeral; for example, Jun 3.

14-18

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14

Switching to Another User Account Using the su Command


You can temporarily switch to another user account to have access and
privileges to files and directories that belong to that user by using the
su command.
To switch user IDs, you must supply the password of the user ID you
are switching to.
While using the user ID you switched to, you will not have access to
your previous privileges, only those of the new user ID. To change to
your previous user ID, type exit.

Command Format
su [-] username

File and User Information Utilities

14-19

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
Switching to Another User Account Using the su Command
Using the su Command to Become Another User
$ su guest
Password:
$ pwd
/home/user2
$ cd ~guest
$ pwd
/home/guest
$ exit
When su is used without options, you will remain in the directory you
were in when you switched user IDs. Environmental settings
customized for your user ID will also remain in effect.
To switch to another UID and have the system read the new users
initialization files, you must use a dash (-) between the command and
the new user ID.
$ su - guest
Password:
$ pwd
/home/guest
$

14-20

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14

Using the id Command


Use the id command to display the user name corresponding to the
effective user ID.

Command Format
id [option(s)]

File and User Information Utilities

14-21

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
Using the id Command
Displaying Your Current UID
$ id
uid=102(user2) gid=10(staff)
$ su - guest
Password:
$ pwd
/home/guest
$ id
uid=115(guest) gid=10(staff)
$
Use the id -a command to identify the user name, user ID, and all of
the groups to which the user belongs. In this example the user is
identified as guest and belongs to the groups staff and sysadmin.
The listing for gid identifies the users primary group and the groups
listing identifies all groups to which the user belongs.
$ id -a
uid=115(guest) gid=10(staff) groups=10(staff) 14(sysadmin)
$

14-22

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14

Using the who Command


The who command displays information about all users currently
logged on the local system. This command lists the users name,
terminal line, login time, and elapsed time since the last activity on the
terminal line.

Command Format
who [option(s)]

Displaying Users on the System


$ who
user2 console May 24 10:17
user3 pts/4 May 24 17:36(machine name)
$

File and User Information Utilities

14-23

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
Using the who Command
Use the who -H option to print column headings above the regular
output.
$ who -H
NAME
LINE
user2 console
user3 pts/4
$

TIME
May 24 10:17
May 24 17:36 (machine name)

Use the who -q option to display only the names and the number of
users currently logged on.
$ who -q
user2 user3
# users=2
$

14-24

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14

Using the who am i and whoami Commands


who am i
The who am i command displays information about your real user ID
(RUID). If you use the su command to switch from one UID to
another, the who am i command will display your original login UID.
The who am i command lists the user name, the terminal line, and the
date and time logged on.

Command Format
who am i

File and User Information Utilities

14-25

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
Using the who am i and whoami Commands
who am i
Displaying Your EUID and RUID Information
Display your effective UID (EUID)
$ id
uid=115(guest) gid=10(staff)
$
Display your real UID
$ who am i
user2 console May 24 10:17 (hostname)
$

whoami
The whoami command displays only the login name of the effective
user.

Command Format
whoami
$ whoami
guest

14-26

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14

The sort Command


The sort command provides a quick and easy way for operators to
organize data in either numerical or alphabetical order. This command
uses the ASCII character set as its sorting order, working from left to
right on a character-by-character basis. By default, sort relies on white
space to delimit the various fields within the data of a file. Some sort
features include:

Multilevel sorting

Field-specific sorting

Accepting standard input

Producing standard output

File and User Information Utilities

14-27

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
The sort Command
Command Format
sort [options] [input_filename]

options

The various options available with the sort command


enable the operator to define the type of sort to perform
as well as the field on which to begin sorting.

Options

14-28

-n

Allow for a numeric sort. The n can be used alone


with a dash or can follow a field reference.

(+|-)n

Begin (+) or end (-) the sort with the field following
the nth separator.

-r

Reverse the order of the sort. The r can be used


alone with a dash or can follow a field reference.

-f

Fold uppercase and lowercase characters together


(ignore case in sort order).

+nM

Sort the first three characters of the field as


abbreviated month names.

-d

Use dictionary order. Only letters, digits, and white


space are compared; all other symbols are ignored.

-o filename

Place any output into the file filename.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
The sort Command
Using sort With Different Options
$ cat fileA
Annette
Jamie
Clarence
Sondra
Janet
$
$ sort fileA
Annette
Clarence
Jamie
Janet
Sondra

48486
48481
48487
48483
48482

48486
48487
48481
48482
48483

$ sort +1n fileA


Jamie
48481
Janet
48482
Sondra
48483
Annette
48486
Clarence
48487

The preceding examples show the sort command in a simple format.


The first sort command produces an ASCII type of sort, beginning
with the first character of each line. The second example is a numerical
sort on the second field (sort skips one separator with the +1 syntax).

File and User Information Utilities

14-29

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
The sort Command
Using sort on Different Fields Within a File
$ ls -ld f* > list
$ cat list
-rw------1 melissao staff
218
-rw------1 melissao staff
218
-rw------1 melissao staff
1696
-rw------1 melissao staff
105
-rw------1 melissao staff
218
-rw------1 melissao staff
56
-rw------1 melissao staff
57
$ sort -rn +4 list -o num.list
$ cat num.list
-rw------1 melissao staff
1696
-rw------1 melissao staff
218
-rw------1 melissao staff
218
-rw------1 melissao staff
218
-rw------1 melissao staff
105
-rw------1 melissao staff
57
-rw------1 melissao staff
56
$ sort +5M +6n list -o update.list
$ cat update.list
-rw------1 melissao staff
56
-rw------1 melissao staff
57
-rw------1 melissao staff
218
-rw------1 melissao staff
218
-rw------1 melissao staff
105
-rw------1 melissao staff
218
-rw------1 melissao staff
1696

Jul
Jul
Oct
Oct
Oct
Mar
Mar

15
15
19
19
19
7
7

16:47
16:48
1998
1998
1998
09:52
09:53

feathers
feathers_6
file1
file2
file3
fruit
fruit2

Oct
Oct
Jul
Jul
Oct
Mar
Mar

19
19
15
15
19
7
7

1998
1998
16:48
16:47
1998
09:53
09:52

file1
file3
feathers_6
feathers
file2
fruit2
fruit

Mar
Mar
Jul
Jul
Oct
Oct
Oct

7
7
15
15
19
19
19

09:52
09:53
16:47
16:48
1998
1998
1998

fruit
fruit2
feathers
feathers_6
file2
file3
file1

The first example represents beginning a sort on some field other than
the first, and shows a numeric, reverse-order example. The sort
command line would read as, Do a reverse order, numeric sort on the
fifth field of the data in the file list, and place the output into a file
called num.list.
The second example represents a multilevel sort showing how the
M option would work. This command would read as Do a Month
order sort beginning with the sixth field. Do a second-level sort in
numeric order and begin on the seventh field (this will sort the
numeric day of the month correctly), name the output file
update.list.
14-30

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
Exercise: Using File and User Information Utilities
Exercise objective In this exercise you will practice using
commands to find files and text.

Tasks
Complete the following steps and write the commands used to
perform each task in the space provided.
1. Use the find command to search the /usr directory and display
the file names of any length that end with ln.
2. Use the ls -li command to answer the following questions:

How many links are there to the file /etc/init.d/lp?


_______________________________________________________

Are these hard or symbolic links?


_______________________________________________________

What is the inode number of the /etc/init.d/lp file?


_______________________________________________________

3. Create a file in /var/tmp that is linked to /etc/init.d/lp. Make


sure it works.

If /var is a separate file system, this will have to be a symbolic link.

4. Using the find command and starting at the /etc directory, find
the other files that are linked to /etc/init.d/lp. What are they?
___________________________________________________________
5. To what directory is /bin linked?
___________________________________________________________
6. Search for the text string other in the /etc/group file.
7. Using ls and grep, display all the files created today.

File and User Information Utilities

14-31

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
Exercise: Using File and User Information Utilities
Tasks
8. Using the grep command, look for all lines in the file4 file
located in your home directory that do not contain the letter "M".
9. Identify who is logged on to the system.
10. Switch to the guest account or another users account as specified
by your instructor in such a way that you are in that users
environment.
11. Type the who am i command. What happened?
___________________________________________________________
12. Type the id command. What happened?
___________________________________________________________
13. What command do you type to display the user ID and all groups
that you belong to?
__________________________________________________________
To create a file for use in the next step, type:
$ ls -la > ls.output
14. Sort the ls.output file. Produce a numerical listing by size of the
files, in reverse order. What command did you use?
___________________________________________________________
15. Perform a multilevel sort of the ls.output file that places the
data in chronological order, then alphabetically by name. What
command did you use?
___________________________________________________________

14-32

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
Exercise: Using File and User Information Utilities
Workshop Labs
Use what you have learned so far in this course to work through the
following:
1. On Monday you are told that all members of your department are
to be dismissed because they consistently arrive at work late. In
order to prove to your supervisor that this is not the case, you ask
to have a week to gather data to prove your groups timeliness. At
the end of the week, you need to provide a printed copy of a file
that lists what time everyone in your group logged in each day for
a week. You have to create this file using commands that you have
learned. For easier readability, the printout should be sorted by
employee before being printed. You would also like to have a copy
in your home directory of the sorted file to refer to at a later date.
Using the least number of commands, how can you achieve this
goal and save the groups job?
2. You would like to have a list of all of the names of the
subdirectories under /etc. Because you want to keep this list for
future reference in a file, you would like any error messages that
might appear while you are doing your search to be removed from
the final output. Create a file that contains the list of these
subdirectories and place it in your personal binary directory.
3. Using the caret (^) character with the regular expression in the
grep command indicates the first character in a line. (For example,
$ grep ^c file will look for lines that start with a c in the
named file.) Using the file created in the workshop lab for Module
6, generate a file that contains the shell commands that start with
the letters a though f, regardless of case (upper or lower). Sort
this file alphabetically using the second field of the output of the
grep command, and save the sorted text. Important You will
need to have the sort command ignore blank spaces when
performing the sort.
4. To which commands is the cp command linked? What similarities
are there between these commands?

File and User Information Utilities

14-33

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
Exercise: Using File and User Information Utilities
Exercise Summary
Discussion Take a few minutes to discuss what experiences, issues,
or discoveries you had during the lab exercises.

Manage the discussion here based on the time allowed for this module, which was given
in the About This Course module. If you find you do not have time to spend on
discussion, then just highlight the key concepts students should have learned from the
lab exercise.

Ask students what their overall experiences with this exercise have been. You might want
to go over any trouble spots or especially confusing areas at this time.

14-34

Conclusions

Have students articulate any conclusions they reached as a result of this exercise
experience.

Interpretations

Ask students to interpret what they observed during any aspects of this exercise.

Experiences

Applications

Explore with students how they might apply what they learned in this exercise to
situations at their workplace.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
Exercise: Using File and User Information Utilities
Exercise Solutions
Complete the following steps and write the commands used to
perform each task in the space provided.
1. Use the find command to search the /usr directory and display
the file names of any length that end with ln.
$ find /usr -name *ln
2. Use the ls -li command to answer the following questions:

How many links are there to the file /etc/init.d/lp?


Four or five, depending upon the system.

Are these hard or symbolic links?


Hard

What is the inode number of the /etc/init.d/lp file?


It is different for every system. It is the number on the far left of the
permissions.

3. Create a file in /var/tmp that is linked to /etc/init.d/lp. Make


sure it works.
$ ln /etc/init.d/lp /var/tmp/printer
$ ls -li /var/tmp/printer
4. Using the find command and starting at the /etc directory, find
the other files that are linked to /etc/init.d/lp. What are they?
$ find /etc -inum inode number
5. To what directory is /bin linked?
$ ls -ld /bin
It is linked to /usr/bin.
6. Search for the text string other in the /etc/group file.
$ grep other /etc/group

File and User Information Utilities

14-35

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
Exercise: Using File and User Information Utilities
Exercise Solutions
7. Using ls and grep, display all the files created today.
$ ls -l | grep 'May

9'

(This date is for example only.)


8. Using the ln command, create a symbolic link in your home
directory to the command /usr/bin/clear. (You can name the
link in your home directory whatever you want.) Check to see if
the new link works to clear your screen.
$ ln -s /usr/bin/clear cl
9. Using the grep command, look for all lines in the file4 file
located in your home directory that do not contain the letter "M".
$ grep -v 'M' file4
10. Identify who is logged on to the system.
$ who
11. Switch to the guest account in such a way that you are in that
users environment.
$ su - guest
12. Type the who am i command. What happened?
Your real UID (RUID) is displayed.
13. Type the id command. What happened?
Your effective UID (EUID) is displayed.
14. What command do you type to display the user ID and all groups
that you belong to?
$ id -a

14-36

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
Exercise: Using File and User Information Utilities
Exercise Solutions
To create a file for use in the next step, type:
$ ls -la > ls.output
15. Sort the ls.output file. Produce a numerical listing by size of the
files, in reverse order. What command did you use?
$ sort -rn +4 ls.output
16. Perform a multilevel sort of the ls.output file that places the
data in chronological order, then alphabetically by name. What
command did you use?
$ sort +5M +6n +8d ls.output
If time of day created is an issue, the answer would be:
$ sort +5M +6n +7n +8d ls.output

File and User Information Utilities

14-37

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
Check Your Progress
Before continuing on to the next module, check that you are able to
accomplish or answer the following:

14-38

Describe some advantages of using file systems

List the inode number of a file

Link files using hard and symbolic links

Employ the find command to locate files by specific criteria

Search for text within a document using the grep command

Identify which users are logged on to your system

Switch to a new user ID and identify the user ID you are currently
using

Identify your effective and real UID when switching users

Use the sort command to sort ASCII files in alphabetical and


numerical order

Use the sort command to perform multilevel sorts on ASCII data

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

14
Think Beyond
For what kinds of situations might you use the utilities presented in
this module in your work environment?

File and User Information Utilities

14-39

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Backing Up and Restoring

15

Objectives
Upon completion of this module, you should be able to:

Use the tar and compress commands to back up files and


directories

Use the jar command to save and compress files and directories

Position a tape to a selected data set using the mt utility

15-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

15
Relevance

Present the following question to stimulate the students and get them thinking about the
issues and topics presented in this module. While they are not expected to know the
answer to the question, the answer should be of interest to them and inspire them to learn
the content presented in this module.

Discussion How frequently do you back up or restore files?

15-2

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

15

Contents Overview
In order to back up or easily transfer files via ftp or another method,
you need to be able to package and restore the files easily. This module
covers the following commands:

tar

compress

jar

mt

In addition, specific instructions for backing up and restoring your


home directory using tar and compress are included.

Backing Up and Restoring

15-3

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

15

The tar Command


The tar (tape archive) command enables you to back up single or
multiple files in a directory hierarchy.

Command Format
tar function_[letter/modifier] [output file] filename(s)/directory(s)
Function Letters
c

Create a new tar file

List the table of contents of the tar file

Extract the specified files from the tar file

Function Modifiers

15-4

Specify the tar file (/tmp/file.tar) or tape


drive (/dev/rmt/x) if other than default

Execute in verbose mode

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

15
The tar Command
Saving a Directory to Tape
You can create the tar file using a relative path name.
$ cd /home
$ tar cv user1

This archives the user1 directory to the default device,/dev/rmt/0.


This command is also useful for creating archive files to share with
other users or attach to mail messages.
$ cd
$ tar cvf files.tar file1 file2 file3

Backing Up and Restoring

15-5

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

15

The compress Command


The compress command is used to compress files using a special
format to reduce the size of the file from 20 percent to 80 percent.

Command Format
compress filename

Compressing a File
The following example uses the -v (verbose) option to compress a file
called bin.file:
$ compress -v bin.file
bin.file: Compression: 70.84% -- replaced with
bin.file.Z

The file is compressed and a .Z suffix is appended to the file name.

15-6

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

15
The compress Command
Files are uncompressed using the uncompress command.

Command Format: Uncompressing


uncompress filename

Uncompressing a File
$ uncompress bin.file.Z

Backing Up and Restoring

15-7

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

15

The jar Command


The jar command is similar to the tar command, but compresses the
resulting file in the same step. It is a Java application that combines
multiple files into a single JAR (Java archive) file. It is also a generalpurpose archiving and compression tool, based on ZIP and the ZLIB
compression format. The jar command was originally created for Java
programmers to download multiple files with one request, rather than
having to issue a download request for each separate file. jar is
standard with the Solaris 7 operating system, but is available on any
system that has Java virtual machine (JVM) installed.

Command Format
The syntax for the jar tool is almost identical to the syntax for the tar
command.
jar options [ output file ] filename(s)/directory(s)

15-8

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

15
The jar Command
Options
c

Create a new jar file

List the table of contents of the jar file

Extract the specified files from the jar file

Specify the jar file (/tmp/file.jar) or tape


drive (/dev/rmt/x) if other than default

Execute in verbose mode

Note It is not necessary to use a hyphen (-) before options when


issuing the jar command.

Adding All the Files in a Directory to an Archive


$ ls
dante
dante_1

dir1
dir2

dir3
dir4

file1
file2

file3
file4

fruit
fruit2

$ jar cvf bundle.jar *


adding: dante (in=1320) (out=744) (deflated 43%)
adding: dante_1 (in=368) (out=242) (deflated 34%)
adding: dir1/ (in=0) (out=0) (stored 0%)
adding: dir1/coffees/ (in=0) (out=0) (stored 0%)
adding: dir1/coffees/beans (in=0) (out=0) (stored 0%)
adding: dir1/coffees/nuts (in=0) (out=0) (stored 0%)
adding: dir1/fruit/ (in=0) (out=0) (stored 0%)
adding: dir1/trees/ (in=0) (out=0) (stored 0%)
adding: dir2/ (in=0) (out=0) (stored 0%)
<output omitted>
adding: file1 (in=1696) (out=874) (deflated 48%)
<output omitted>
Note The jar tool is not intended for backing up symbolic links.
Error messages will display if this is attempted.

Backing Up and Restoring

15-9

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

15

The mt Command
The mt command enables direct tape manipulation.

Command Format
mt [ -f tape-device-name ] command [ count ]
The -f option is used to specify the tape device file name, typically a
no-rewind device file name. If the -f option is omitted, the value of
the TAPE environment variable is used to determine the tape device to
manipulate.

15-10

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

15
The mt Command
Commands
status

Displays status information about the tape


drive.

rewind

Rewinds the tape.

retension

Rewinds the cartridge tape completely, winds


the tape forward to the end of the tape, then
rewinds back to the beginning of the tape to
smooth out the tape tension.

erase

Erases the entire tape.

fsf

Forward skips count tape files.

bsf

Backward skips count tape files.

eom

Skips to the end of the recorded media.

off

Ejects 4- or 8-mm tapes.

Note Only the unique prefix of a command is required. For example,


use ret in place of retension.
Use the following mt command to rewind a tape:
$ mt rew
To have the tape skip forward a tape file, use the following command:
$ mt -f /dev/rmt/0n fsf 1
The device name /dev/rmt/0n tells the tape drive not to rewind the
tape after it has performed a function. This device naming convention
can also be used when archiving files with tar and jar.
Note The retension option does not work with 8-mm tapes.

Backing Up and Restoring

15-11

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

15
Backing up and Restoring the Home Directory
Backing up the Home Directory
Since most work is done in users home directories, these directories
are often scheduled for backup on a nightly basis by system
administrators. If your home directory is not being backed up by the
system administrator, it is good practice to perform a regular nightly
backup of changing data.
1. Create the tar file using a relative path name.
$ cd /export/home
$ tar cvf /tmp/home.tar user1

2. Display the table of contents.


$ tar tvf /tmp/home.tar
3. Compress the tar file.
$ compress -v /tmp/home.tar
/tmp/home.tar: Compression: 80.85% -- replaced with
/tmp/home.tar.Z

4. Change directory to /tmp. Back up the compressed file on to a


tape using the tar command.
$ cd /tmp
$ tar cv home.tar.Z

15-12

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

15
Backing up and Restoring the Home Directory
Restoring the Home Directory
To restore files,
1. In the home directory, make a new directory and change to it to
prevent overwriting of files.
$ cd
$ mkdir newhome
$ cd newhome

2. Extract the home directory from tape.


$ tar xv

3. Uncompress the file.


$ uncompress home.tar.Z

4. Extract the tar file.


$ tar xvf home.tar

5. Move files as needed.

Backing Up and Restoring

15-13

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

15
Exercise: Saving and Restoring Files
Exercise objective In this exercise you will practice backing up files
to tape or disk.

Tasks
Note If you get a Permission Denied error while performing the
following exercises, check the write protect switch on the tape.
Complete these steps:
1. Back up your home directory to a file using the tar command.
2. Compress the tar file and archive it to tape.
3. Use the jar utility to back up ~/practice.
4. Use the tar utitlity to back up ~/practice and compress the file.
5. Compare the tar and jar file backups of ~/practice for size.
6. Retension the tape.

Workshop Labs
Use what you have learned so far in this course to work through the
following:
1. Another user in your group needs a copy of the files in your
personal binary directory. Create a compressed tar file, place it in
that directory, and make it available to the other user.

15-14

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

15
Exercise: Saving and Restoring Files
Exercise Summary
Discussion Take a few minutes to discuss what experiences, issues,
or discoveries you had during the lab exercises.

Manage the discussion here based on the time allowed for this module, which was given
in the About This Course module. If you find you do not have time to spend on
discussion, then just highlight the key concepts students should have learned from the
lab exercise.

Ask students what their overall experiences with this exercise have been. You might want
to go over any trouble spots or especially confusing areas at this time.

Conclusions

Have students articulate any conclusions they reached as a result of this exercise
experience.

Interpretations

Ask students to interpret what they observed during any aspects of this exercise.

Experiences

Applications

Explore with students how they might apply what they learned in this exercise to
situations at their workplace.

Backing Up and Restoring

15-15

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

15
Exercise: Saving and Restoring Files
Exercise Solutions
1. Back up your home directory to a file using the tar command.
$
$
$
$

cd
cd ..
tar cvf /tmp/homedir.tar login-ID
tar tvf /tmp/homedir.tar

2. Compress the tar file and archive it to tape.


$ cd /tmp
$ compress homedir.tar
$ tar cv homedir.tar.Z
3. Use the jar utility to back up your practice directory.
$ cd ~
$ jar cvf ~/practice.jar practice
4. Use the tar utility to back up your practice directory and
compress the file.
$ cd ~
$ tar cvf ~/practice.tar practice
$ compress -v practice.tar
5. Compare the tar and jar file backups of your practice directory
for size.
$ ls -l *jar *tar.Z
6. Retension the tape.
$ mt ret

15-16

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

15
Check Your Progress
Before continuing on to the next module, check that you are able to
accomplish or answer the following:

Use the tar and compress commands to back up files and


directories

Use the jar command to save and compress files and directories

Position a tape to a selected data set using the mt utility

Backing Up and Restoring

15-17

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

15
Think Beyond
What tasks do you currently complete that you can apply the tar or
jar commands to, besides saving and restoring files and directories?

15-18

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

System Processes and Memory


Management

16

Objectives
Upon completion of this module, you should be able to:

Identify processes on your system using the ps command

Find a process using the pgrep command

Control processes using the jobs command

Terminate unwanted processes using the kill and pkill


commands

16-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16
Relevance

Present the following question to stimulate the students and get them thinking about the
issues and topics presented in this module. While they are not expected to know the
answer to the question, the answer should be of interest to them and inspire them to learn
the content presented in this module.

Discussion At times an application that you are running will freeze


or cause your system to become inaccessible. How would you regain
control of your workstation?

Additional Resources
Additional resources The following reference can provide additional
details on the topics discussed in this module:

16-2

Solaris Users Guide, Part Number 802-6499

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16

System Process Overview


Each task you perform in the Solaris 7 environment starts a process. An
example of a process is using vi to edit a letter, or sending a file to the
printer. Each process is assigned a unique process identification number
(PID), which is used by the system to identify the process.
The following pages define useful commands on how to locate a
process and terminate processes.

System Processes and Memory Management

16-3

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16

Process Hierarchy
There are five types of processes on a Solaris 7 system:

Daemon

Parent

Child

Orphan

Zombie or defunct

Daemon processes are processes that are started by the kernel and exist
for a specific purpose. For instance, the lpsched daemon exists for the
sole purpose of handling print jobs. When no printing is taking place
on the system, the lpsched daemon is running but inactive. When a
print job is submitted, this daemon becomes active until the job is
finished. The dtlogin daemon provides the CDE login screen at the
beginning of a users session and again after the user exits CDE.

16-4

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16
Process Hierarchy
Following system boot-up, a process called init is invoked. This
process is at the top of the process hierarchy and is responsible for
spawning many system processes. The dtlogin daemon is spawned
by init and init is, therefore, referred to as the parent process of the
dtlogin daemon.
When a user is working in a terminal window in CDE, that terminals
PID is the parent process ID (PPID) of any commands issued in the
terminal. These commands are child processes of the terminal process.
The parent process receives and displays the output from the child
process and then kills the process.
If a command is issued in a terminal window and the window is
closed before the command returns output, that process becomes an
orphan. The system passes the orphan process to init which then
becomes the parent process and terminates the child process.
Occasionally a child process does not return to the parent process with
its output. This process becomes lost in the system. The only
resource this process uses is a slot in the process table; it cannot be
stopped in a conventional manner. This type of process is called a
zombie or defunct process. The only way to kill a defunct process is to
reboot the system.

System Processes and Memory Management

16-5

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16

Processes and PIDs


Use the ps command to list the processes currently running on the
system. The output of this command will display the PID number and
the command associated with it. Many times a PID number is needed
for use with the kill command (discussed on page 16-14).

Command Format
ps [-options]
Options
-e

Print information about every process on the


system.

-f

Generate a full listing. (Refer to the man pages


for a description of the headings displayed.)

Because of the number of processes usually running on a system, it is


useful to pipe the ps -ef command to more so that the output can be
read a page at a time, as in the example on the next page.

16-6

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16
Processes and PIDs
Displaying a Full Listing of All Processes
$ ps -ef | more
UID
PID PPID
root
0
0
root
1
0
root
2
0
root
3
0
root
236
1
root
844
1
aster 1292
1
root
241 236
rose
1400 321
--More--

C
80
80
27
80
80
54
80
69
80

STIME
16:46:41
16:46:44
16:46:44
16:46:44
16:48:08
12:12:10
06:48:51
16:48:14
20:03:11

TTY
?
?
?
?
?
?
console
?
?

TIME
0:01
0:40
0:00
4:33
0:01
0:00
0:01
0:01
0:00

CMD
sched
/etc/init pageout
fsflush
/usr/lib/saf/sac
/usr/lib/lpsched
-ksh
/usr/lib/saf/ttymon
/usr/openwin/bin/clock

Table 16-1 describes the column headings.


Table 16-1 Column Headings
Value

Description

PID

The process identification number of the


process

PPID

The parent process identification number of


the process

TTY

The controlling terminal for the processa

TIME

The amount of CPU time used by the process

CMD

The command nameb

The controlling terminal for system daemons appears as a question mark (?).
<defunct> will appear in the the CMD column if a process is a zombie or defunct process. Also,
the CPU time may be a bit higher for a defunct process than for other processes.
b

System Processes and Memory Management

16-7

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16
Processes and PIDs
Searching for a Specific Process
A quicker way of determining the correct PID is to pipe the output of
the ps command through grep, searching for the specific process you
want to terminate.
$ ps -e | grep lp
225
?
217
?
260
?
$

0:01
0:0
0:01

lpNet
lpsched
lpNet

In Solaris 7, you can use the pgrep command to search for a specific
process. Using the -l option will display the names of the processes
associated with the PID found.
$ pgrep -l lp
225 lpNet
217 lpsched
260 lpNet
$

16-8

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16

Managing Jobs
The shell gives you the ability to execute several jobs simultaneously.
Print requests or an application that has been executed are examples of
jobs. Every job is assigned a job ID. The coordination of multiple jobs
within the shell is called job control.
When a job has been executed in the window environment, it runs in
the foreground and ties up that window until the job is done.
Jobs executing in the background do not tie up your window, so you
can start other jobs without waiting for the background job to finish.
The commands used to control a job based on the job ID can only be
used in the window in which the job was started.

System Processes and Memory Management

16-9

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16
Managing Jobs
Use the following commands to control jobs:
Table 16-2 Job Management Commands
Command

Value

jobs

Display which jobs are currently running.

fg %n

Place a job in the foreground.

bg %n

Place a job in the background.

kill %n

Abort the specified background job. The job ID


must be specified.

Control-c

Abort the foreground job.

Control-z

Suspend the foreground job.

To run a job in the background, type the command followed by an


ampersand (&). The number returned in brackets is the job ID number.
An example of a time-consuming job that could be run in the
background is searching a large directory stucture with the find
command. For example:
$ find / -name core > trash 2> /dev/null &
[1] 3923
In this example, each argument has the following meaning:
Table 16-3 Command Arguments

16-10

Argument

Meaning

>

Redirect standard output (1) to filename

trash

The file used to capture standard output

2>

Redirect standard error (2) to filename

/dev/null

Data written to this file is discarded

&

Process job in the background

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16
Managing Jobs
The responses displayed by the system have the following meaning:
Table 16-4 Responses
Response

Meaning

[1]

The job ID number

3923

The process ID number

If you are still working in the shell, the next time you press Return you
will see a message indicating that the background process has
completed.
[job-id] + Done

job description . . .

Use the jobs command to list your active jobs.


$ jobs
[1] + Running find / -name core> trash 2> /dev/null &

If you bring the background job back to the foreground, it will tie
up your shell until the job is completed or placed back in the
background.
$ fg %1
find / -name core > trash 2> /dev/null

To put the same job in the background, suspend it first.


find / -name core > trash 2> /dev/null
^Z
[1] + Stopped(SIGTSTP) find / -name core> trash \
2> /dev/null &
$ jobs
[1] + Stopped(SIGTSTP) find / -name core > trash \
2> /dev/null &
$ bg %1
[1] find / -name core > trash 2> /dev/null &
$

System Processes and Memory Management

16-11

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16
Managing Jobs
Placing a stopped job into either the foreground or the background
restarts the job.

If you log off before the background job is completed, use the nohup command to enable a
background job to complete, otherwise, the background job will be terminated when you
log off.

Note Notification is sent when there are stopped jobs at logout.

16-12

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16

Terminating Processes
Signals
There are currently 46 signals defined in the Solaris 7 operating
system. Each signal is associated with a number and a name. Signals
are used to terminate, suspend, and continue processes. Information
on the different signals can be found by using the following command:
$ man -s 5 signal
A process that is not responding can sometimes be terminated by
using Ctrl-c. This sends an interrupt (INT) signal to the process,
terminating it and any child processes it might have spawned.

System Processes and Memory Management

16-13

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16

Terminating Processes
The kill Command
The kill command provides a direct way to terminate unwanted
command processes. It is useful when you want to stop a command
that takes a long time to run, or when you need to terminate a process
that you cannot quit in the normal way.

Command Format
kill [-signal] job-id or process-id

Terminating a Process
You would:
1. Type ps to find out the PID(s) for the process(es).
2. Type kill followed by the PID(s).

16-14

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16
Terminating Processes
The kill Command
If you use the kill command without specifying a signal, signal 15
(SIGTERM) is sent to the process with the specified PID number. This
usually causes the process to terminate.

Finding and Terminating a Process by User


The ps -u command can be used either with a login name or a UID
number. A user can only terminate his or her own processes, but the
superuser can terminate any process running on the system. If there
are multiple windows open on a users desktop, the output of the ps
command will show pts/# under the TTY heading for every window
open. A pts (pseudoterminal) is the device name given to windows
and remote login sessions.
$ ps -u login-ID
PID
12892
12932
12935
<Output omitted>
$ kill 12932
[1] + Terminated
\; &
$

TTY
console
pts/0
pts/1

TIME
0:01
0:01
0:00

COMD
ksh
find
ps

find / -name core -exec rm {}

If you need to forcibly terminate a process, you can append the -9


option to the kill command. This option is necessary for killing
shells which will not respond to any other signal to terminate.
$ kill -9 PID#
$
Note For processes other than shells, use the kill -9 command as a
last resort because it is an abrupt method and does not allow for
proper process termination.

System Processes and Memory Management

16-15

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16
Terminating Processes
The kill Command

To abort a background job, use the specific job number as the


argument to the kill command.
$ kill %1
[1] + Terminated find / -name core > trash \
2> /dev/null &
$ jobs
$

The pkill command, new in Solaris 7, works exactly like the pgrep
command, except that it terminates the matching process or processes
with a kill signal.
$ sleep 100&
$ ps
472
12418
$ pkill sleep
$ ps
472
$

pts/3
pts/3

0:01
0:00

ksh
sleep

pts/3

0:01

ksh

Note The sleep command is frequently used in shell scripts to cause


the machine to pause for a specified number of seconds before
continuing on to the next command. It is used in the above example
only for purposes of illustration.

16-16

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16

Memory
Physical Memory (RAM) and Swap Space
All computers have central memory, or system memory, which has a
sequence of instructions (a program) and data related to the program.
This memory is controlled directly by the processor in conjunction
with the Memory Management Unit (MMU) and is called physical
memory, or random access memory (RAM).
Many processes are held simultaneously in RAM, so it is possible to
use it up. If a new process needs to be placed in RAM, the pageout
process selects pages of a process that are not currently in use and
pages them out to swap space on the disk. The selection of pages is
made based on a not recently used algorithm. Swap space is a raw
slice or disk file set aside for this purpose.
Processes remain in RAM while they are active. The swapping method
uses swap space on the disk which is limited. RAM plus swap space
constitutes virtual memory which is the maximum space that
processes can use. Virtual memory has a much shorter access time
than accessing something on the formatted areas of the disk. For
obvious reasons, the kernel is not swapped.
System Processes and Memory Management

16-17

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16
Memory

Kernel

1
Process 1

2
Process 2

RAM (physical memory)

Figure 16-1

16-18

Swap space

Swapping

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16

Memory
Paging
A program on a Sun workstation can address up to 4 Gbytes of
memory. A system is typically equipped with some number of Mbytes
of RAM.
During the execution, a process is placed in RAM (cut in pages) and is
swapped page by page in and out of RAM. This process is called
paging.
Swapping rarely takes place on systems with very large amounts of
RAM, whereas paging frequently occurs and is a normal part of
system operation.

System Processes and Memory Management

16-19

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16
Exercise: Manipulating System Processes
Exercise objective In this exercise, you will use the commands
learned in this module to determine PID numbers, kill processes, and
control jobs.

Tasks
Complete the following steps:
1. In a terminal window, issue the following command:
$ cat -v /dev/zero
Note This command is being used to produce a continuously
running command for demonstration purposes only. For information
on the /dev/zero file, see man zero.
2. Open another terminal window (shell) and use the ps command to
identify the process ID of the cat command.
3. From the current window, kill the cat command using the cat
commands process ID.
4. From the current window, determine the PID of the window in
which the cat command was running and kill that window.
5. Issue the following command in the background:
$ sleep 500 &
6. Using the jobs command, find the job number of the sleep
command in step 5. Bring the job to the foreground and then put it
back in the background.
7. Kill the job running the sleep command.

16-20

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16
Exercise: Manipulating System Processes
Workshop Labs
Use what you have learned so far in this course to work through the
following:
Getting rid of core files that are taking up space on your hard drive is
a common task that is useful to run in the background.
1. Issue a find command that will look for and remove core files
starting at the root directory, and send error messages to
/dev/null. Have the process run in the background. Next, bring
the job to the foreground to check on its progress, then place it
back in the background again.
2. This type of command can use up quite a bit of system resources;
at this point, the response time of your machine is more important
to you than removing the core files. Stop the job; it will be
resumed in a later exercise.

System Processes and Memory Management

16-21

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16
Exercise: Manipulating System Processes
Exercise Summary
Discussion Take a few minutes to discuss what experiences, issues,
or discoveries you had during the lab exercises.

Manage the discussion here based on the time allowed for this module, which was given
in the About This Course module. If you find you do not have time to spend on
discussion, then just highlight the key concepts students should have learned from the
lab exercise.

Ask students what their overall experiences with this exercise have been. You might want
to go over any trouble spots or especially confusing areas at this time.

16-22

Conclusions

Have students articulate any conclusions they reached as a result of this exercise
experience.

Interpretations

Ask students to interpret what they observed during any aspects of this exercise.

Experiences

Applications

Explore with students how they might apply what they learned in this exercise to
situations at their workplace.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16
Exercise: Manipulating System Processes
Exercise Solutions
Complete the following steps:
1. In a terminal window, issue the following command:
$ cat -v /dev/zero
2. Open another terminal window (shell) and use the ps command to
identify the process ID of the cat command.
$ ps -ef | grep cat
3. From the current window, kill the cat command using the cat
commands process ID.
$ kill PID
where PID is the process ID of the cat command
4. From the current window, determine the PID of the window in
which the cat command was running and kill that window.
Look at the PPID of the cat command:
$ ps -ef | grep PPID
then type
$ kill -9 PID
where PID is the PPID of cat.
5. Issue the following command in the background:
$ sleep 500 &
6. Using the jobs command, find the job number of the sleep
command in step 5. Bring the job to the foreground and then put it
back in the background.
$ fg %1
^Z
$ bg %1
System Processes and Memory Management

16-23

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16
Exercise: Manipulating System Processes
Exercise Solutions
7. Kill the job running the sleep command.
$ kill %1

16-24

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16
Check Your Progress
Before continuing on to the next module, check that you are able to
accomplish or answer the following:

Identify processes on your system using the ps command

Find a process using the pgrep command

Control processes using the jobs command

Terminate unwanted processes using the kill and pkill


commands

System Processes and Memory Management

16-25

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

16
Think Beyond
What do you currently do when you need to stop a process? How will
using kill change that?
What might be the advantage of having daemon processes? What
might you expect to see that would indicate you are running out of
virtual memory?

16-26

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Network Basics

17

Objectives
Upon completion of this module, you should be able to:

Describe the terms client-server and distributed processing

Open a session on a remote machine using telnet

Log in remotely to another machine on the network

Use ftp to get a file from a remote system

Identify users logged in on the local network

Describe the concept of naming services

17-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17
Relevance

Present the following question to stimulate the students and get them thinking about the
issues and topics presented in this module. While they are not expected to know the
answer to the question, the answer should be of interest to them and inspire them to learn
the content presented in this module.

Discussion What network features do you use now? What do you


think would be the advantages of being connected to other users, or a
central file server?

Additional Resources
Additional resources The following reference can provide additional
details on the topics discussed in this module:

Solaris Users Guide, Part Number 802-6499

Important This is a fundamentals class, basically aimed at end-users. This module is


intended as an introduction to network commands only. It is strongly suggested that you
do not teach the system administration files used for networking here. That topic is fully
covered in the SA-287 course and not intended for this audience.

Be sure you have a naming service running so the students can use the rlogin and
rusers commands.

17-2

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17
Client-Server
Example Networking Environment
Figure 17-1 shows a sample networking environment with
workstations, a printer, and so on.

Figure 17-1

Example Solaris Networking Environment

You may want to explain to the students the difference between having access to a
naming service and not having access to a naming service. You cannot assume that
students will have access when they go back to their working environment.

If you are not running a naming service, the host name and IP address must be
recognized by the remote system as being in the /etc/inet/hosts file.

If the user does not have a home directory on the remote machine, the user is
automatically placed in the root (/) directory.

Network Basics

17-3

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17

Client-Server
Distributed Processing
Distributed processing enables access to remote systems for the purpose
of sharing information and network resources. It also enables
communication with users on other systems.

Network
A network is a connection that enables an exchange of information
between machines. Two types of networks are:

17-4

Local area network (LAN) A network that covers a small area,


usually less than a few thousand feet.

Wide area network (WAN) A network that can span thousands


of miles.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17
Client-Server
Host
A host is a computer system on a network. The local host is the machine
on which the user is currently working. A remote host is a system that
is being accessed by a user from another system.

Server
A server provides resources to one or more clients by means of a
network.

Client
A client is a machine that uses the services from one or more servers on
a network.

Naming Services
Sometimes it is useful to have a common user and group list for hosts
on a network. In such situations, a naming service can be implemented
by the sytem administrator. A naming service allows users to be
recognized by all remote machines on the network. If the system
administrator on your network chooses not to use a naming service,
you must have an account on a remote machine in order to log in to it.

Network Basics

17-5

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17

Network Commands
telnet
telnet is an application that is part of the Solaris 7 environment. It
utilizes Transmission Control Protocol/Internet Protocol (TCP/IP) to
connect to another system.
The telnet server simulates a terminal in order to authorize a user to
connect to a remote system and work in that environment. When
using telnet, you can:

17-6

Open a session on a remote machine

Alternate between the remote session and the local session

Access machines that do not run under the UNIX environment

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17
Network Commands
telnet
The following is an example of using telnet to connect to a remote
system called beach:
$ telnet beach
Trying 192.9.49.10 ...
Connected to beach
Escape character is ^].
4.2 BSD UNIX (beach)
login: jdupont
Password:
Last login: Wed Jun 1 19:03:33 on console
beach% (Enter commands)
beach% exit
Connection closed by foreign host
$

The following is an example of using telnet to alternate between the


remote session and a local session:
$ telnet beach
Trying 192.9.49.10 ...
Connected to beach
Escape character is ^].
4.2 BSD UNIX (beach)
login: jdupont
Password:
Last login: Wed Jun 1 19:08:15 on console
beach% ^]
telnet> !
$ pwd
/home/user2
$ exit
beach% exit
Connection closed by foreign host

Network Basics

17-7

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17

Using the rlogin Command


Overview
Use the rlogin command to establish a remote login session on
another workstation.
Remotely logging in to a workstation is helpful under the following
circumstances:

To access information on another workstation that is not available


otherwise

To access your workstation remotely to read mail.

To kill a process that has caused your workstation to hang

Command Format
rlogin hostname [-option]

17-8

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17
Using the rlogin Command
Overview
Remotely Logging in to Another Host
$ rlogin saturn
Password:
Last login: Mon Dec 21 11:04:27 from venus
Sun Microsystems Inc. SunOS 5.7 Generic October 1998
$ id
uid=102(user2) gid=10(staff)
$ uname -n
saturn
$ pwd
/home/user2
$ exit
Connection closed.
$

Network Basics

17-9

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17

Using the rlogin Command


Specifying a Different Login ID
Use the -l option to specify a different login ID for the remote login
session.
The system administrator can set up a guest account so users can
remotely log on to a server.

Command Format
rlogin hostname -l username

17-10

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17
Using the rlogin Command
Before attempting to remotely log in to another system as a different
user, be sure you have an account on the desired remote machine.
Check with your system administrator if you do not have an account
on the remote machine. The information you will need to know is:

Machine name

Login ID

Password of the new account

Logging in Remotely as Another User


$ rlogin saturn -l user15
Password:
Last login: Mon Dec 21 11:04:27 from venus
Sun Microsystems Inc. SunOS 5.7 Generic October 1998
You have mail.
$ id
uid=115(user15) gid=10(staff)
$ pwd
/home/user15
$ exit
Connection closed.
$

Network Basics

17-11

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17
Using the rlogin Command
Terminating a Local Process From a Remote Machine
When your system is not responding and you do not want to reboot,
you may be able to kill a process on your system remotely by logging
on to another machine and using the rlogin command to access your
system. For example:
$ rlogin hostname
Password:
Last login: Tue Jun 8 17:40:30
Sun Microsystems Inc. SunOS 5.7
You have mail.
$ ps -e
PID
TTY
10153
console
12892
console
217
term/a
/usr/lib/lpsched
14490
pts/2
12932
pts/0
13162
pts/7
10138
console
10159
console
10140
pts/1
10151
console
10614
pts/1
10109
console
$ kill 14490
$ exit
Connection closed.
$

17-12

from venus
Generic October 1998

TIME
0:03
0:01
0:0

CMD
cm
sh

0:03
0:01
0:08
0:04
7:29
0:05
12:42
0:27
0:00

maker3ol
/bin/sh
admintool
clock
mailtool
cmdtool
xnews
cmdtool
xinit

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17
Using the rlogin Command
Using rlogin and pkill to Recover From a Hung CDE
Session
When your workstation does not appear to be responding to mouse or
keyboard input, the odds are excellent that the problem stems from
within your CDE session as opposed to the underlying operating
system itself. In such cases, you can use another workstation to access
your workstation via rlogin (or telnet) and then use the pkill
command to terminate the corrupted CDE session; all without
rebooting your workstation.
$ rlogin hostname
Password:
Last login: Fri Jul 9 16:50:30 from barney
Sun Microsystems Inc. SunOS 5.7 Generic October 1998
$ pkill -9 loginshell
If you do not know your default shell, type the following command:
$ pkill -9 basename $SHELL
which will determine and terminate all instances of your login shell for
you.

Either variant will return you to the dtlogin screen, enabling you to
start a new CDE session.

Network Basics

17-13

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17

Network Commands
Using the ftp Command
The ftp command (part of an industry-standard application called
FTP, or File Transfer Protocol) is used to transfer files using ASCII or
binary mode between systems using similar or dissimilar operating
systems. Servers with sites set up for downloading files sometimes
provide an anonymous ftp account so users can pull files off the server.
For this kind of an account, at the Name prompt, the word anonymous
is entered instead of accepting the default displayed. If a password is
required for the anonymous account, it will usually be your full email
address.

17-14

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17
Network Commands
Using the ftp Command
Once you have successfully used ftp to access a remote site, some
familiar file and directory access commands like cd and ls are
available. If permissions are set by the sites system administrator for a
user to see the contents of a directory, the ls command will display
files in that directory. If permissions are set such that a user does not
have access to the files, when the ls command is entered, a prompt
will be returned in response. As on your local system, cd will change
directories on the remote system. If it is necessary for you to change
directories on your own system in the middle of the ftp session, the
lcd (local change directory) command can be used. To end an ftp
session, type bye at the prompt.
$ ftp venus
Connected to 129.150.212.16.
220 venus FTP server (UNIX(r) System V Release 4.0) ready.
Name (129.150.212.16:lister): Return <CR>
331 Password required for lister.
Password: xxx
230 User lister logged in.
ftp> cd /etc/inet
250 CWD command successful.
ftp> bin
200 Type set to I.
ftp> get hosts /tmp/hosts
200 PORT command successful.
150 Binary data connection for hosts (129.159.129.38,33425) (77 bytes)
226 Transfer complete.
local: /tmp/hosts remote: hosts
77 bytes received in 0.0014 seconds (5,25 Kbytes/s)
ftp> bye

Network Basics

17-15

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17

Using the rusers Command


Use the rusers command to see who is logged in on the local
network.

Command Format
rusers [-option(s)] [hostname]

Displaying Remote Users on a Network


$ rusers
Sending broadcast for rusersd protocol version 3...
localhost
user2
saturn
user3
Sending broadcast for rusersd protocol version 2...
$
If your network is busy or there are many hosts on the network, this
command can take quite a while to complete its output. Press
Control-c to abort the command.

17-16

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17
Using the rusers Command
Displaying Remote Users on a Network
If you want to see whether a specific user is logged in, specify the
users host name.
$ rusers saturn
saturn
$

user3

Use the -l option to get a longer listing in the style of the who
command.
$ rusers -l
Sending broadcast
user3
user2
Sending broadcast
$

Network Basics

for rusersd protocol version 3...


saturn:console
May 24 08:33
localhost:console May 24 08:33
for rusersd protocol version 2...

17-17

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17

The NIS+ Naming Service


The goal of the NIS+ naming service is to allow centralization of
network administration.

Decentralized Administration
The administration of a group of machines grows in complexity with
the number of machines and users to manage. Thus, decentralized
administration is conceivable for two or three machines, it becomes
more complex if the number exceeds that limit.
For example, imagine a group of five machines. If all the users have to
be able to log in as themselves on each machine, the administrator
must duplicate the /etc/passwd on every machine. Although putting
this in place initially is possible, maintenance becomes difficult. In
effect, each modification of one element of the password file makes it
necessary to reproduce the change on each machine.

17-18

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17
The NIS+ Naming Service
Decentralized Administration
The problem that is raised by the /etc/password file is exponentially
increased by necessary changes to many other administrative files,
such as the groups and hosts files.

Centralized Administration
It is advisable for administrators to set up networks with a centralized
administration that distributes a database to all the machines known
by the distributed administration.
This database can be centralized on one server, which provides the
administrative services. The group of machines using the database on
the server is called a domain. This centralized administration uses a
naming service as the framework for the domain(s). NIS (Network
Information Service) and NIS+ are two naming services that can be set
up for use in the Solaris networked environment.
Note This section and the following one on NFS are intended as
introductions to some networking concepts. The topics are in no way
addressed completely in this class. They are covered more fully in the
SA-287: Solaris 7 System Administration II and advanced networking
courses.

Network Basics

17-19

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17

The NFS System


The NFS system is Suns distributed computing file system. It is a
network service that allows users to transparently access files and
directories located on another disk on the network.

17-20

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17

The NFS System


NFS Server
The NFS system server:

Has a local disk

Allows access to the resources on the disk to machines with


specified permissions (restrictions)

Responds to requests from diverse clients

Does not maintain any status information about the files opened
by clients, so there are no dependencies between server and clients

Can serve clients of other servers and be an NFS client itself

Network Basics

17-21

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17

The NFS System


NFS Client
The NFS system client:

17-22

Mounts the desired file system which has been authorized by the
NFS system server

Reads or writes to files on the NFS server

Maintains open files

Can access many NFS servers and be an NFS server, if it has a


local disk

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17
Exercise: Performing Network Basics
Exercise objective In this exercise you will use some of the
networking commands introduced in this module.

Tasks
Complete the following steps:
1. Use the rlogin command to log in to another machine in your
classroom.
In what directory are you placed on the remote machine?
___________________________________________________________
2. Issue the command that shows you the hostname of the current
machine.
3. Log out of the remote machine. Display the hostname of your
current machine to determine if you are back to your own host.
4. Use the rlogin command and option to log in to another machine
as the user guest with a password of guest (or as another user as
specified by your instructor).
5. Log out of the remote machine.

Workshop Lab
Use what you have learned so far in this course to work through the
following:
1. Start the find command that was previously stopped.
2. Log in to your machine from another students machine and kill
the find command.

Network Basics

17-23

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17
Exercise: Performing Basic Network Commands
Exercise Summary
Discussion Take a few minutes to discuss what experiences, issues,
or discoveries you had during the lab exercises.

Manage the discussion here based on the time allowed for this module, which was given
in the About This Course module. If you find you do not have time to spend on
discussion, then just highlight the key concepts students should have learned from the
lab exercise.

Ask students what their overall experiences with this exercise have been. You might want
to go over any trouble spots or especially confusing areas at this time.

17-24

Conclusions

Have students articulate any conclusions they reached as a result of this exercise
experience.

Interpretations

Ask students to interpret what they observed during any aspects of this exercise.

Experiences

Applications

Explore with students how they might apply what they learned in this exercise to
situations at their workplace.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17
Exercise: Performing Basic Network Commands
Exercise Solutions
Complete the following steps:
1. Use the rlogin command to log in to another machine in your
classroom.
$ rlogin hostname
In what directory are you placed on the remote machine?
A home directory on the remote machine (either /home/username or
/export/home/username) or the root directory (/) if no home
directory exists.
2. Issue the command that shows you the hostname of the current
machine.
$ uname -n
3. Log out of the remote machine. Display the hostname of your
current machine to determine if you are back to your own host.
$ exit
$ uname -n
4. Use the rlogin command and option to log in to another machine
as the user guest with a password of guest.
$ rlogin hostname -l guest
5. Log out of the remote machine.
$ exit

Network Basics

17-25

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17
Check Your Progress
Before continuing on to the next module, check that you are able to
accomplish or answer the following:

17-26

Describe the terms client-server and distributed processing

Open a session on a remote machine using telnet

Log in remotely to another machine on the network

Use ftp to get a file from a remote system

Identify users logged in on the local network

Describe the concept of naming services

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

17
Think Beyond
What other advantages of a networked environment can you think of?

Network Basics

17-27

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Mail Tool and Calendar Manager

18

Objectives
Upon completion of this module, you should be able to:

Describe the main features of the Mail Tool

Compose and send an electronic mail (email) message

Read an electronic mail message

Respond to a mail message

Delete and undelete mail messages

Set mail aliases

Create alternate mailboxes

Attach files to mail messages

Describe the major functions of the Calendar Manager

Add appointments to your calendar

View your calendar in the four formats: Day, Week, Month, and
Year

Set Calendar options

18-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Relevance

Present the following question to stimulate the students and get them thinking about the
issues and topics presented in this module. While they are not expected to know the
answer to the question, the answer should be of interest to them and inspire them to learn
the content presented in this module.

Discussion What types of information do you send through email?


Do you need to send only text, or files in various formats? Do you save
messages?
What advantages can you see to keeping a calendar of appointments
on your system? Would you want to make this calendar available to
other users in your group?

18-2

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
The Mail Icon and Mail Window
The Mail icon
on the Front
Panel

List of received
email messages

Mail Tool and Calendar Manager

The Mail icon


showing new
mail has been
received

Message viewing
area

18-3

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18

The Mail Window


By default, the Mail window is divided into two portions.
The upper portion displays a list of the email messages which have
been received.
The lower portion displays the text content of the currently
highlighted message. This allows you to view each messages contents
by clicking once on an email subject header line in the upper portion.

18-4

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
The Mail Window
New Messages
A new message, that has not yet been read is shown with the letter
N to the left of the senders name.

New mail
messages

Attached Files
When an email message has one or more files attached, a diamond
character will be displayed after the New Message indicator (the letter
N). To read an attachment, double-click on its icon at the bottom of the
window.

Attachment

Mail Tool and Calendar Manager

18-5

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Increasing and Decreasing the Message Viewing Area

To increase or decrease the message viewing area, drag the button,


circled in the above example, up or down.

18-6

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18

Responding to a Received Message


To reply to a message that you have received, open the Compose
menu. You are given the choice of replying to the sender or to all
recipients of the message. You are also given a choice of including the
original message or not. Mail is frequently sent out in a mass mailing
to many recipients who happen to be on a mail alias. Mail aliases are
often quite large and general, so use the Reply to All option with
caution.
If you want to reply and include the message you received, you can
bypass the Compose menu and click on the Reply, Include Message
icon on the toolbar of the Mail Tool.

Mail Tool and Calendar Manager

18-7

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Responding to a Received Message

Reply, Include Message icon

18-8

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Responding to a Received Message

After you choose a method of reply, the window above will be


displayed.
By default, the original Subject text will be used, preceded by Re:, and
the To: entry will, automatically, be set to the email address of the
sender of the message.

Mail Tool and Calendar Manager

18-9

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Deleting Mail Messages

Delete
options

18-10

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18

Deleting Mail Messages


To keep the list of received mail messages to a minimum (and to save
disk space), periodically delete mail messages.
There are a number of delete options, which are displayed on the
preceding page.
Choosing to delete the mail messages does not remove the mail.
Rather, the messages are stored until you close the mail window. This
gives you an opportunity to decide not to delete the message. You can
force the mail program to delete any mail messages which were
previously selected for deletion by clicking on Mailbox Destroy
Deleted Messages.
While you continue to work with the mail program, you can view a
list of the deleted mail messages and undelete one or more messages
from the list. When a message is undeleted, it will reappear in the list
of received mail messages.

Mail Tool and Calendar Manager

18-11

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Deleting Mail Messages

18-12

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Creating Alternate Mailboxes

Messages that you receive may contain information that you will want
to access at a later time. In the CDE Mail Tool, you can create multiple
mailboxes for the purpose of storing mail for later retrieval. These
mailboxes can be named to reflect the contents you intend to store in
them.

Mail Tool and Calendar Manager

18-13

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Moving Messages to Alternate Mailboxes
Once a new mailbox has been created, you can then use the Move
menu to move received mail into it.

18-14

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Composing New Mail Messages

To compose a new mail message, click on ComposeNew Message.


This will display a window where you can fill in the appropriate
information. Make sure the address you are sending the message to is
complete. You can include more than one name, separated by commas,
in the To: and CC: fields. When you are finished creating the message,
click on the Send button in the bottom left corner of the pane to send
the message to the addressees.

Mail Tool and Calendar Manager

18-15

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Attaching Files to Mail Messages

To attach a file to a message you are composing, click on


AttachmentsAdd File. A window will be displayed from which you
can choose the file you want to attach.

18-16

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Setting up Mail Aliases

Email addresses can be difficult to remember. Mail Tool provides a tool


that allows you to set up aliases for either a particular person or a
group of people that you frequently send mail to. This utility can be
accessed by clicking on OptionsAliases. Choose a name for the alias
and enter the email addresses of all users you want to be part of the
alias. The email addresses must be separated by a comma. After an
alias has been entered, click on Add to place it in your list of aliases.
When you are finished creating aliases, click on OK.

Mail Tool and Calendar Manager

18-17

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18

Other Mail Tool Options


Many options can be customized with the different categories listed
under the Options menu. Some of these include

18-18

Saving copies of mail that you have sent

Specifying how often you would like the system to check for new
mail

Specifying how you would like to be notified of new mail

Setting a vacation message to be sent in reply to messages when


you are unavailable

Creating a custom signature that can be attached to all outgoing


email

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18

The Calendar Manager


The Calendar Manager icon is situated on the Front Panel.
By default, the Calendar window displays a month view of your
calendar. The view can be changed by clicking on one of the four view
icons at the top right hand side of the window, as circled in the
example.

Mail Tool and Calendar Manager

18-19

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
The Calendar Manager
Appointments or things-to-do can be added to your calendar by
clicking on the appropriate icon at the top left side of the window, as
shown.

Appointments

Things-to-do

18-20

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Viewing the Calendar
Day View

This is the day view of the calendar, selected by clicking on the circled
icon.

Mail Tool and Calendar Manager

18-21

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Viewing the Calendar
Week View

This is the week view of the calendar, selected by clicking on the


circled icon.

18-22

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Viewing the Calendar
Year View

This is the year view of the calendar, selected by clicking on the circled
icon.

Mail Tool and Calendar Manager

18-23

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Adding an Appointment

When you click on the Appointment button, an Appointment Editor


window will be displayed.
Details which can be entered into this window are:

The date on which the appointment is to be made

The start and end times of the appointment

Details relating to the appointment (in the What box)

Once the appropriate details have been selected or entered into the
relevant window areas, click on Insert to add that appointment.
Once an appointment has been inserted, it will be displayed in the
Time What area at the right side of the window and on the appropriate
day of your calendar.

18-24

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Setting Start and End Times

Pick and point lists are provided to indicate the times your
appointments start and end. These lists can be selected by clicking on
the appropriate time box to the right of the start and end times.
Note By default, you can add several appointments on the same day
to start at the same time. The Calendar Manager does not warn you of
conflicting appointments.

Mail Tool and Calendar Manager

18-25

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Selecting a Date
Regardless of the current view of the calendar, you can scroll forwards
and backwards along a timescale associated with that view.
Once an appropriate date is visible on the display, you can open the
Appointments Editor by double-clicking on the area in the window
associated with that day.
If you are looking at the weekly view, click on the area at the bottom
left of the window, then double-click in the hourly section to set an
appointment for that time.

Double-click in an hours
box and the appointment
will be scheduled for
that hour.

18-26

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Appointment Editor Options

Mail Tool and Calendar Manager

18-27

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18

Appointment Editor Options


As shown previously, a range of additional options is available when
adding an appointment. By clicking on More in the lower left corner of
the window, this display will open up at the bottom of the
Appointment Editor window.
The following options are available:

Frequency of the appointment

Number of times a frequent appointment is to be added to the


calendar

Privacy controls

Appointment reminders

Who to send email to (when an appointment reminder is to be


sent)

To close the additional options window area, click on Less.

18-28

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Printing Calendar Appointments

Mail Tool and Calendar Manager

18-29

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Printing Calendar Appointments
In the CalendarFile menu, you have the option to print the current
view of the calendar or open a Print window in which the print
options can be set.

In addition to specifying which printer to print to and how many


copies are required, you can choose which view is to be printed.
From and to dates allow you to specify the date range to be printed.
You can also print to a file instead of to a printer.

18-30

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Setting Calendar Options
The FileOptions menu option, as shown below, will display the
Editor Defaults window, by default.

In the Editor Defaults window, you can set the options to suit your
personal preferences.
Once the values have been modified, click on either OK or Apply to
save the updated details.
Other Options settings can be set by selecting the appropriate choice
from the pull-down menu.

Mail Tool and Calendar Manager

18-31

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Setting Calendar Options
Editor Defaults

18-32

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Setting Calendar Options
Display Settings

In Display Settings you can:

Set the time range for the working day

Set the hour display as 12 or 24 hour

Designate the default view for the Calendar Manager

Designate the default calendar to view

Mail Tool and Calendar Manager

18-33

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Setting Calendar Options
Access List and Permissions

In this window, you can set the access rights for the calendar. You can
designate who has the right to work with or view your calendar. By
default, this is set to world (which means that everyone has access
rights).

18-34

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Setting Calendar Options
Printer Settings

This window enables you to set your personal options for the printing
of calendar appointments.

Mail Tool and Calendar Manager

18-35

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Setting Calendar Options
Date Format

The Date Format window enables you to set the format for date
display and date entry.

18-36

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Finding Appointments

The Find window enables you to search for text in the appointment
entries. You can specify the time period to search, giving a start and
end date.
Once appointments have been found, you can double-click on the
details (shown in the lower portion of the window) to view the actual
appointment details.

Mail Tool and Calendar Manager

18-37

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Browsing Other Calendars

If you want to check the appointments which have been made in other
users calendars, use the Browse Show Other Calendar menu option.
With the correct permission settings to view other calendars, you can
compare peoples appointments to help arrange meetings which do
not conflict with existing appointments.
The Browse menu option also provides a menu editor for configuring
the menu options which are used by the Calendar window.

18-38

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Exercise: Using the Mail Tool and Calendar Manager
Exercise objective In this exericse, you will use the different
features of the Mail Tool to send email messages, reply to messages
you receive, and customize the Mail Tool. You will also use the
features of the Calendar Manager to schedule appointments and
customize the way you are notified of those appointments.

Tasks
Complete the following steps:
1. Open a Mail Tool window and send an email message to yourself,
using just your login name as an address.
2. Check your mail to see if you received your email.
3. Reply to the message that you sent to yourself.
4. Send an email message to another user in your class.
5. Delete one of your email messages.
6. Undelete the deleted email message.
7. Create an alias which includes three of your fellow students.
8. Send a message to another user in your class, attaching the file
dante to the message.
9. Create an alternate mailbox called Misc, and move a message into
the new mailbox.
10. Add an icon to the toolbar for Destroy Deleted Messages.
11. Open the Options menu and the Signature option. Create a
customized signature to append to all of your mail messages. Send
a message to yourself and close with the signature. Check for the
message in your mailbox, and read the message.
12. Schedule an appointment on your calendar for 10:30 every
Monday morning for six weeks starting next week.
13. Allow other users to view your calendar and insert appointments.

Mail Tool and Calendar Manager

18-39

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Exercise: Using the Mail Tool and Calendar Manager
Tasks
14. Have the system mail you a message four hours before an
appointment.
15. Open a Calendar Manager window by clicking on the appropriate
Front Panel icon.
16. Change the view from day to week, then week to month.
17. Add an appointment which lasts between 9 AM and 3 PM for
todays date.
18. Add another appointment which starts at 1 PM and ends at 2 PM
for todays date.
19. Make an appointment for the period between 9 AM and 10 AM for
the next six Mondays (starting next week).
20. Print your calendar entries for this week.
21. Have the Calendar Manager notify you by email six hours before
an appointment and on your screen five minutes before an
appointment.
22. Try to view another users calendar. (Consult with your instructor
to see if this is possible in your training room.)

18-40

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Exercise: Using the Mail Tool and Calendar Manager
Exercise Summary
Discussion Take a few minutes to discuss what experiences, issues,
or discoveries you had during the lab exercises.

Manage the discussion here based on the time allowed for this module, which was given
in the About This Course module. If you find you do not have time to spend on
discussion, then just highlight the key concepts students should have learned from the
lab exercise.

Ask students what their overall experiences with this exercise have been. You might want
to go over any trouble spots or especially confusing areas at this time.

Conclusions

Have students articulate any conclusions they reached as a result of this exercise
experience.

Interpretations

Ask students to interpret what they observed during any aspects of this exercise.

Experiences

Applications

Explore with students how they might apply what they learned in this exercise to
situations at their workplace.

Mail Tool and Calendar Manager

18-41

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Check Your Progress
Before continuing on, check that you are able to accomplish or answer
the following:

18-42

Describe the main features of the Mail Tool

Compose and send an electronic mail (email) message

Read an electronic mail message

Respond to a mail message

Delete and undelete mail messages

Set mail aliases

Create alternate mailboxes

Attach files to mail messages

Describe the major functions of the Calendar Manager

Add appointments to your calendar

View your calendar in the four formats: Day, Week, Month, and
Year

Set Calendar options

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

18
Think Beyond
How you could use the Mail Tool and Calendar Manager features to
make your work easier?

Mail Tool and Calendar Manager

18-43

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Features of the C Shell

This appendix describes some of the features available in the C shell.


For information about the Bourne and Korn shells, refer to Module 10,
Bourne and Korn Shell Variables.
Teaching this appendix is optional. If there is time, you can choose to point out the
difference in syntax between the Korn and C shells when setting variables and aliases.
You may also want to restate that the initialization files for the C shell are .login and
.cshrc.

A-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

A
C Shell Variables
Local Variables
The C shell uses names with all lowercase letters for local variables.
The following is an example of how to set a local variable and how to
display the currently set local variables and their values.

Command Format
set variable=string
unset variable
The set command prints the values of your local variables to the
screen.

Setting Local Variables


% set history=6
% echo $history
6
% unset history
% echo $history
history: Undefined variable
% set
cp cp -i
home /home/user2
noclobber
path (/usr/bin /usr/ucb .)
shell /bin/csh
user user2
%

A-2

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

A
C Shell Variables
Environment Variables
The C shell uses names with all uppercase letters for environment
variables. The following is an example of how an environment
variable is set in the C shell and how to display the currently set
environment variables and their values.

Command Format
setenv VARIABLE string
unsetenv VARIABLE
The setenv command prints the values of your current environment
variables to the screen.

Setting Environment Variables


% setenv LPDEST staffp
% echo $LPDEST
staffp
% setenv
LANG=C
HZ=100
PATH=/usr/bin /usr/ucb .
LOGNAME=user2
MAIL=/var/mail/user2
USER=user2
SHELL=/bin/csh
HOME=/home/user2
LPDEST=staffp
PWD=/home/user2
% unsetenv LPDEST
% setenv
LANG=C
HZ=100
PATH=/usr/bin /usr/ucb .
LOGNAME=user2
MAIL=/var/mail/user2
USER=user2
SHELL=/bin/csh
HOME=/home/user2
PWD=/home/user2
%

Features of the C Shell

A-3

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

A
C Shell Variables
Path
The C shell uses a different format than the Bourne and Korn shells for
setting the path variable. Instead of the colon used by the Bourne and
Korn shells as a delimiter between path names, the C shell uses a
space and surrounds the entire variable in parentheses.

Command Format
set path=(pathname [pathnames(s)])

Changing the path Variable


The following example changes the path variable to search for a
particular command in /usr/bin, the current directory, the home
directory, and the /usr/openwin/bin directory:
% echo $path
/usr/bin . /usr/openwin/bin
% set path=(/usr/bin /usr/ucb . $HOME
/usr/openwin/bin)
% echo $path
/usr/bin /usr/ucb . /home/user2 /usr/openwin/bin
%

A-4

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

A
History in the C Shell
The history Command
The history variable saves and prints the current command and
history list number to the screen. The history list keeps a record of the
exact command lines that you enter, in the order that you enter them.
Unlike the Korn shell, the C shell does not automatically have the
history variable set. You must set the history variable (history list)
before the history command can be executed.

Command Format
set history=n
Set history to a specific number to display that number of previous
commands to the screen.

Activating the history Variable


% set history=5
% history
18 set history=5
19 history
%
In the example above, only two lines are displayed after typing the
history command. After you have set the history variable, as shown
above, the history list will then be created from that point on.

Features of the C Shell

A-5

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

A
History in the C Shell
The history Command
Any commands entered prior to executing the set history
command are not part of the history list. Any commands typed after
setting the history variable are added to the history list and are
displayed each time you type the history command. For example:
% pwd
% cd /tmp
% history
18 set history=5
19 history
20 pwd
21 cd /tmp
22 history
%

A-6

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

A
History in the C Shell
Command-Line Substitution
You can use command-line editing to make changes to the last
command and then execute it.

Command Format
^old_string^new_string
Each string can be any length. The caret (^) symbols tell history to
locate the first occurrence of the letter(s) old_string in the previous
command, substitute the letter(s) new_string for it, and execute the
modified command.

Making Corrections to the Command Line


% lp -d ztaffp feathers
UX:lp: Error:
ztaffp: unknown printer

% ^z^s
lp -d staffp feathers
request id is staffp-5 ( 1 file )
%

Features of the C Shell

A-7

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

A
History in the C Shell
Command-Line Substitution
The history variable in the C shell offers additional features for
editing previously entered commands. Table A-1 lists the options
available with the history variable in the C shell.
Table A-1 history Variable Options
Feature

Function

!!

Executes the previous command

!*

Repeats all arguments from the previous command

!$

Repeats the last argument from the previous command

!number

Executes command number from the history list

!n:p

Views command n from the history list without


executing it

The Bourne shell does not offer these features for editing previously
entered commands. Commands specific to the Korn shell are used to
perform in-line editing in Korn shells.
% history
31 set history=40
32 cd /home/user2/practice
33 pwd
34 lpstat
35 set noclobber
36 mkdir /home/user2/practice/weekly
37 cd /home/user2/dir3
38 ls planetd
39 ls planets
40 history
% !32
cd /home/user2/practice
%
The command in the previous example executes command-line 32 from
the history file output above (cd home/user2/practice).

A-8

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

A
History in the C Shell
Command-Line Substitution
You can combine history and command-line substitution to recall
and change a previous command. Use :p if you want to view the
command first without executing it. For example:
% !37
cd /home/user2/dir3
% !38:p
ls planetd
% ^d^s
ls planets
mars
moon
pluto
% cd ..
% ls dir2 dir4
dir2:
beans
recipes
dir4:
flowers
roses
% history
31 set history=40
32 cd /home/user2/practice
33 pwd
34 lpstat
35 set noclobber
36 mkdir /home/user2/reports/weekly
37 cd /home/user2/dir3
38 ls planetd
39 ls planets
40 cd /home/user2/practice
41 cd /home/user2/dir3
42 ls planetd
43 ls planets
44 cd ..
45 ls dir2 dir4
46 history
% !45:p
ls dir2 dir4
%

Features of the C Shell

A-9

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

A
History in the C Shell
Command-Line Substitution
Use !! to execute the most recent command exactly as it was executed
previously. If you entered lpstat, sent some print jobs from other
terminal windows, and want to enter the lpstat command again
from the original terminal window, type !! at the shell prompt to
execute lpstat the second time. For example:
% lpstat -o
no entries
% !!
lpstat -o
sparky-3
filtered
printer1-5
printer 1
print1-6
filtered
%

root

15

Jun 9

14:55

root

573

Jun 9

13:14 on

root

545

Jun 9

08:10

Use !* to repeat all arguments of the previous command.


Use !$ to repeat the last argument of the previous command. For
example:
% cd
% mkdir a b c
% ls !*
ls a b c
a:
b:
c:
% rm -ir !$
rm -ir c
rm: examine files in dir c (y/n)? y
rm: remove c: (y/n)? y
%

A-10

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

A
History in the C Shell
Command-Line Substitution
% ls -l > /tmp/list.file
% more !$
more /tmp/list.file
total 90
-rw-r--r-- 1 user2 other 72 Jun 21 15:07
-rw-r--r-- 1 user2 other 72 Jun 21 15:07
drw-r--r-- 5 user2 other 512 Sep 28 16:39
.
.
.
drw-r--r-- 2 user2 other 512 Sep 29 09:45
drw-r--r-- 4 user2 other 512 Sep 29 10:01
%

Features of the C Shell

dante
dante_1
dir1

letters
practice

A-11

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

A
C Shell Features
Customizing Your Prompt
The C shell enables customization of your system prompt.

Command Format
set prompt=value

Changing Your Prompt


% set prompt="Whats Next? "
Whats Next? set prompt="Hello, hostname "
Hello, venus set prompt="% "
%
When you change your current command prompt to something new,
the new prompt will remain until you change it again or until you log
out.
To make your change permanent, add the set prompt command to
the .cshrc file for the C shell.

A-12

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

A
C Shell Features
Aliases
Command aliases are available in the Korn and C shells, but they are
not available in the Bourne shell.
A command alias enables you to

Substitute a short command for a long one

Create a single command for a series of commands

Create alternate forms of existing commands

Change a command set

Command Format
alias alias_name value

Setting Aliases
% alias c clear
% alias gohome cd;ls

Features of the C Shell

A-13

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

A
C Shell Features
Aliases
Use the unalias command when you want to remove an alias.

Command Format
unalias alias_name

Unsetting an Alias
% unalias c
% c
c: Command not found
%
Aliases are only valid for the window in which they are created.
However, you can add the aliases to the .cshrc file for the C shell to
activate them whenever you invoke a shell.

A-14

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Command-Line Mail

This appendix provides the following information for accessing mail


from the command line:

Sending mail from the command line using the mailx program

Reading and printing messages

Creating and using a mail alias

B-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

B
Introduction to mailx
The Solaris operating environment provides a program called mailx
for sending and receiving electronic mail (email). The mailx program
provides facilities for reading, writing, sending, receiving, saving, and
deleting messages from the command line.
The mailx program (utility) is not window-based; therefore, it can be
run in either a window environment or from any terminal.

B-2

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

B
Command-Line Mail
Use the mailx program from the command-line when:

You are using a command-line login shell

You are using a terminal

You remotely log in to your workstation to read your mail

Command Format
mailx
mailx username@hostname
Each user has a mailbox file in which to receive mail. By default, this
mailbox is located in /var/mail/username, where username is your
login ID.
The mailx program notifies you when you receive mail and places the
mail in your mailbox. After you have read your mail, mailx
automatically places these letters in a storage file called mbox, which is
located in your home directory.

Reading Your Mail


$ mailx
No mail for user2
$

In the Solaris 7 environment, the mail utility offers two versions, mailx and mail. You can
use either one; however, the mailx version has more options. This appendix covers the
mailx version. /usr/ucb/mail is symbolically linked to /usr/bin/mailx.

Command-Line Mail

B-3

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

B
Sending a Mail Message
To send mail:
1. Specify username@hostname as an argument to the mailx
command.
2. Enter the subject of your mail and press Return.
3. Enter the text of your message, and press the . (period) key or
Control-d (to transmit message) on a line by itself to signal the end
of the message.
For example:
$ mailx user3@saturn
Subject: lunch!
Hi there!
Do you have any plans for lunch today?
If not, would you care to join me?
user2
. (Type a dot [.] and press Return)
EOT
$
(EOT is an acronym for end of transmission.)

B-4

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

B
Canceling a Mail Message
Press Control-c to cancel a mail message.
$ mailx user3@saturn
Subject: lunch!
Do you have any plans . . . (press Control-c)
^C
(Interrupt -- one more to kill letter)
(press Control-c)
^C /home/user2/dead.letter 3/29
$
Note Each line of text within your letter can be up to 256 characters
long. When you exceed this limitation, your screen will freeze. If this
occurs, press Control-c to abort your letter.
If you cancel a message, it is saved in your home directory under the
name dead.letter. Either remove this file or save the text under
another name for later transmission.

Command-Line Mail

B-5

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

B
Reading a Mail Message
If you have mail, mailx notifies you each time you log in with the
message:
You have mail. or
You have new mail.
To read your mail messages, invoke the mailx program.
$ mailx
mailx version 5.0 Thu Aug 5 10:36:57 PDT 1999 type ? for
help.
/var/mail/user2: 2 messages 2 new
>N1 user3Mon May 14 14:4416/334About lunch!
N2 user4Mon May 14 14:5314/326Your lunch
?
Note The question mark (?) is the mail prompt.
When you have a large number of letters in your mailbox, the
displayed list may not show all of your mail headers. If this is the case,
type one of the following options:
Options

B-6

z+

Displays the next screenful of


mail headers

z-

Displays the previous screenful


of mail headers

Redisplays the list of mail


headers at any time

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

B
Reading a Mail Message
The output from the mailx command is called the mail header. The
mail header displays:

The version of the program

A question mark (?) for help with mail

The location of the mail box (for example, /var/mail/username)


where your mail messages are saved

The status of the mail box:

The total number of messages in the mail box

The number of new messages

The status (new or unread) for each message

The number of each message in the order it was received

The sender (user and machine name)

The time and date the message was sent

The size of the message (the number of lines and number of


characters in the message)

The subject of the message

Mail Headers
$ mailx
mailx version 5.0 Thu Aug 5 10:36:57 PDT 1999 type ?
for help.
/var/mail/user2: 2 messages 2 new
>N 1 user3
Mon May 14 14:4416/334
About lunch!
N 2 user4 Mon May 14 14:5314/326
Your lunch
?

Command-Line Mail

B-7

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

B
Reading a Mail Message
When a new message is received, or an old message was not read, one
of the following characters appears next to the applicable message:
Table B-1 Message Classification Characters
Character

Message

Indicates a new message

Indicates a message that was received


earlier, but was not read before
quitting the mailx program
previously

Indicates a new message that was read


during the current invocation of
mailx

Indicates a message that was read


previously and is saved in the current
mail box

>

Indicates current message

Indicates which message number, or if


typed by user, listing of options to
look for

To read the first mail message, press Return at the mail prompt (?).
The first (or current) message appears on your screen.
Press Return to read any subsequent messages.
If you want to select a specific mail message to read, type the number
of the mail message at the mail prompt and press Return.

B-8

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

B
Reading a Mail Message
Reading a Specific Message
$ mailx
mailx version 5.0 Thu Aug 5 10:36:57 PDT 1999 Type?
for help.
"/var/mail/user2": 2 messages 2 new
>N 1 user3 Mon May 14 14:4416/334About lunch!
N 2 user4 Mon May 14 14:5314/326Your lunch
? 2
Message 2:
From user4@jupiter Mon Aug 2 14:53 PST 1999
Date: Mon, 2 Aug 1999 14:53:31 PST
From: user4@jupiter
To: user2@venus
Subject: Your lunch
Hi user2!
I heard you are going out to lunch.
Mind if I join you?
user4
?

Command-Line Mail

B-9

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

B
Deleting and Undeleting a Mail Message
Use the d (delete) command within mailx to delete mail messages.
d [ number...range ]

To delete the current message


?d

To delete a non-current message


? d number

To delete several messages at a time


?d 1 3 5

To delete a range of messages


? d 1-5

To undelete mail messages


? u number
? u number number. . .
? u number-number

Note You can undelete messages only until you quit mailx.

B-10

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

B
Replying to a Mail Message
Use the r command within mailx to reply to the current message. For
example:
$ mailx
mailx version 5.0 Thu Aug 5 10:36:57 PDT 1999 Type? for help.
"/var/mail/user2": 2 messages 2 new
>N 1 user3 Mon Aug 2 14:44 16/334 About lunch!
N 2 user4 Mon Aug 2 14:53 14/326 Your lunch
? 1
Message 1:
From user3@saturn Mon Aug 2 14:44 PST 1999
Date: Mon, 2 Aug 1999 14:45:31 PST
From: user3@saturn
To: user2@venus
Subject: About lunch!
I have no plans for lunch and would be happy
to join you.
user3
? r
To: user3@saturn
Subject: Re: About lunch!
Great! Lets meet in the lobby after class.
user2
.
EOT
?

Command-Line Mail

B-11

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

B
Replying to a Mail Message
To reply to a non-current message, type:
? r number
Your reply will be sent to the sender of the message.
To reply to the sender and everyone who received the current
message, type:
? R
To reply to the sender and everyone who received a non-current
message, type:
? R number
Note Be careful about using R to reply if you are sending any
confidential information. Mail messages are frequently sent to large
groups of people that you may not want receiving the contents of your
reply.

B-12

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

B
Saving a Mail Message
To save a current message, type:
? s filename
This will save the message in the specified file in your home directory.
A saved message can be read using the cat or more commands, or
edited using vi, the CDE Text Editor, or any editor your system uses.
To save a non-current message, type:
? s <message number> filename

Command-Line Mail

B-13

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

B
Printing a Mail Message
Use the lp command with the pipe (|) symbol to print a mail message
within mailx.

Command Format
? |number lp

Sending a Message to the Printer


? 1
Message 1:
From user3@saturn Mon Aug 2 14:44 PST 1999
Date: Mon, 2 Aug 1999 14:45:21 PST
From: user3@saturn
To: user2@venus
Subject: About lunch!
I have no plans for lunch, and would be happy
to join you.
user 3
? |1 lp
Pipe to: "lp"
request id is printer1-9 (standard input)
"lp" 16/334
?
The mail message is printed to your default printer.

B-14

You can specify a destination printer by using the lp -d printername option.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

B
Quitting Mail
Use the q (quit) command to save changes and exit mailx. Read and
unread messages are automatically stored.
If you exit using q, unread messages remain in
/var/mail/username. By default, read messages are stored in the
mbox file in your home directory.
It is good practice to save messages that contain important information
in a separate file and to clean out your mbox on a regular basis as it can
grow quite large.
Use the x command to exit mailx without saving changes.
To access messages stored in your mbox file, type:
$ mailx -f
mailx version 5.0 Thu Aug 5 10:36:57
"/export/home/user2/mbox": 5 messages
>0
1
user1
Mon Aug 14 09:08
0
2
user5
Mon Aug 14 10:25
0
3
user3
Mon Aug 14 10:52
0
4
user1
Mon Aug 14 11:58
0
5
user4
Mon Aug 14 12:02
0
6
user3
Mon Aug 14 14:45
0
7
user4
Mon Aug 14 14:53
?

Command-Line Mail

PDT 1999 Type? for help.


15/342
90/555
33/912
45/215
16/347
16/334
14/326

News
Meeting
Project
Deadline
Interview
About lunch!
Your lunch

B-15

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

B
Sending a File Using Mail
Use the mailx command and standard input redirection to send
someone a file. For example:
$ mailx user3@saturn < dante
$
Using the above command with the -s option allows you to include a
subject line.
$ mailx -s "myfile" user3@saturn < dante
$
Note When writing mail messages, remember to press Return at the
end of each line. There is no automatic line wrap with mail.

B-16

Note A piece of email is not a single file. A piece of email is made into pages, which are
appended into one file. By default, the storage area for all mail messages is
/var/mail/username.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

B
Creating a Mail Alias
A mail alias is a group of user names (login IDs) in a single file. Use
mail aliases when you want to send the same message to a group of
users. A mail alias is also called a distribution list.

Command Format
mailx aliasname
Use an editor to add mail aliases to your.mailrc file, which is located
in your home (or login) directory. The .mailrc file is used to store
private mail aliases and variables relating to the mail program. Your
system administrator can set up public mail aliases, available for any
user on the system to use, in the /etc/aliases file.
You can use any editor to create or add mail aliases to the .mailrc file.
Create one mail alias per line, and then save the changes. For example:
$ cd
$ vi .mailrc
alias class user3@saturn user4@jupiter user5@earth
~
~
~
".mailrc" [newfile]
:wq

$ mailx class
Subject: test!
This is a test of my newly created alias
user2
.
EOT

Command-Line Mail

B-17

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

B
Using Tilde Commands
While composing a letter, you can use tilde commands to perform a
variety of functions.

Command Format
~ single character [string]
Table B-2 lists some of the more useful tilde commands.
Note If you want to include a literal tilde character in a letter, type
two tildes in succession. Only one tilde will be displayed.
Table B-2 Tilde Commands and Functions

B-18

Command

Function

~!command

Escapes to a shell command

~.

Simulates pressing Control-d to mark end of file

~?

Lists a summary of tilde commands

~b username

Adds user name(s) to the blind carbon copies (Bcc:) list

~c username

Adds user name(s) to the carbon copies (Cc:) list

~f number

Forwards the specified letter; valid only when sending a message


while reading mail

~h

Prompts for header lines: Subject, To, Cc, and Bcc

~r filename

Reads in the text from the specified file

~t name

Adds the specified name(s) to the To list

~p

Prints the message being entered to the screen

~s string

Changes the subject line to string

~t name

Adds the specified name(s) to the To list

~m number

Inserts text from the specified letter into the current letter; valid
only when sending a message while reading mail

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

B
Using Tilde Commands
The following example demonstrates the use of some of the tilde
commands to make a change to the Subject line (~s string) and to
refresh and print the message being entered to the screen (~p):
$ mailx all_staff_alias
Subject: Meeting Today
There will be a staff meeting at 3:00 p.m. today
~s Staff meeting 3:00 p.m. Today
in the large conference room.
Please be prompt.
~p
---------Message contains:
To: all_staff_alias
Subject: Staff Meeting 3:00 p.m. Today
There will be a staff meeting at 3:00 p.m. today
in the large conference room.
Please be prompt.
(continue)
.
EOT

Command-Line Mail

B-19

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Workshop Lab Solutions

This appendix provides suggested solutions for the Workshop Labs


presented in the text. These solutions are only one way to solve each
problem. Many of the scenarios have multiple solutions and no one
solution is the correct answer.

C-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

C
Module 1 Solaris Computing Environment
1. Because the user had not saved the work done before the power
outage, it was still in RAM memory. Both RAM and swap are
cleaned out on reboot. Thus, the work was lost.
2. The user could save work to another workstations disk, to tape, or
to diskette.

C-2

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

C
Module 2 Accessing Your System
1. The employee may not have been able to log in to the system
because he or she forgot or mistyped the password, the system
administrator changed the password for various reasons, the login
ID was incorrect, or he or she does not have an active account yet.
2. The system administrator must set the user up to log in to a
specific shell environment. This information is kept in the
/etc/passwd file.

Workshop Lab Solutions

C-3

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

C
Module 3 Introduction to the Common Desktop Environment
1.
a.

Change names of workstation buttons.

b. Use Style Manager.


c.

Use option in Style Manager.

d. Use exit option in Style Manager.


2. Drop icon from Application Manager, Desktop_Apps window
onto Install Icon part of subpanel. Use Promote to Front Panel
menu option to put icon on the Front Panel.
3. Putting your mouse pointer in a blank space on the Front Panel,
click on Add Icon. Then drop Calculator icon from the Application
Manager, Desktop_Apps window on the new space in the Front
Panel.

C-4

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

C
Module 4 Getting Help
1. Use Front Panel Help to get information on Calendar Manager. If
difficulties arise with specifics after using the general help, use
application-specific help by clicking on the Help menu in the
upper right corner of the Calendar Manager window.
2. Look at the man page for the /etc/passwd file by using:
$ man -s 4 passwd

Workshop Lab Solutions

C-5

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

C
Module 5 Accessing Files and Directories
1. Look at the man page for an option to the ls command that will
display directory listings with last access time rather than last
modified time.
2. You can either use:
$ ls /usr/bin/c*
or
$ man -k calendar

C-6

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

C
Module 6 Directory and File Commands
1. Look in the /etc/passwd file.
2. Use the mkdir command to create the directory. Then, using
$ ls -F
identify the executable file(s) to be copied to the new directory.
3. Use:
$ man -k shell > ~/shell_commands

Workshop Lab Solutions

C-7

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

C
Module 8 File Security
1. $ chmod 750 directory
2. $ mkdir ~/Textfiles
3. $ cd
$ cp file1 file2 dante fruit Textfiles
4. $ chmod 750 Textfiles
5. $ ls Textfiles > names; chmod 660 names

C-8

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

C
Module 10 Bourne and Korn Shell Variables
1.$ mkdir $HOME/dir1/coffees/flavors

Workshop Lab Solutions

C-9

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

C
Module 12 Basic Features of the Korn Shell
1. $ vi .kshrc
a.

set -o noclobber

b. alias p=pwd
alias l=ls -l
c.

set -o vi

2. $ vi .profile
ENV=$HOME/.kshrc; export ENV
3. $ . .profile
$ . .kshrc

C-10

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

C
Module 14 File and User Information Utilities
1. On Monday:
$ who > timely
On Tuesday through Friday:
$ who >> timely
$ sort timely | tee good.news | lp
2. $ find /etc -type d 2>/dev/null > ~/bin/file
3.$ grep -i ^[a-f] file | sort -b +1 -o file2
4. $ which cp
$ ls -i /usr/bin/cp
$ find /usr/bin -inum inode 2> /dev/null

Workshop Lab Solutions

C-11

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

C
Module 15 Backing Up and Restoring
1. $ cd
$ tar cvf bin.tar bin
$ compress bin.tar
$ chmod 660 bin.tar.Z
You also need to check permissions on ~/bin directory to make
sure they are set at at least 750.

C-12

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

C
Module 16 System Processes and Memory Management
1. $ find / -name core 2> /dev/null -exec rm {} \; &
$ jobs
$ fg %1
^Z
$ bg %1
2.$ fg %1
^Z

Workshop Lab Solutions

C-13

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

C
Module 17 Network Basics
1. $ jobs
$ fg %1
(If the command is no longer running, start a sleep 2000 in the
background to finish the exercise.)
2. $ rlogin -l my_user my_machine
$ pkill find

C-14

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Metacharacters

This appendix provides a quick reference to the metacharacters


covered in this course.

D-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

D
Introduction to Metacharacters
Table D-1 shows some of the metacharacters you can use in the
Solaris 7 environment.
Table D-1 Metacharacter Quick Reference
Metacharacter

Description

Command Format

Example(s)

; (semicolon)

Enables you to
enter multiple
commands on a
single command
line.

command;command

date;cal;who

* (asterisk)

Represents any
character or
characters.

ls d*

? (question
mark)

Matches any
single character.

ls dir?

[ ] (square
brackets)

Matches a set or
range of
characters for a
single character
position.

[range]

ls [b-f]*
ls [bf]*
ls [cab]*
ls [A-z]*

D-2

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

D
Table D-1 Metacharacter Quick Reference
Metacharacter

Description

Command Format

Example(s)

>, <, 2>, >>


(angle
brackets for
redirection)

> Redirects the


output of a
command to a file
rather than to the
screen.
< Redirects the
input to a
command from a
file rather than
from the
keyboard.
2> Redirects
error from a
command to a file
rather than to the
screen.
>> Appends
the output of a
command to an
existing file.

command > file

ls /etc > etc.list

command < file

mailx user2@saturn <


/etc/hosts

command 2> file

Date 2> errorfile


cat errorfile

command >> file

cal 1 1996 >> mon00


cat mon00

Takes the output


of one command
and passes it as
input into the
following
command.

command | command

ls -l /etc | more

| (pipe)

Metacharacters

D-3

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

Introduction to sedand awk

This appendix provides reference information on the sed and awk


commands. These commands are powerful editing tools that permit
manipulation of data.

E-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

E
Regular Expressions
Regular expressions are commonly used as a means of defining data
strings for manipulation with the vi editor. However, regular
expressions can also be used with several additional UNIX tools and
utilities. Some characteristics of regular expressions are they:

Represent data strings

Are defined the same for multiple utilities

Use symbols to represent different types of data

Table E-1 Regular Expressions

E-2

Regular Expression

Definition

Represents a single character position that matches any


ASCII character.

x*

Represents 0 or more occurrences of the preceding


expression (x).

[charset]
[char-range]

Is a single character position, matching any one ASCII


character listed as a charset or as a char-range; for
example, [AaBbCc] or [A-Ca-c] would both represent
either upper or lowercase a, b, or c.

[^charset]

Is a single character position that does not match any


character within the charset or char-range.

Is the beginning of line marker.

Is the end of line marker.

Disables the following special symbol. (It is also used


when referencing tagged expressions.)

\(string\)

Defines an expression that can be called in numeric


order for replacement values.

\{m,n\}
\{m,\}
\{m\}

Is used to define the number of occurrences to


match; for example, \{3\} would represent 3
occurrences exactly, \{1,\} would represent one or
more occurrences of the preceding character, and
\{1,5\} would represent at least one but no more than
5 characters inclusively.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

E
Using Noninteractive Power Tools: sed
The streaming editor, sed, enables you to edit data from the command
line. Using regular expressions to define text, the sed command can
take input from a file or from another command, alter the data, and
produce standard output. The sed command:

Reads standard input

Produces standard output

Utilizes regular expressions

Reads a command file

Implements multiple edits in one pass

Uses the same command and expression syntax as vi

Command Format
sed expression [ filename ]

expression Represents the edit that is desired. This expression can


include line numbers and/or regular expressions,
along with some type of editing command. Multiple
expressions can be defined on the command line, or a
command file (sed script) can be created for later use.
filename

Lists file(s) sed is to work on. If sed is to be used as part


of a pipe, the filename can be omitted from the sed
syntax; for example, ls -l | sed expression.

Introduction to sed and awk

E-3

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

E
Using Noninteractive Power Tools: sed
Table E-2 Commonly Used sed Expressions
Expression

Definition

n
n,m

Uses line n only.


Uses line numbers n through m.
(If line numbers are not specified, the sed command affects
each line unless a search string is specified.)

s/old/new/[g]

Substitutes the new data for the old data.


The sed command substitutes only the first occurrence per
line unless the global option g is included.

-e expression

Enables the sed command to recognize more than one


expression per command line. When using more than one
expression, each expression must be preceded with the e indicator.

-f scriptname

Enables the sed command to get editing instructions from a


script called scriptname.
The referenced script contains all the desired edit commands.

/pattern/command

Searches for any line containing pattern and performs the


command .

Table E-3 Commonly Used Edit Commands

E-4

Command

Definition

a\
text string

Appends the following text string after the referenced


line.

c\
text string

Changes the referenced line(s) to the following text string.

i\
text string

Inserts the following text string before the referenced line.

Deletes the referenced line(s).

r filename

Reads in text from filename after the referenced line(s).

w filename

Writes all referenced lines to filename.

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

E
Using Noninteractive Power Tools: sed
Removing Characters With sed
This example shows how to search for lines containing a string
and remove those lines.

% ls -l | sed /^total/d > ls.data


% cat ls.data
-rw-r--r-1 laugh
other
315
-rw-r--r-1 laugh
other
66
-rw-r--r-1 laugh
other
66
-rw-r--r-1 laugh
other
66
-rw-r--r-1 laugh
other
46598
-rw-r--r-1 laugh
other
1409

Mar 2 16:35 field2


Feb 28 15:22 filea
Feb 28 15:33 fileb
Feb 28 15:32 filec
Mar 2 15:59 next
Mar 2 16:14 next.tab

Placing Characters at the End of Each Line


% sed s/Feb.*$/& <==/
-rw-r--r-1 laugh
-rw-r--r-1 laugh
-rw-r--r-1 laugh
-rw-r--r-1 laugh
-rw-r--r-1 laugh
-rw-r--r-1 laugh

ls.data
other
other
other
other
other
other

315
66
66
66
46598
1409

Mar 2 16:35 field2


Feb 28 15:22 filea <==
Feb 28 15:33 fileb <==
Feb 28 15:32 filec <==
Mar 2 15:59 next
Mar 2 16:14 next.tab

Syntax would read "For any line containing Feb, followed by any
number of characters to the end of the line, print this line with <=== at
the end."

Introduction to sed and awk

E-5

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

E
Using Noninteractive Power Tools: sed
Changing White Space to Colons in Data
% sed -e s/ \{1,\}/:/g -e s/Feb.*$/& <==/ ls.data
-rw-r--r--:1:laugh:other:315:Mar:2:16:35:field2
-rw-r--r--:1:laugh:other:66:Feb:28:15:22:filea <==
-rw-r--r--:1:laugh:other:66:Feb:28:15:33:fileb <==
-rw-r--r--:1:laugh:other:66:Feb:28:15:32:filec <==
-rw-r--r--:1:laugh:other:46598:Mar:2:15:59:next
-rw-r--r--:1:laugh:other:1409:Mar:2:16:14:next.tab

Syntax would read, "sed, search for at least one or more spaces, and
replace all spaces that are found together with a single colon."

E-6

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

E
Using Noninteractive Power Tools: awk
The awk utility gives you virtually unlimited control over the format of
your data. With a relatively simple syntax, awk can manipulate
columns of data. In its most advanced usage, awk can be used to write
very complex programs to format, manipulate, and perform
mathematical computations on data. This appendix covers some of the
more basic uses of awk, including:

Reordering columns

Performing format changes to data

Adding to existing data

Reading standard input

Producing standard output

Command Format
awk options { action } [ filename ]
The option section of the awk command line can represent a single
character option followed by an argument, or can be a complex
definition statement. This appendix focuses on the single character
option used to define the input field separator. If you need a more
complex definition statement, refer to the AnswerBookTM on-line
documentation set or the on-line manual pages for more information.
Option
-Fc

Define c as the field separator. Blanks (any number


of spaces and tabs) are the default.

Example awk Command Line


$ awk -F: {action} /etc/passwd
$ ls -l | awk {action}

Introduction to sed and awk

E-7

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

E
Using Noninteractive Power Tools: awk
Most often you will use the action statement of print to instruct the
awk command to print the fields of each record in the pattern that you
want. The action statement must be enclosed within curly braces
({}), and must be surrounded by single quotes. When defining the
desired pattern, the fields are represented in the numeric order that
they are found in the data. Each field number will be preceded with a
dollar sign ($). Commas (,) produce spaces in the output.

Using awk to Display Specific Data


-rw-r--r--

laugh

other

1409

$1

$2

$3

$4

$5

Mar

$6 $7

16:14

next.tab

$8

$9

$0

$ ls -l | awk {print $9,$5}


field3 405
filea 66
fileb 66
filec 66
next 46598
next.tab 1409

E-8

Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

E
Using Noninteractive Power Tools: awk
Using the awk Command to Add Text to Data
$ ls -l | awk {print $9,"is using",$5,"bytes"}
field3 is using 405 bytes
filea is using 66 bytes
fileb is using 66 bytes
filec is using 66 bytes
next is using 46598 bytes
next.tab is using 1409 bytes

Be sure to note the text is surrounded in double quotes, and is


separated by commas as if it were an incoming field.

Using the awk Command to Change the Format of Data


$ ls -l | awk {print $3,"Tab",$9,"Tab",$6,$7}
laugh
field3
Mar 2
laugh
filea Feb 28
laugh
fileb Feb 28
laugh
filec Feb 28
laugh
next
Mar 2
laugh
next.tab
Mar 2

Note that the column alignment may look different on your screen due
to data content.
Note nawk (new awk) is an updated version of awk that provides
extended capabilities unavailable in previous versions. Until a user
begins using the more complex programming capabilities of awk,
however, the behavior of nawk and awk are identical.

Introduction to sed and awk

E-9

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D

S-ar putea să vă placă și