4.3 Browsing, the file system, and re-direction4 Labs4.1 Setup UNIX account4.2 Some Unix commands

4.2 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. (Note: gort has about 1500 different commands avaliable).

  1. Log on to the system.
  2. At the system prompt, (in this document it is shown as username@gort ~ $- even though it may look VERY different), issue the cal command.

    This will show the current month's calendar.

     
    username@gort ~ $ cal
    

    Try the same command with some arguments. For October 1996

    username@gort ~ $ cal 10 1996
    

    Try other dates as well.

    username@gort ~ $ cal 1996
    

    TABER CIS137-- Lab: 4.2
    Name:





    The first "trick" question. Try the command:

     
    username@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.
     
    username@gort ~ $ cal 1752 > temp
    

    To make the file a bit longer let's add year 1753.

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

    username@gort ~ $ cat temp
    

    It should scroll off of the top of the screen. Look at the same file with the more command.

    username@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.

    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.

     
    username@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.

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

     
    username@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:

     
    username@gort ~ $ man man
    

    Also look up the ls command.

    username@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.
     
    username@gort ~ $ who
    

    Also try it with the "am i" options (no dash this time).

     
    username@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:
    username@gort ~ $ ls -iF
    

    Another command of interest: chsh.

  8. For the more daring: run a shell from within a shell. tcsh is an enhansed "C" shell. You will get a prompt ending with ">". 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 bash shell this semester.
     
    username@gort ~ $ tcsh
    
  9. Log off
     
    username@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).

Please turn your lab to Louis Taber or to Pima Community College employee in room A-115 of the Santa Rita Building. Ask them to place it in the dark blue folder in Louis Taber's mailbox.


Instructor: Louis Taber, louis.taber.at.pima at gmail dot com (520) 206-6850
My web site in Cleveland, OH
The Pima Community College web site


4.3 Browsing, the file system, and re-direction4 Labs4.1 Setup UNIX account4.2 Some Unix commands