4.4 Editor 1 - About Me4 Labs4.2 X Window system4.3 Some UNIX commands

4.3 Some UNIX commands

The purpose of this lab is to get some familiarity with the UNIX user interface. Please take some time with this and explore. What you learn in this lab will probably help you the entire semester, if not longer.

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!).

  1. Log on to the system.
  2. At the system prompt, (in this document it is shown as gort:~> - even though it may look VERY different), issue the cal command. This will show the current month's calendar.
     
    gort:~>  cal
    
    Try the same command with some arguments. For October 1996
    gort:~>  cal 10 1996
    
    Try other dates as well.
    gort:~>  cal 1996
    

    TABER CIS137
    Name:





    The first "trick" question. Try the command:

     
    gort:~>  cal 10
    
    What year did you get? (A second hint: The year is on the top line.) cal only handles a.d. years.




  3. Create a file using redirection. Unix lets you direct the output of a program to a file with the ">" symbol. Do this.
     
    gort:~>  cal 1752 > temp
    
    To make the file a bit longer let's add year 1753.
     
    gort:~>  cal 1753 >> 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.

    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).

    gort:~>  cat temp
    
    It should scroll off of the top of the screen. Look at the same file with the more command.
    gort:~>  more temp
    
    At the "-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.

  4. The UNIX ls command is every other system's dir command. Try it.
     
    gort:~>  ls
    
    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 the
    alias 
    
    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:
    unalias ls
    
    You should at least see your file temp. Try it with a -a option.
     
    gort:~>  ls -a
    
    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 -al
    
    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.




  5. Try the 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:
     
    gort:~>  man man
    
    Also look up the ls command.
    gort:~>  man ls
    
    What does the -R option do? (Note that the "R" is upper case.)




    What does the -r option do? (Note that the "r" is lower case.)





  6. Try the who command.
     
    gort:~>  who
    
    Also try it with the "am i" options (no dash this time).
     
    gort:~>  who am i
    
    Also try the finger and w commands.
  7. Other commands to look up in the text book and the 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:
    gort:~>  ls -iF
    
    Two other commands of interest are chfg and chsh. chfg is disabled on some systems.
  8. For the more daring: run a shell from within a shell. sh is the Bourne shell. Is is often used for system-level shell programming. You will get a prompt of "$". You will need to do a ^D or an 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
    
  9. Log off
     
    gort:~>  exit
    
    This will keep someone else from using your account and free up system resources.
Turn in the pages with your answers (or a copy). Place the lab in the instructor hand-in box in BUS R6E, the "terminal room".
Instructor: ltaber@pima.edu ** My new Home at GeoApps in Tucson ** The Pima College Site ** The Mad Dr. G.'s home page on phred.

4.4 Editor 1 - About Me4 Labs4.2 X Window system4.3 Some UNIX commands