UMBC CMSC104

Unix Lab Exercise

Objectives

-To practice using the basic UNIX/Linux commands

Note: There is nothing that you must turn in associated with this exercise. If you do not finish the exercise during the lab session, it is to your benefit to finish it later on your own.

The Assignment

Commands you will use: pwd, ls, mkdir, cd, cat, more, less, rm, rmdir, mv

Follow the steps below in order. Notice that you are not always given the full command to use. As you move through the exercise, you are given fewer and fewer commands. It's time to think! Use your class notes as a reference.

Creating a Directory Hierarchy (Tree) To Use During the Semester

  1. Log into your gl account.

  2. Look at the name of your home directory.

    linux1[110]% pwd
    /afs/umbc.edu/users/d/b/dblock/home   
    linux1[111]%    
    
    

  3. Look at the contents of your home directory. It might contain the following (and possibly more) subdirectories:

    linux1[111]% ls
    Mail  bin  www  mybio.txt
    linux1[112]%
    
    

  4. Look at the "long" contents of your home directory. You should see the same subdirectories, but with more information about each.


    linux1[112]% ls -l
    total 6
    drwx------    2 dblock   rpc          2048 Sep 19 09:04 Mail
    drwx------    2 dblock   rpc          2048 Sep 19 09:04 bin
    drwx------    2 dblock   rpc          2048 Sep 19 09:04 www
    drwx------    2 dblock   rpc          1024 Sep 19 09:04 mybio.txt
    linux1[113]%
    
    

  5. Look at the "hidden files in your directory. If you can't remember how to do so, use the man pages. Look for the option that will show all files including those that are hidden. To exit out of the man page, you should type 'q' for quit.

    linux1[120]% man ls
    linux1[121]% 
    
    

  6. Create a subdirectory called CS104. Verify that it has been created by again looking at the contents of your home directory.

    linux1[121]% mkdir CS104
    linux1[122]% ls
    CS104  Mail  bin  www
    linux1[123]%
    
    

  7. Move to the CS104 directory. Verify that your current directory is now indeed CS104 (Remember that linux is case sensitive...so CS104 is different from cs104.)

    linux1[123]% cd CS104
    linux1[124]%
    
    

  8. Create six new subdirectories, one for each of the assignments that you will be doing in this class. Call them Hw1, Hw3, Proj1, Proj2, Proj3 and Proj4. There is no directory for the second homework because you will turn it in on paper. Verify that each of the subdirectories has been created.

  9. Move your mybio.txt file from your home directory into the Hw1 directory. Check to see that it is no longer in your home directory. Then, check to see that it is in the Hw1 directory.

    linux1[133]% mv ../mybio.txt Hw1
    linux1[134]% ls ..
    CS104  Mail  bin  www
    linux1[135]% ls Hw1
    mybio.txt
    linux1[136]%
    
    

  10. Move back to your home directory. Is there more than one way to get there? If so, try using a way that you have never used before. Verify that your current directory is indeed your home directory (use pwd).

More Practice with Directory and File Commands

  1. Make sure you are in your home directory. If you are not, you should move there.

  2. Create a new directory named MyFiles. Verify that the directory exists.

  3. Move to the MyFiles directory. Verify that you are there.

  4. Use the xemacs editor to create a file called sam.txt.

    linux1[138]% xemacs sam.txt
    linux1[139]%
    
    
    Once you have opened the file, you should type the following:

    I am Sam. Sam I am.
    Do you like green eggs and ham?

    Save the file and exit xemacs.

  5. Look at the contents of the current directory. It should contain just the sam.txt file.

  6. Display the contents of sam.txt on the monitor (cat sam.txt OR more sam.txt OR less sam.txt). To exit out of less, you should type 'q'.

  7. Move back to your home directory. Verify that you are there.

  8. List the contents of the MyFiles directory. It should contain only the file sam.txt.

  9. Create another subdirectory called MoreFiles. Verify that it exists.

  10. Try to delete the MyFiles subdirectory. You will get a message that the directory is not empty. You must delete all files and subdirectories from a directory before deleting the directory itself. So,

  11. Move sam.txt from the MoreFiles directory to your current (home) directory.

    linux1[156]% mv MoreFiles/sam.txt .
    linux1[157]% ls
    CS104  Mail  MoreFiles  bin  sam.txt  www
    linux1[158]% 
    
    

Be sure to logout completely when you have finished!


Last Modified: Wednesday, 13-Sep-2006 15:58:30 EDT
Last Modified: Wednesday, 13-Sep-2006 15:58:30 EDT