Friday, May 27, 2011

PART - I Fundamentals of the UNIX Systems Chapter1

Chapter 1. Getting started with UNIX

1.1 UNIX Shells

The core of the UNIX operating system is the kernel. It can be thought of as a piece of software that handles all the communications between user software and computer hardware. It is the kernel that decides how to communicate with peripheral devices, how to share time among users of the system, how to allocate memory for different programs running, and how to utilize the processor and other resources. The kernel keeps records of all programs (commonly called processes) running on the system and shares time among these processes according to a well-defined policy.

Users of the UNIX system don't have a direct interaction with the kernel. Instead, the user always works with a program called the UNIX shell. A shell can be considered a command interpreter. The shell takes user commands, interprets them, and takes the necessary action to execute them. It also provides the output of these commands to the user.

1.2 Logging In and Out of HP-UX

All HP-UX users are assigned a user name or login name and a password to access the system. Each user name is unique. When users want to start using the system, they enter the user name and password assigned to them. The process of entering this information is called the login process. Similarly to end a user session, the user issues a command (exit), and this process is called the logout process. The login and logout processes are necessary for system security so that only those authorized can use the system.

The Superuser

There is a special user in the UNIX systems called root. This user is created during the installation process of HP-UX. The root user has privileges to do all

system administration tasks, such as adding and deleting users, administration of printers, and other routine system maintenance tasks. Usually, the systems administrator uses the root user name. It is a common practice to call the root user the superuser to show the power associated with the name.

Each user in the UNIX system has a unique number associated with the user name, called a User ID. The root user has ID 0; therefore, any user with that ID has superuser privileges.

Logging In

When logging in, you'll see a login prompt on your terminal screen similar to the one shown in Figure 1-1.

Figure 1-1. HP-UX login prompt.

This prompt shows that the system is waiting for a user to enter a login name and password. At the login prompt, the user should enter the login name. The system then prompts for the password assigned to the login name. The user then enters the password. If the login name and the password match one of the users on the system, the user is allowed to log into the system. If the login name and password do not match an existing user, then access to the system is denied and the error message, Login incorrect, is displayed. Figure 1-2 shows an example of a complete login session where a user named boota logs into HP-UX.

Figure 1-2. Login session for user boota.

Once the user sees the $ symbol, the login process is complete.

Shell Prompts

As soon as a user logs into HP-UX, the shell assigned to the user starts and displays the shell prompt (also called the command prompt). Superuser and common user command prompts differ: $ represents a common user, while # represents a superuser. When you see either of these command prompts, you can issue any command for which you are authorized.


When you log in as the root user, be careful, as by your actions you can accidentally damage the system integrity.

Logging Out

Once you have finished working on HP-UX, you need to log out of the system. The logout process finishes your session. To log out, use the exit command at the shell prompt. The system will terminate your session and display the login prompt. A typical logout process is as follows.

$ exit


GenericSysName [HP Release B.11.00] (See /etc/issue)

Console Login :

Study Break

Logging In and Out as a Super- and Common User

