1 of 45 Chapter 3: Getting Started Amir Afzal UNIX Unbounded, 5th Edition Copyright ©2008 UNIX...
-
Upload
elaine-hawkins -
Category
Documents
-
view
225 -
download
0
Transcript of 1 of 45 Chapter 3: Getting Started Amir Afzal UNIX Unbounded, 5th Edition Copyright ©2008 UNIX...
1 of 45Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
UNIX Unbounded 5th EditionAmir Afzal
Chapter 3Getting Started
Copyright ©2008 by Pearson Education, Inc.Upper Saddle River, New Jersey 07458
All rights reserved.
2 of 45Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Chapter 3The UNIX Operating System
This chapter explains how to start and end (log in and log out) a UNIX session. It also explains the function of passwords and how to change your password. Then after showing the command line format, the chapter introduces a few simple UNIX commands and explains their applications. It also describes how you can correct typing mistakes. Finally, the process of establishing contact with UNIX is explored in more detail, and some internal UNIX operations are discussed.
3 of 45Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-1 The Login Prompt
3.1: ESTABLISHING CONTACT WITH UNIXThe process of establishing contact with the UNIX operating system consists of a number of prompts and user inputs that start and end a session.
• A session is a period of time during which you use the computer
Logging InThe process of identifying yourself and letting UNIX know that you want to use the system is called the logging-in process.
• The first thing you must do to use a UNIX system is log in
4 of 45Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-2 The Password Prompt
Login Name • When your account is created, your login name (also called User ID or User Name) and password also are established
• Your User ID is unique and identifies you to the system
• Respond to the login: prompt by typing your User ID and then pressing [Return]
• After you type your User ID UNIX system displays the password: prompt
(for this example, we will use david)
5 of 45Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Password
• A password is a sequence of letters and digits used by UNIX to verify that the user is allowed to use the system
• Type your password and then press [Return]
• The UNIX system displays some messages
• The UNIX system displays the system prompt
• The standard prompt is usually a dollar sign ($) or a percent sign (%)
6 of 45Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-3 The Logging-in Process
7 of 45Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-4 Incorrect Login
If you make a mistake and enter the wrong user ID or password, UNIX displays a message and the login: prompt will appear again, ready for you to enter your User ID.
8 of 45Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-5: The Old Password Prompt
3.1.2 Changing Your Password: The passwd Command
The passwd command changes your current password. If you do not have a password, it creates one.
• Type passwd and press [Return] (UNIX displays the Old password: prompt)
• Enter your current password and press [Return] (UNIX displays the New password: prompt)
Figure 3-6 New Password Prompt
9 of 45Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-7 Re-Enter New Password Prompt
• Enter your new password (UNIX shows the Re-enter new password: prompt)
• Retype the new password (UNIX is verifies that you did not make a mistake)
10 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-8 Sample of Error Messages
Password Format Your password must comply with the following criteria:
• The new password must differ from the old one by at least three characters
• The password must be at least six characters long and must contain at least two characters and one number
• The password must differ from your User ID
If UNIX detects anything wrong with your password, it displays an error message and shows the New password: prompt again.
11 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-9 Changing a Password in the Linux Environment
The wordings of the prompts are slightly different for the Linux system, but thecommand and sequence of prompts are the same.
12 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-10 Sample of Error Messages
13 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
3.1.3 General Rules for Choosing Passwords
• Do not use a dictionary word (in any language)
• Do not use the name of a person, pet, location, or a character from a book
• Do not use any variation of your name and ID/account name
• Do not use known information about you, such as your phone number, birthday, and so on
• Do not use a simple pattern or easy sequence of keyboard keys
14 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Tips for Creating and Safeguarding Your Password
Make a habit of protecting your password by observing the following rules:
• Do not write down your password—try to memorize it
• Do not place your password in a file
• Do not use the same password for all of your password-protected systems and activities
• Do not reveal your password to anyone
• Do not let anyone watch you entering your password
• Choose a “hard-to-guess” password
15 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
3.1.4 Logging Off
• The process of signing off when you have finished with the system is called logging off or logging out
• To log off, press [Ctrl-d], which means to simultaneously hold down the key labeled Ctrl (for Control) and press the letter d
• UNIX responds first by displaying logging off messages
• Then UNIX shows the system’s standard welcome message and login: prompt
16 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-11: The Logging-In and Logging-Out Process
17 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-12 The Command Line Format
3.2.2 Basic Command Line StructureEach command line consists of three fields:
• Command name
• Options
• Arguments
18 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-13 The date Command
3.2.3 Date and Time Display: The date Command
• The date command displays the current date and time on the screen
• The date and time are set by the system administrator and users cannot change them
19 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
3.2.4 Information on Users: The who Command
• The who command lists the login names, terminal lines, and login times of the users who are currently logged on the system
• The who command is used to check the level of activity in the system or to find out whether a particular person is on the system
20 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-14 The who Command
1. The first column shows the login name of the user
2. The second column identifies the terminal being used
3. The tty number gives you some indication about the location of the terminal
4. The third and fourth columns show the date and time that each user logged in
21 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-15: The who Command with am i Argument
• Type who am I or who am I (UNIX displays who the system thinks you are)
22 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
who Options
Table 3.1 lists some of the who command options • Linux also provides some alternative and new options
• Under Linux, some of these options are not available, or some of the options outputs are slightly different
1. Linux new and alternative options are listed under the Linux heading in Table 3.1
2. Linux new and alternative options are preceded by two minus signs (--)
Table 3.1 The who Command Options
Option Linux Operation
-q --count The quick who; just displays the name and number of users
-H --heading Displays heading above each column
-b Displays the time and date of the last reboot
--help Displays a usage message
23 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-16A The who Command with -H Option
Figure 3-16B The who Command Using Linux --heading Option
24 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-17A The who Command with -q Option
Figure 3-17B The who Command Using Linux --count Option
25 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-18 The who Command with -b Option
26 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-19 The who Command Using Linux --help Option
27 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
3.2.5: Display a Calendar: The cal Command
The cal command displays the calendar for the specified year.
• If the year and the month are both specified, then the calendar for just that month is displayed
• The default argument for the cal command is the current month
Displaying the calendar for the current month (see Figure 3.20). (Assuming current month, year is November 2005)
28 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-20 The cal Command with No Option
29 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-21 The cal Command Output
Notes:1. Type the specified year in full year value. For example, type cal 2010 (not cal 10)
2. Use the month number (1 to 12) and not the month name
3. The cal command without arguments displays calendar of the current month
4. The cal command with year argument but without month argument displays a calendar for the specified year
Displaying the calendar for November 2010.
30 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-22 Learn Utility Main Menu
3.3 GETTING HELP
3.3.1 Using the learn CommandThe learn command brings up a computer-aided instruction program that is arranged in a series of courses and lessons.
31 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-23 Help Utility Main Menu
3.3.2 Using the help CommandThe help command is more popular than the learn command and is available on many UNIX systems.
32 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
3.3.3 Getting More Information: The UNIX Manual
You can find a detailed description of the UNIX system in a large document called the User’s Manual.
• Some installation may have a printed copy of this manual
• The electronic version of the manual is stored on disk and is called the online manual
• The UNIX user’s manual is tersely written and difficult to read
• It is more like a reference guide than a true user’s manual
33 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
3.3.4 Using the Electronic Manual: The man Command
The man (manual) command shows pages from the online system documentation.
• Type man followed by the name of the command • You can use man to get the details about the commands
For example type: man cal [Return] (UNIX responds by showing a page similar to Figure 3.24)
Note:Nearly all UNIX installations provide the man pages, and the man command is the most popular way to obtain detailed information about command usage and options.
34 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-24 man Utility Display of cal
35 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
3.4 CORRECTING TYPING MISTAKES
The shell program interprets the command line after you press the [Return] key.
• Erasing Characters• Use the [Backspace] key for erasing characters or use [Ctrl-h] once for each character you intend to erase
• Erasing an Entire Line• You can erase an entire line any time before pressing [Return]
• [Ctrl-u] removes the entire command line and the cursor moves to a blank line
• The character that erases the entire line is called the kill character
• Terminating Program Execution• The character that terminates your running program is called the interrupt character
• On most systems, [Del] or [Ctrl-c] is assigned as the interrupt character
• The interrupt character stops the running program and causes the shell prompt $ to be displayed
36 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-25 UNIX Error Message
37 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
3.5 USING SHELLS AND UTILITIES
The shell is a program that handles user interaction with the UNIX system. The UNIX commands are processed by a shell that lies between the user and the other parts of the operating system.
Shell Commands• Some commands are part of the shell program; these built-in commands are recognized by the shell and are executed internally
Utility Programs• Most UNIX commands are executable programs (utilities) that the shell locates and executes
38 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
3.5.1 Kinds of Shells
Bourne Shell • The Bourne shell (sh) is the standard shell that is part of most UNIX operating systems
• It is usually the default shell on your system
• The prompt for the Bourne shell is the dollar sign ($)
Korn Shell • The Korn shell (ksh) is a superset of the Bourne shell • It has the basic syntax and features of the Bourne shell (sh) as well as many other features
• You can generally run the shell program written for sh under ksh without modifications • The prompt for the Korn shell is the dollar sign ($)
39 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
C Shell
• The C shell (csh) was developed at the University of California at Berkeley and is part of the BSD (Berkeley Software Distribution) version of UNIX
• The syntax of shell programming under the C shell is different from sh and ksh since it is a C language–style syntax • The prompt sign for C shell is the percent sign (%)
Bourne Again Shell
• Most UNIX systems provide more than one shell
• Linux comes with its own standard shell called the Bourne Again shell • The Bourne Again shell (bash) is based on the Bourne shell
• The Bourne Again shell is usually the default shell on Linux systems • The prompt for the Bourne Again shell is the dollar sign ($)
40 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
3.5.2 Changing Your Shell• Whatever shell you are using when you login to a UNIX system is assigned to your account by the system administrator
• You can easily change your current shell by typing the name of the shell you want to useFor example, the following sequence of commands changes your current shell from ksh to bash and back to ksh again:
$_ . . . . . . . . . . . . . . . . . . . . . Assuming you have Linux and your current shell is (ksh)
$ bash [Return] . . . . . . . . . . Change the current shell to bash
bash$_ . . . . . . . . . . . . . . . . . Prompt indicating the shell in use is bash
bash$ exit [Return] . . . . . . . Exit bash and return to ksh
$_ . . . . . . . . . . . . . . . . . . . . . .Prompt shows the shell in use is ksh
41 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-26 getty Displays the login: Prompt
3.6 MORE ABOUT THE LOGGING-IN PROCESS
42 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-27 login Displays the password: Prompt
43 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-28 The Shell Program Displays the $ Prompt
44 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-29 Logging-In and Logging-Off Cycle
45 of 45
Chapter 3: Getting Started
Amir AfzalUNIX Unbounded, 5th EditionCopyright ©2008
Figure 3-30 The Command Line Format