Documente Academic
Documente Profesional
Documente Cultură
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.
Additional Resources
Additional resources The following reference can provide additional
details on the topics discussed in this module:
2-2
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.
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
2-4
Be unique
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
Default shell Defines which shell the user will have upon login.
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
2-6
Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Make a window active by clicking the left mouse button while the
mouse pointer is in that window area
Select a File or Folder icon while working with the File Manager
2-7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
2
The Mouse Buttons
The Left Mouse Button
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
You can log in using the login screen shown, or at the command line.
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.
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.
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.
2-14
Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
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
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.
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.
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
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.
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. .
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.
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.
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.
2-27
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
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.
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.
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.
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:
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
Objectives
Upon completion of this module, you should be able to
Rename workspaces
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.
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
3-3
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
3-4
Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
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.
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
3-7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
3-8
Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
3
Workspace Buttons
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:
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
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
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
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
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.
3-19
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
3-20
Color Set the color attributes of the windows and the workspace
background
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
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.
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
3-25
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
3
Style Manager Options
Mouse
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.
3-27
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
3
Style Manager Options
Screen
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.
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
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.
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:
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.
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:
Rename workspaces
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:
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.
4-2
Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
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
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
4-10
Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
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
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
Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Return
/string
Getting Help
4-15
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
nispasswd(1),
crypt(3C),
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
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
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
Objectives
Upon completion of this module you should be able to:
Access files and directories within the file structure using absolute
and relative pathnames
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
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
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
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.
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.
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:
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:
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
options
argument
Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
5
Command-Line Syntax
cal
cal 1987
date
date -u
banner "hi there"
(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
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
5-13
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
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 (.).
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
..
~-
~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
5-17
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
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
$
dante1 dir2
dir1
dir3
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
Symbol
Directory
Executable
(none)
Symbolic link
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.
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.
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.)
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.
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
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
$
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
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
$
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
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__________________________________________________
dir3___________________________________
flowers___________________________________________
recipes___________________________________________
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.
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.
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
dir3
dir3
flowers
dir4/flowers
recipes
dir2/recipes
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
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?
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
Access files and directories within the file structure using absolute
and relative pathnames
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?
5-43
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Objectives
Upon completion of this module, you should be able to
Display the contents of text files using the cat, more, head, and
tail commands
Create empty files or update access time of existing files using the
touch command
Manage files and directories using the mv, cp, and rm commands
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.
Additional Resources
Additional resources The following reference can provide additional
details on the topics discussed in this module:
6-2
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.
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
Control-q
Control-c
Control-d
Control-u
Control-w
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
The file command determines file type by referencing the first two bytes of the file. See
the contents of /etc/magic.
6-5
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
6
Determining File Type
Command Format
file filename(s)
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.
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.
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
Return
/string
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.
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.
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.
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.
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
-c
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
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.
6-23
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
6
File and Directory Naming Conventions
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.
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.
6-25
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision 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.
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.
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
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
fruit
trees
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
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
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.
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
$
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
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)
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
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)
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
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
6-43
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
6
Redirection
Overview
These are defined as follows:
Command
Standard
output
6-44
or
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.
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.
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.
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.
ls ~ | tee homedir | lp
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.
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.
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
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
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
Display the contents of text files using the cat, more, head, and
tail commands
Create empty files or update access time of existing files using the
touch command
Manage files and directories using the mv, cp, and rm commands
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?
6-57
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Objectives
Upon completion of this module, you should be able to:
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.
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
7-3
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
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
Standard file
Folder icon
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.
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
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.
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:
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
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
Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
7
Folder or File Name Conflicts
7-13
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
7
Changing Folders
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
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*
*s
??a
[Aa]*
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
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
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.
7-19
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
7
Selected Menu Options
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.
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.
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
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.
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:
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:
Set and change file permissions using symbolic and octal notation
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.
Additional Resources
Additional resources The following reference can provide additional
details on the topics discussed in this module:
8-2
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 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--
-rw-r--r-File type
User
Group
Others
Figure 8-1
8-6
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
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
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
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.
-rwx-----
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
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.
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
who
op
permission(s)
r Read
w Write
x Execute
= Set permissions
- Remove access
+ Give access
u
g
o
a
8-16
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:
$ 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
staff
Jun 11 1:44
dante
There is no space after u+x and before go+r,although there is a comma between them.
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
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 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
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:
File Security
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.
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-
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
8-24
666
022
644
777
022
755
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
027
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.
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.
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
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___
-rwxrwxr-x
user: read X
group: read X
others: read___
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
Set and change file permissions using symbolic and octal notation
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
Objectives
Upon completion of this module, you should be able to:
Start vi
Create text in vi
Delete text in vi
Set vi options
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.
Additional Resources
Additional resources The following reference can provide additional
details on the topics discussed in this module:
9-2
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.
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
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
vi
vi -r filename
view filename
vedit filename
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
Command
Meaning
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
j or
k or
0 (zero) or ^
Return
Control-f
Control-d
Control-b
Control-u
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
Command
Meaning
x (lowercase)
X (uppercase)
dw
3dw
dd
3dd
dG
d1G
:5,10d
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
3cw
i (Return)
Break line
xp
:u
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
Command
Meaning
yy
:1,3 co 5
:4,6 m 8
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).
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
Command
Meaning
:w
:w new_filename
:wq
ZZ
:q!
:wq!
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:
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
Command
Meaning
:set nu
:set nonu
:set ic
:set noic
:set list
:set nolist
:set showmode
:set noshowmode
:set
:set all
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
Command
Meaning
1G
:21
Go to line 21
21G
Go to line 21
To clear the screen or insert files, use the following options:
Meaning
Control-L
:r filename
:34 r filename
9-14
Command
Meaning
/string
?string
:%s/old/new/g
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.
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.
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
Start vi
Create text in vi
Delete text in vi
Set vi options
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?
9-19
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
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
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.
Additional Resources
Additional resources The following references can provide
additional details on the topics discussed in this module:
10-2
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.
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.
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
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.
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
$ 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.
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
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
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
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
The whence command, which is built into the Korn shell, does the same thing as which.
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.
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.
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.
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
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
Describe where the initialization files are located and what types
of settings can be defined
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.
Additional Resources
Additional resources The following references can provide
additional details on the topics discussed in this module:
11-2
Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
11
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
Checks if you have mail and will print a mail message upon login
11-5
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
11
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:
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
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
Bourne
Korn
.kshrc
.cshrc
Initialization Files
11-9
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
11
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
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
Command Format
ENV=$HOME/filename; export ENV
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
Describe where the initialization files are located and what types
of settings can be defined
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
12
Objectives
Upon completion of this module, you should be able to:
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.
Additional Resources
Additional resources The following references can provide
additional details on the topics discussed in this module:
12-2
Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
12
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
Command Format
PS1=value
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
Command Format
alias aliasname=value
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.
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
12-9
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
12
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.
12-11
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
12
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
12-13
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
12
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
12-15
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
12
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
cw
Change word
Note The arrow keys cannot be used to reposition the cursor during
in-line editing.
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
No
Noa
Yes
No
Yes
Yes
No
Yes
Yes
No
Yes
Yes
No
Yes
Yes
Logout file
No
Yes
No
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.
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.
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.
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
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
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?
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:
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.
13-2
Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
13
Command Format
lp [ -options] [filename(s)]
Options
-d
-o nobanner
-n
-m
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
Command Format
lpstat [-options]
Options
-p
-o
-d
-t
-s
-a
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.
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
$
Printing
13-7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
13
Command Format
cancel request-ID
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
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
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
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
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
14
Objectives
Upon completion of this module, you should be able to:
Switch to a new user ID and identify the user ID you are currently
using
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.
Additional Resources
Additional resources The following references can provide
additional details on the topics discussed in this module:
14-2
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.
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
14-6
Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
14
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
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
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
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
expression
Search Expressions
Definition
-name filename
-type filetype
-mtime [+|-]n
-atime [+|-]n
-inum n
-user loginid
-group groupid
-perm mode
-size [+|-]n[c]
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 {} \;
-ls
14-14
-o
-a
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 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>
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, 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
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
-v
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
Command Format
su [-] username
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
Command Format
id [option(s)]
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
Command Format
who [option(s)]
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
Command Format
who am i
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
Multilevel sorting
Field-specific sorting
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
Options
14-28
-n
(+|-)n
Begin (+) or end (-) the sort with the field following
the nth separator.
-r
-f
+nM
-d
-o 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
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:
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.
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?
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:
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'
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
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
Switch to a new user ID and identify the user ID you are currently
using
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?
14-39
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
15
Objectives
Upon completion of this module, you should be able to:
Use the jar command to save and compress files and directories
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.
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
15-3
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
15
Command Format
tar function_[letter/modifier] [output file] filename(s)/directory(s)
Function Letters
c
Function Modifiers
15-4
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
15-5
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
15
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
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.
Uncompressing a File
$ uncompress bin.file.Z
15-7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
15
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
dir1
dir2
dir3
dir4
file1
file2
file3
file4
fruit
fruit2
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
rewind
retension
erase
fsf
bsf
eom
off
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
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
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.
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
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 jar command to save and compress files and directories
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
16
Objectives
Upon completion of this module, you should be able to:
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.
Additional Resources
Additional resources The following reference can provide additional
details on the topics discussed in this module:
16-2
Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
16
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.
16-5
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
16
Command Format
ps [-options]
Options
-e
-f
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
Description
PID
PPID
TTY
TIME
CMD
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
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.
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
fg %n
bg %n
kill %n
Control-c
Control-z
16-10
Argument
Meaning
>
trash
2>
/dev/null
&
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]
3923
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 . . .
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
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.
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.
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.
TTY
console
pts/0
pts/1
TIME
0:01
0:01
0:00
COMD
ksh
find
ps
16-15
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
16
Terminating Processes
The kill Command
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
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
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.
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.
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:
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:
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.
Additional Resources
Additional resources The following reference can provide additional
details on the topics discussed in this module:
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
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
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
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
$
Network Basics
17-7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
17
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
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
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
Command Format
rusers [-option(s)] [hostname]
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
17-17
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
17
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
17-20
Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
17
Does not maintain any status information about the files opened
by clients, so there are no dependencies between server and clients
Network Basics
17-21
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
17
17-22
Mounts the desired file system which has been authorized by the
NFS system server
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
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
18
Objectives
Upon completion of this module, you should be able to:
View your calendar in the four formats: Day, Week, Month, and
Year
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.
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
Message viewing
area
18-3
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
18
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
18-5
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
18
Increasing and Decreasing the Message Viewing Area
18-6
Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
18
18-7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
18
Responding to a Received Message
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
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
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.
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
18-15
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
18
Attaching Files to Mail Messages
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
18-17
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
18
18-18
Specifying how often you would like the system to check for new
mail
Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
18
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.
18-21
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
18
Viewing the Calendar
Week View
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.
18-23
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
18
Adding an Appointment
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.
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
18-27
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
18
Privacy controls
Appointment reminders
18-28
Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
18
Printing Calendar Appointments
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.
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.
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
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.
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.
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.
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.
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
View your calendar in the four formats: Day, Week, Month, and
Year
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?
18-43
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
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.
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.
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)])
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.
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.
% ^z^s
lp -d staffp feathers
request id is staffp-5 ( 1 file )
%
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
!!
!*
!$
!number
!n:p
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
%
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
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
%
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
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
Command Format
alias alias_name value
Setting Aliases
% alias c clear
% alias gohome cd;ls
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
Sending mail from the command line using the mailx program
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:
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.
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+
z-
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:
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
>
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 ]
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
B-14
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
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
~.
~?
~b username
~c username
~f number
~h
~r filename
~t name
~p
~s string
~t name
~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
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.
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.
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
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
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
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
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
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
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)
command | command
ls -l /etc | more
| (pipe)
Metacharacters
D-3
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
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:
E-2
Regular Expression
Definition
x*
[charset]
[char-range]
[^charset]
\(string\)
\{m,n\}
\{m,\}
\{m\}
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:
Command Format
sed expression [ filename ]
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
s/old/new/[g]
-e expression
-f scriptname
/pattern/command
E-4
Command
Definition
a\
text string
c\
text string
i\
text string
r filename
w 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.data
other
other
other
other
other
other
315
66
66
66
46598
1409
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."
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
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
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.
laugh
other
1409
$1
$2
$3
$4
$5
Mar
$6 $7
16:14
next.tab
$8
$9
$0
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
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.
E-9
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D