CMSC104 Spring 2014 Unix Lab Exercise

Objectives

Resources:

The Assignment

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

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.

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.

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

  1. Log into your gl account (we'll go over this).

  2. Look at the name of your home directory.

    linux1[2]% pwd
    /afs/umbc.edu/users/d/b/dblock/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  mybio.txt
    linux1[5]%
    
    

  4. Look at the "long" contents of your home directory. You should see the same subdirectories as you saw with ls, but with more information about each. Note that it is -l (the letter l, not the number 1).

    linux1[6]% ls -l
    total 6
    drwx------    2 dblock   rpc          2048 Sep 19 09:04 Mail
    drwx------    2 dblock   rpc          2048 Sep 19 09:04 bin
    lrwx------    2 dblock   rpc          2048 Sep 19 09:04 www -> ../pub/www
    -rw-------    2 dblock   rpc          1024 Sep 19 09:04 mybio.txt
    linux1[7]%
    
    

  5. Look at the "hidden files in your directory. If you can't remember how to do so, use the man pages (man ls). Look for the option that will show "all" files including those that are hidden (files starting with a period). To exit out of the man page, you should type 'q' for quit.
  6. Now, in the next few steps, you are going to create directories for some of your homework and projects. The directories will be created in your Desktop directory. Make sure you are in your home directory before you start.
  7. Change into the Desktop directory.
  8. linux1[19]% pwd
    /afs/umbc.edu/users/d/b/dblock/home/   
    linux1[20]% cd Desktop
    linux1[21]% pwd
    /afs/umbc.edu/users/d/b/dblock/home/Desktop
    linux1[22]% 
    
    

  9. Create a subdirectory called cs104. Verify that it exists.
  10. linux1[29]% mkdir cs104
    linux1[30]% ls
    cs104
    linux1[31]%
    
    

  11. Change into the cs104 directory. (Make sure you are there!) Create subdirectories called hw1, hw2, hw3, hw4, proj1, proj2, and proj3. (Shortcut: Remember the up arrow will repeat the last command. This might be helpful when creating the subdirectories.) When you have finished verify that the subdirectories exist.

Practice with the emacs Text Editor

You will be using the emacs text editor to create a file called mybio.txt.

  1. Change into the hw1 directory and start emacs.
  2. linux1[39]% cd hw1
    linux1[40]% emacs mybio.txt
    
    

  3. Now you can type in your bio. It must contain the following information:
    1. Your name, major, and class standing (e.g., sophomore).
    2. A paragraph or two telling me a little bit about yourself,
      • Where you are from and why you chose UMBC for your education?
      • Why did you chose your major?
      • What is the best course (college or otherwise) you have had so far and why?
      • What is your favorite color?
      Do not leave out any of this information!
  4. Edit any mistakes using the Backspace or Delete key to backspace and the Ctrl-d (where Ctrl is the Control key) sequence to delete a character. When you get to the end of a line, hit the enter key at a reasonable spot instead of the letting the text wrap around to the next line. Remember that emacs is simply a text editor and does not format things nicely for us.
  5. Save your work as you go by pressing Ctrl-x and then Ctrl-s.
  6. To exit emacs press Ctrl-x and then Ctrl-c. If you have made changes since you last saved, it will ask you if you want to save the file; press 'y' for yes.
  7. You will know that you have exited emacs and are again talking to the Linux system if you see the linux1[#]% or linux2[#]% or linux3[#]% prompt.
  8. Check that the file mybio.txt is in your directory: ls
  9. linux1[58]% ls
    mybio.txt
    
    

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 emacs editor to create a file called things2do.txt.

    linux1[32]% emacs things2do.txt
    linux1[33]%
    
    
    Once you have opened the file, you should type the following:

    1. Finish today's lab exercise.
    2. Eat dinner.

    Save the file and exit emacs.

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

  6. Display the contents of things2do.txt on the monitor (cat things2do.txt OR more things2do.txt OR less things2do.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 Personal directory (ls Personal). It should contain only the file things2do.txt.

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

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

    If you do not complete the lab today and would like to finish later, you can continue to work on it from home.

Be sure to logout completely when you have finished!