Practice logging in to HP-UX with your own login name. Notice your command prompt. It must be a dollar ($) symbol. Use the exit command to log out of the system. When you see the login prompt again, log in as root (superuser) using the root password. The superuser prompt will be a pound symbol (#). Again log out with the exit command. Try the same procedure on another terminal.

1.3 Home Directory

Just after the login process, a user goes into a default directory set for that user. This default directory has a special significance and is called the user's home directory. Every HP-UX user has a predefined home directory that is created at the time of creating the user. Usually users' home directories are the same name as the user name and are placed in /home. For example, the home directory of user boota is /home/boota.

1.4 Using HP-UX Commands

Once you see the shell prompt, you must use HP-UX commands. Enter the command name and then press the Enter key to execute it. If the command is valid, the shell executes it and displays the result produced by the command.

The simplest command to use is the date command, which shows the current date and time on the system. For example, the date command will be used as follows.

$ date

Thu Aug 29 15:36:23 EDT 1999


If you enter a wrong command, the shell will display an error message. For example, the result of a misspelled date command is as follows.

$ daet

sh: daet: not found.


Now it is time to use some other simple commands like pwd, whoami, and uname.


Remember: A common user is not allowed to use the commands related to system administration tasks such as creating a new user or changing the system date and time. Only the superuser has the privilege to use such commands.

Extrinsic and Intrinsic Commands

Some of the commands that a user issues are intrinsic commands, which are built into the UNIX shell being used. Other commands, stored as separate files, are called extrinsic commands. When a user issues a command, the shell first checks if it is an intrinsic command. If it is not, then extrinsic commands are checked. The command for changing a directory (cd) is a typical intrinsic command, and the command for listing files (ls) is a typical extrinsic command. The extrinsic and intrinsic commands are also called external and internal commands, respectively.

Changing Your Password

Perhaps the first command every user should know is how to change the password. When the superuser or the system administrator creates a new account for you, your initial password is typically (but not always) set. When you log into HP-UX for the first time, you should change your password to secure your account. The password is changed with the passwd command. When you issue this command, you will be asked to enter the current password. For security reasons, this password will not be displayed on the screen. If you enter this old password correctly, you are prompted to enter the new password. Once you enter the new password and press the Enter key, the system will ask you to reenter the new password. Now you enter the new password again. A typical password changing session would be like the following.

$ passwd

Old password :

New password :

Re-enter new password :

Password changed


Please note that you must have a password between six and eight characters long, and it must be a combination of characters and numbers. At least two characters of the password must be letters and one must be a number or a special character, such as a dash (-), underscore (_), or asterisk (*). If you use a password of length greater than eight, any characters after the eighth character are ignored. For security reasons, it is better not to use any dictionary word as a password.

Shell History and Repeating Commands

The HP-UX shell keeps the last executed commands in a shell history. The shell history is used for future reference to the same commands or reexecuting the commands without retyping them. The command history is saved in a file called .sh_history (in which an underscore separates the characters .sh and the word history) for each user. This file is kept in the user's home directory. Users can

set the number of entries in the history through a control variable, which will be discussed later in Chapter 3.

To repeat a previous command, a user presses the - key combination. The previous command appears on the command prompt. If the user wants to go another step backward, simply pressing the key again moves one step back. Similarly, you can go back as far as you want until the history is finished. When the correct command is displayed, just press the key to execute it.

For example, consider you have used the following three commands in sequence.

$ date

Thu Aug 29 15:36:23 EDT 1999

$ whoami


$ pwd



Now you want to execute the date command again. Just press - once and you shall see that pwd command appears on the command prompt. Now press the key again and whoami will appear. Pressing the key for the third time, the date command will appear on the command prompt. Now you can execute the command by pressing the key.

The history command is designed to recall commands which have been used previously. For example, the following command shows the last three commands.

$ history -3





Command Aliases

An alias is a different name for a UNIX command. Aliases can also be used to remember commands by assigning them more meaningful names. They can be set using the alias command at the command prompt. For example, the ls command is used to list the file and directory names in HP-UX. If you want to use dir instead of ls, you can use an alias for that purpose as follows.

$ alias dir=ls


If after that you use dir command, it will function the same as the ls command does. Aliases are very useful for situations in which a user has to repeatedly issue a complex or long command.

1.5 Shell Startup Files

When you log into HP-UX, some commands are executed automatically and the environment is set for you (e.g., setting of variables that control the behavior of your shell). As an example, the history length is set at the login time. Similarly, it is possible to set how your shell prompt should appear, which printer should be used for your print requests, in which directories the shell should look for extrinsic commands you issue, and so on. All this is done through shell startup files. If you have a DOS or Windows background, these files can be considered as the AUTOEXEC.BAT file in DOS or the Startup Group in Microsoft Windows.

There are two types of startup files: the system startup file and the user startup files. The system startup file is common for all users of the system, while user startup files can be customized for every user.

System Startup File

The system startup file is used for tasks that are common to all system users. Examples of these tasks are setting your time zone (TZ), and the global search path for extrinsic commands. The system startup file is called profile and is present in the /etc directory of HP-UX. It is the responsibility of the system administrator to manage this file and make it more useful, keeping in mind a particular UNIX environment. The system startup file can also be used by a system administrator to send messages that are displayed to users as soon as someone logs into the system.

User Startup File

The user startup file is called .profile ("dot profile") and is placed in a user's home directory. This file is used for user-specific tasks, such as setting shell aliases, and for executing any programs that a user wants to start soon after login. A typical example of such a program is a customized environment used for database operators in which a form is displayed for entering data into the database. This file can also be used to change or modify some of the environment settings made by the superuser in the system startup file.

The system startup file is executed first in the startup procedure, and then the user startup file is executed. In addition to these two files, an HP-UX user can execute another file pointed to by the ENV variable if it is set in either of the two startup files.

Study Break

Using HP-UX Commands

Log in using the user name assigned to you and change your password. Try a new password fewer than six characters. Also try using a password containing all letters. Check if the system date and time are correct. Find out the name of your home directory using the pwd command. List files in your home directory with the ls -a command and write down the names of files that start with a dot (.) character. Create an alias for this command. Before logging out, use the history command to list all of the commands you have used.

1.6 Some Simple HP-UX Commands

In this section, I will describe some simple HP-UX commands. Some of these commands are very useful and handy, even for complex system administration tasks. These commands are useful for getting information about your system and

users. This basic information can be utilized for system administration tasks. The man command is used to get help on all HP-UX commands, and you will need to refer to it often.

Where Am I?

In the HP-UX environment, it is always important to know what directory you are in before you move to another directory else. You can use the pwd (print working directory) command at any time to find out the current directory name.

$ pwd



What Is the Current Date and Time?

The date command tells you the current date and time set on the HP-UX system clock.

$ date

Thu Aug 29 15:36:23 EDT 1999


The date command is also used for changing the date and time. This feature of the command is accessible by the superuser only. So if you are logged in as user root, you can set a new date and time, in case the displayed date or time is incorrect. Please note that there is another HP-UX command, time, which is used for another purpose (not for displaying or setting system time).

Who Are Others and Who Am I?

What if you see an unattended terminal to which a user is logged in? You can use the whoami command to identify who is logged in. When you use this command, you are actually asking the system to tell "you" about "yourself."

$ whoami



There are some other interesting uses of this command. For example, if you write a shell program that will do something different depending on which user

executes the program, this little command does a great job of detecting who initiated the program.

There is another useful command that is even shorter than this one. This is the who command, which tells you the login names of all users logged into the system, along with their login time and the terminal line they are using. The output of the who command may vary depending on how many users are logged in.

$ who

operator pts/ta Aug 30 16:05

boota pts/tb Aug 30 15:59


It is interesting that an even shorter command exists in HP-UX, which is w, and it does a similar job. Additionally, the w command tells how long the system has been up, what the current time is, and what the logged-in users are doing.

$ w

4:27pm up 1 day, 12:10, 2 users, load average: 0.07,

0.08, 0.09

User tty login@ idle JCPU PCPU what

operator pts/ta 4:05pm 12 -sh

boota pts/tb 3:59pm w


In HP-UX, some commands are linked to other commands such that the result of these commands is the same. For example, the w command is linked to the uptime -w command and both have the same output. Command linking is done to provide a short name for a frequently used command.

What Is the Name of My System?

Every HP-UX system has a system name. If you are curious to know what the system name is or which version of HP-UX is running on the system, use the uname command.

$ uname -a

HP-UX myhp B.11.00 E 9000/800 71678 8-user license


Here the command output shows that it is an HP-UX system. The system name is myhp and it is running HP-UX version 11.00.

Printing Banners

Banners are very useful for printing welcome messages at login time and for separating printed pages of different users when many users are using a common printer. You can print a fancy design of your name using the banner command.

$ banner BOOTA

###### ####### ####### ####### #

# # # # # # # # #

# # # # # # # # #

###### # # # # # # #

# # # # # # # #######

# # # # # # # # #

###### ####### ####### # # #


The Calendar

A calendar is displayed by cal, which is a short and handy command for printing the calendar of a particular month. In the simplest case, the cal command prints the calendar of the current month, but you can use the command in a number of ways to print the desired calendar.

$ cal

August 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


Getting Help with Manual Pages

UNIX systems provide a very powerful and useful feature that provides detailed help on all of the commands. This tool is called manual pages or man pages. You can use the man command to get help for any UNIX command as follows:

$ man cal

cal(1) cal(1)


cal - print calendar


cal [[month] year]


Cal prints a calendar for the specified year. If a

month is also specified, a calendar for just that

month is printed. If neither is specified, a calen-

dar for the present month is printed. Year can be

between 1 and 9999. Month is a decimal number be-

tween 1 and 12. The calendar produced is a Gregorian



Environment Variables

LANG determines the locale to use for the locale

categories when both LC_ALL and the corresponding en-

vironment variable (beginning with LC_)do not specify

a locale. If LANG is not set or is set to the empty

string, a default of "C" (see lang(5)) is used.

. . .

. . .


How would a user get help on the man command itself? Just as man cal provides help on the cal command, the man man command helps with the man command. We shall describe the manual pages in more detail in Chapter 8.

Executing Multiple Commands on One Line

The shell allows users to enter multiple commands on a single line. In this case, each command is separated by a semicolon. See the result of the command execution as given here.

$ cal;date

August 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

Mon Aug 30 17:57:51 EDT 1999


Options and Arguments

Options and arguments are used to enhance a command feature. Anything typed after the command name is either an option or an argument. A minus (-) symbol precedes any option. Options change command behavior as shown with the history command where you used -3 as an option. Arguments provide additional information to a command. You used the man command with argument

cal, which provided information to the man command to show manual pages for the cal command.

No comments:

Post a Comment