Classwork 2: Unix Lab Exercise

Objectives

To practice using the basic UNIX/Linux commands

Note: at the end of the lab, you will use submit to turn in a transcript of your Linux session. If you do not finish all the steps, just submit as much as you get done.

The Assignment

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

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[2]% pwd
    /afs/umbc.edu/users/p/a/park/home   
    linux1[3]%    
    
    

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

    linux1[4]% ls
    Mail  bin  www  joke 
    linux1[5]%
    
    

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

    linux1[6]% ls -l
    total 6
    drwx------    2 park rpc  2048 Sep 15 09:04 Mail
    drwx------    2 park rpc  2048 Sep 15 09:04 bin
    -rwx------    1 park rpc  1024 Sep 15 09:04 joke
    lrwxr-xr-x    1 park rpc  2048 Sep 15 09:04 www -> ../pub/www
    linux1[7]%
    
    

  5. Look at the "hidden files in your directory using ls -a.

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

    linux1[8]% mkdir cs104
    linux1[9]% ls
    cs104  Mail  bin  www  joke 
    linux1[10]% 
    
    

  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[11]% cd cs104
    linux1[12]% pwd
    /afs/umbc.edu/users/p/a/park/home/cs104
    linux1[13]%    
    
    

  8. Create 3 new subdirectories, for the first 3 homework assignments that you will be doing in this class. Call them hw01, hw02 and hw03. Verify that each of the subdirectories has been created.

  9. Move the joke/motto file you created in Classwork 01 from your home directory into the hw01 directory. (If you did not complete Classwork 01, do it now and submit it.) Check to see that it is no longer in your home directory. Then, check to see that it is in the hw01 directory. You should be in the cs104 directory when you issue these commands.

    linux1[14]% pwd
    /afs/umbc.edu/users/p/a/park/home/cs104   
    linux1[15]% mv ../joke hw01
    linux1[16]% ls ..
    cs104  Mail  bin  www
    linux1[17]% ls hw01
    joke
    linux1[18]%
    
    

  10. Change directory to the hw01 directory. Use nano joke to edit your joke/motto file and add the following joke:

    Why do ducks have webbed feet?
    To stamp out fires.
    
    Why do elephants have flat feet?
    To stamp out flaming ducks!
    

  11. Submit your new joke/motto file:

    submit cs104_chang cw02 filename
    

  12. 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. Move to your home directory. Make sure you are there (pwd).

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

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

  4. Use the nano editor to create a file called things2do.txt.

    linux1[32]% nano things2do.txt
    
    

    Once you have opened the file, you should type the following:

    
    1. Finish today's lab exercise.
    2. Finish homework 1.
    3. Bring my pet tarantula to CMSC104 for Show'n'Tell
    
    

    Save the file and exit nano (use Ctrl-X).

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

  6. Start a transcript of your Unix session with

    linux1[33]% script
    Script started, file is typescript
    

    It's very important that you don't skip this step!!!

  7. List the contents of the Personal directory (ls Personal). It should contain only the file things2do.txt.

  8. Display the contents of things2do.txt on the monitor (cat Personal/things2do.txt OR more Personal/things2do.txt OR less Personal/things2do.txt). To exit out of less, you should type 'q'.

  9. Make sure you are in your home directory! Create another subdirectory called PersonalBackup in your home directory. Verify that it exists. Both Personal and PersonalBackup should be in your home directory.

  10. linux1[34]% pwd
    /afs/umbc.edu/users/p/a/park/home/   
    linux1[35]% mkdir PersonalBackup
    linux1[36]% ls 
    cs104  Mail  bin  www  Personal  PersonalBackup
    linux1[37]%
    
    

    Copy the file things2do.txt from Personal to PersonalBackup.

    linux1[38]% cp Personal/things2do.txt PersonalBackup
    linux1[39]%
    

    Look at the contents of the PersonalBackup subdirectory. It should now contain the file things2do.txt.

  11. Try to delete the Personal 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,

    • Delete things2do.txt from Personal.
    • Look at the contents of Personal to make sure that it is empty.
    • Delete the Personal subdirectory.
    • Look at the contents of your current (home) directory to make sure that Personal has been deleted.

      linux1[40]% rmdir Personal/
      rmdir: `Personal/': Directory not empty
      linux1[41]% rm Personal/things2do.txt
      rm: remove regular file `Personal/things2do.txt'? y
      linux1[42]% ls Personal/
      linux1[43]% rmdir Personal
      linux1[44]% ls
      cs104  Mail  PersonalBackup  bin  www
      linux1[45]%
      
      

  12. Move things2do.txt from the PersonalBackup directory to your current (home) directory.

    linux1[46]% mv PersonalBackup/things2do.txt .
    linux1[47]% ls
    cs104  Mail  PersonalBackup  bin  things2do.txt  www
    linux1[48]% 
    
    

    • Look at the contents of your home directory to be sure that things2do.txt is there.
    • Look at the contents of PersonalBackup to be sure that things2do.txt is no longer there.
    • Delete the PersonalBackup subdirectory.
    • Delete things2do.txt.

  13. Now you have to stop recording the transcript of your Unix session:

    linux1[49]% exit
    exit
    Script done, file is typescript
    

    • Check that you have a file named typescript.
    • Check that the file is not empty using cat.
    Submit your typescript file:

    linux1[49]% submit cs104_chang cw02 typescript
    


Be sure to logout completely when you have finished!