Commands typed in at a terminal or in a shell script (a batch file) are first interpreted by the shell. The results of the shell processing are used to start executable programs. Executable programs must be marked in the directory as executable, be on the search path, and have the right "magic number" in the first two bytes. Almost all UNIX commands are "external" commands.
This lab is intended to introduce some UNIX commands and shell syntax. The man-machine interface is straightforward character-based. The system issues a prompt, to which the user provides a reply. This reply is in the form of the name of an executable program, arguments and options to be passed to the program, and ended with a carriage return. After the carriage return, the shell "looks" at the text string and tries to interpret the request and execute the program. To separate tokens on the command line use a space (or a tab). Most options are indicated by a preceding hyphen "-". Unlike DOS, you need a space prior to the options. For example, in DOS you can use "cd..", but in UNIX you need "cd ..". (It is hard to see, but there is a space between the "cd" and the "..".) Be careful about uppercase characters. Almost all UNIX commands are in lower case.
Please look at the table for some initial UNIX commands (It is a partial list!).
gort:~>
- even
though it may look VERY different),
issue the cal command. This
will show the current month's calendar.
Try the same command with some arguments. For October 1996gort:~>
cal
Try other dates as well.gort:~>
cal 10 1996
gort:~>
cal 1996
TABER CSC137
Name:
The first "trick" question. Try the command:
What year did you get? (A second hint: The year (a.d.) is on the top line)gort:~>
cal 10
To make the file a bit longer let's add year 1753.gort:~>
cal 1752 > temp
Use the years 1752 and 1753; this will be important later. The ">>" will append the output of the command to the file. Another option, not used here, is ">!" which will overwrite a file.gort:~>
cal 1753 >> temp
This should quickly come back with the system prompt as if nothing happened. Look at the file temp with the cat command. (The UNIX "type" command. It is short for catenate).
It should scroll off of the top of the screen. Look at the same file with the more command.gort:~>
cat temp
At the "gort:~>
more temp
-More-(nn%)
" prompt try a space first.
Re-issue the command. You can use the cursor control keys to
retrieve the last command and edit it in most modern shells.
Back in the more command
try a cr (carriage return). Try a "4
" then a
return and then a space. Try an "h
" for help. A "b
" for
back and a "q
" for quit. What was the first line output after a
"b
" command (be quick - it scrolls off of the screen!)?If your system has a less command, try it. gort has it. The command has several nice features that more is missing. This includes backing up even when the input is a pipe.
How many days did September of 1752 have? This may be a
trick question. This is the year England started using the
Gregorian calendar.
You really should notice some days missing. (If not, look again!)
You may want to look at the date
command too. UNIX systems can deal
with multiple time zones (for different users on the same system),
and leap seconds.
Please note that UNIX systems can be customized quite a bit. Your system administrator may have "enhanced" & and "improved" your interface in a variety of ways! You may be able to use the command dir. The command ls may have some of its options already set for you. To find out (most) of this run thegort:~>
ls
command. This will give you a list of "command translations" that are taking place. If you find an alias for ls that you would like to have "go away" so you can see the "normal" operation you can remove the alias with:alias
You should at least see your file temp. Try it with a -a option.unalias ls
This will show your hidden files -- the ones placed in your account when it was set up. Try the long format, the -l option. Also try both the "l" and the "a" option at the same time ( -al ).gort:~>
ls -a
This displays quite a bit of information about the file. It includes the protection bits, owner, the group (on some systems this will be missing), length in bytes, time of modification, and the file name. What is the length of the file temp in bytes? This is the number just prior to the date.gort:~>
ls -al
man
command. (Most systems might call it help.) It
accesses
the manual pages, which are cryptic. Look up
the manual pages for the man command:
Also look up the ls command.gort:~>
man man
What does the -R option do? (Note that the "R" is upper case.)gort:~>
man ls
What does the -r option do? (Note that the "r" is lower case.)
Also try it with the "gort:~>
who
am i
" options (no dash this time).
Also try thegort:~>
who am i
finger
and w
commands.
man
pages:
id
, date
, pwd
, wc
, and tty
.
Please look at the manual pages! Try some of the other
options available on the commands, such as:
Two other commands of interest are chfg and chsh.gort:~>
ls -iF
chfg
is disabled on some systems.
exit
to get
back to the original shell. The ^D
is the systems End-Of-File (EOF) character. Some shells disable the use
of ^D to exit the session.
You can also try the c-shell. Its name is csh.
We will mostly use the tcsh shell this semester.
gort:~>
sh
This will keep someone else from using your account and free up system resources.gort:~>
exit