Unix Fundamentals Chapter 02
Unix Fundamentals Chapter 02
______________________________________________________________________________
Chapter Two
Foundation
In This Chapter
Command Structure
Basic Command Examples
Some Simple Commands
Getting Help with Man Pages
Changing Your Password
The PATH Variable
Logging Your Session
Exercises
40 UNIX Fundamentals Workshop
______________________________________________________________________________
UNIX Fundamentals Workshop 41
______________________________________________________________________________
In This Chapter
Command Action
man -k keyword search the online manuals‘ index for information related to
the given keyword
script <filename> save the output of your shell session to a file – end with
Ctrl-d
Command Structure
UNIX commands are entered at a shell prompt. Commands can invoke applications, scripts, filters,
and utilities. The syntax for UNIX commands is
where options are optional command parameters, and name is the file, directory, or text string to per-
form the action upon. Together, the options along with any files or directories passed to the com-
mand become the command‘s arguments. The command plus its arguments are referred to as the
command line.
Syntax
Description Example
Command Action
mailx userid@wnt Send email from command prompt (end with Ctrl-d)
man –k <string> Search online manual index for commands related to string
uname -a Display information about your system (OS version & level)
whereis <command> Follows the $PATH variable and displays all occurrences of
command found.
Note: To quit or exit any of the above applications, try one of these commands, keystrokes, or menu
selections: ctrl + c, ctrl + d, or exit.
UNIX Fundamentals Workshop 45
______________________________________________________________________________
Simple Commands
The date command displays the current date and time. The command has several formatting op-tions
listed in the man pages. The command is useful when executed in conjunction with other commands,
to output the date and time of execution. It is frequently used in the generation of log files created
with shell scripts.
Display date...
Alert: Sometimes, the date or time displayed is incorrect!!! If it is wrong, contact your system ad-
ministrator and have them reset it (otherwise, things like caching can get confused).
46 UNIX Fundamentals Workshop
______________________________________________________________________________
Echoing Text
The echo command echoes the entered characters or associated shell variable contents. The com-
mand also has several escape char-acters, such \n to force a carriage return. The command is useful
when executed in conjunction with a series of other commands, within a shell script, to generate out-
put.
Echo text...
Echo the output of the date command with helpful text (note the
quotes around the date command – they are called backticks).
Delaying a Command
The sleep command delays execution of one or more commands. The sleep command is useful for
testing output devices, such as delaying a printer job until a user can reach the printer room. The de-
fault format of the command‘s argument is in seconds.
The man command generates both a short synopsis of the command's arguments and a short descrip-
tion of the command's functions. In addition, many man pages include details examples of using the
command.
The command man -k keyword displays a list of all matching commands related to the given key-
word.
Section Description
Example
DATEBOOK(1) DATEBOOK(1)
NAME
datebook - calendar and reminder program for X11
SYNOPSIS
datebook [-W] [-V] [-D date] [-F datefile]
DESCRIPTION
Datebook is a personal appointment calendar. It was written to solve
the never ending problem of forgetting when you need to attend a
meeting, go to the doctor, or phone home. Datebook provides calendar
features, that let you enter and review events for a particular day or
week, as well as reminder features that notify you before particular
events.
:
Each activity or appointment entered into Datebook is considered an
event. Events that are specified with a time will generate alarms.
In the X11 environment, an alarm will cause an alarm window to appear
on the user's screen. This window will present the user with the
option to acknowledge, delay (snooze) or delete the event in question.
Outside of X11 the user can have datebook call a program or script
when the alarm occurs (see AlarmNotify).
Events can be classified into various event classes. Each class can
have a different amount of time that the user will be warned in
advance of the event. For example, for local meetings you might want 5
minutes warning, but if the meeting is offsite 30 minutes warning
would be more appropriate. The class can also specify the time to
"snooze" before repeating an alarm. The class can also be used to
specify a bitmap to be displayed in the alarm window.
OPTIONS
-W List the events for the next week to stdout. This option will
not bring up X windows and will therefore work outside of X.
-D date This option is like the list week option, but it only lists
the events for a particular date. This date should be in a
simple date (month, day and year) like 12/14/89 or November
28. If used in combination with -W the week starting at date
will be listed.
-F datefile
This option allows the user to start with one or more (one -F
option per file) date files instead of the date files
specified by the ~/.datebookrc file.
Some man pages have multiple sections, referenced as command(n) in the See Also section.
Section Description
(3) Subroutines
(5) Miscellaneous
(6) Games
(7) Devices
The command man n command displays section n of the man page for command.
man(5) man(5)
NAME
man - macros for formatting entries in this manual
DESCRIPTION
These macros are used by nroff (and are usable by troff) to determine
the layout format of the on-line version of entries found in this and
other related reference manuals. These macros are used by the man
command (see man(1)).
The default page size is 8.5x11 inches, with a 6.5x10-inch text area.
The -rs1 option (which is ignored by nroff) reduces these dimensions
to 6x9 inches and 4.75x8.375 inches, respectively - and reduces the
default type size from 10-point to 9-point; the vertical line spacing
from 12 points to 10 points. The -rV2 option can be used to set
certain parameters to values appropriate for certain Versatec
printers: line length to 82 characters; page length to 84 lines;
underlining inhibited. This option should not be confused with the
-Tvp option of the man command, which is available on some UNIX
operating systems.
Any text argument below can consist of one to six ``words''. Double
quotes ( can be used to include blanks in a ``word''. If text is
empty, the special treatment is applied to the next line containing
text to be printed. For example, .I can be used to italicize a whole
line, or .SM followed by .B to make small bold text.
Type font and size are reset to default values before each paragraph
and after processing font- and size-setting macros such as .I, .RB,
and .SM. Tab stops are neither used nor set by any macro except .DT
and .TH. .TH invokes .DT (see below).
Use the passwd command to change your userid‘s password. If all goes well, the passwd
utility will update the user‘s password encryption in the /etc/shadow file (/etc/passwd
on some of the older systems). The /etc/passwd and /etc/shadow files are used to au-
thenticate you every time you log in.
Note: You can only change your own userid‘s password. A privileged user, such as root, can
change any user‘s password.
prompt>passwd Enter
passwd: Changing passwd for sssims
Enter login password: *********
New password: ********
Re-enter new password: ********
Passwd (SYSTEM): passwd successfully changed for sssims
prompt>
54 UNIX Fundamentals Workshop
______________________________________________________________________________
How does the shell know whether you have access to a command when you execute it? The shell
maintains an internal variable, called PATH, it its own environment. As such, you will commonly
hear such variables referenced as ―environment variables‖. The PATH variable is typically set to a
colon delimited list of directories. If you attempt to run a utility or command, and receive a message
such as ―command: not found‖, you can bet that the directory you need is not included in your PATH
variable.
Display current setting for PATH (note the need to preface the
variable with the dollar sign ($)).
In the above output, there are five directories listed. The last one
is signified by a „.‟ (referred to as “dot”). It signifies that your
current working directory is the last place the shell will look for a
command.
You can still execute a command that is not contained within a directory located in your PATH varia-
ble using one of these three methods:
Use an absolute path to the command you wish to run, such as /usr/local/bin/sas
Change your current working directory to the location where the command resides. By ex-
ecuting it there, your PATH will pick it up because it will be in your current directory (the ―.‖
at the end of the PATH)
Note: For Windows users who are familiar with the PATH variable on that system – make
sure you note that UNIX uses a colon as the directory delimiter in the PATH variable, whe-
reas Windows uses a semicolon.
UNIX Fundamentals Workshop 55
______________________________________________________________________________
Note: script will overwrite any information previously recorded to the file you specify.
The shell prompt returns, and all input and output of your login
session will be recorded in the script file noted. When you are
ready to stop recording your session in the script file, enter the exit
command (or Control-D):
prompt>exit Enter
Script done, file is mysession.out
You can now view this file with the cat command
Exercises
1. Which environment variable determines the search path for any program you run?
2. Start a script file – named myscript.out – located in your home directory. Your
prompt will return. With your script still running, do the following:
3. Terminate your script file and view its contents using cat.
58 UNIX Fundamentals Workshop
______________________________________________________________________________