CMSC104 Section 0201 & 0401 (2025)

CMSC104 Section 0201 & 0401 (1)

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: script, pwd, ls, mkdir, cd, cat, more, less, rm, rmdir, mv

Follow the steps below in order. Notice that you are not always given thefull 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. Before typing anything else, type the command script. The script commandlogs everything you type so you can go back and review it later. It will create a file called typescript that contains all of the commands you type until you exit the script.
    linux1[108]% scriptScript started, file is typescriptlinux1[1]%
  3. Look at the name of your home directory.
    linux1[2]% pwd/afs/umbc.edu/users/d/b/dblock/home linux1[3]% 
  4. Look at the contents of your home directory. It might contain the following (and possibly more or less) files and subdirectories:
    linux1[4]% lsMail bin www mybio.txtlinux1[5]%
  5. Look at the "long" contents of your home directory. You should see the same subdirectories, but with more information about each.
    linux1[6]% ls -ltotal 6drwx------ 2 dblock rpc 2048 Sep 19 09:04 Maildrwx------ 2 dblock rpc 2048 Sep 19 09:04 bindrwx------ 2 dblock rpc 2048 Sep 19 09:04 wwwdrwx------ 2 dblock rpc 1024 Sep 19 09:04 mybio.txtlinux1[7]%
  6. 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.
  7. Create a subdirectory called cs104. Verify that it has been created by again looking at the contents of your home directory.
    linux1[8]% mkdir cs104linux1[9]% lscs104 Mail bin www mybio.txtlinux1[10]% 
  8. Move to the cs104 directory. Verify that your current directoryis now indeed cs104 (Remember that linux is case sensitive...so cs104is different from CS104.)
    linux1[11]% cd cs104linux1[12]% pwd/afs/umbc.edu/users/d/b/dblock/home/cs104linux1[13]% 
  9. Create a subdirectory for hw1. Verify that it exists.
  10. 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. You should be in the cs104 directory when you issue these commands.
    linux1[14]% pwd/afs/umbc.edu/users/d/b/dblock/home/cs104 linux1[15]% mv ../mybio.txt hw1linux1[16]% ls ..cs104 Mail bin wwwlinux1[17]% ls hw1mybio.txtlinux1[18]%
  11. Move back to your home directory. Is there more thanone 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).
  12. Now, you are going to create directories for hw3, proj1, proj2, proj3 and proj4. There is no directory for hw2 because you will turn that in on paper. You already created a directory for hw1 in step 8. The remaining directories will be createdin your www directory, where your JavaScript projects mustbe stored in order to be seen on the Web. You must create these directories with the exact names I give you, including spelling and upper or lowercase. You need to go up to the parent directory of your home directory.
  13. linux1[19]% pwd/afs/umbc.edu/users/d/b/dblock/home/ linux1[20]% cd ..linux1[21]% lsMail backup home publinux1[22]% 

  14. Now, change into the pub directory. Look at the contents of the directory.
  15. linux1[23]% pwd/afs/umbc.edu/users/d/b/dblock/linux1[24]% lsMail backup home publinux1[25]% cd publinux1[26]% lswwwlinux1[27]%
  16. Change into the www directory. Then, create a subdirectory called cs104. Verify that is exists.
  17. linux1[28]% cd wwwlinux1[29]% mkdir cs104linux1[30]% lscs104linux1[31]%
  18. Change into the cs104 directory. Create subdirectories for hw3, proj1, proj2, proj3and proj4. (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.

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. Verifythat the directory exists.
  3. Move to the Personal directory. Verifythat you are there.
  4. Use the xemacs editor to create a file called things2do.txt.
    linux1[32]% xemacs things2do.txtlinux1[33]%
    Once you have opened the file, you should type the following:

    1. Finish today's lab exercise.
    2. Finish homework 1.
    3. Buy Ms. Block's birthday present. :)

    Save the file and exit xemacs. In case you forgot how to save, it's ctrl-x ctrl-c and then press 'y' for yes.

  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 shouldtype 'q'.
  7. Move back to your home directory. Verify that you are there.
  8. List the contents of the Personal directory (ls Personal). Itshould 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. linux1[34]% pwd/afs/umbc.edu/users/d/b/dblock/home/ linux1[35]% mkdir PersonalBackuplinux1[36]% ls cs104 Mail bin www Personal PersonalBackuplinux1[37]%
    • Copy the file things2do.txt from Personal to PersonalBackup.
      linux1[38]% cp Personal/things2do.txt PersonalBackuplinux1[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 emptylinux1[41]% rm Personal/things2do.txtrm: remove regular file `Personal/things2do.txt'? ylinux1[42]% ls Personal/linux1[43]% rmdir Personallinux1[44]% lscs104 Mail PersonalBackup bin wwwlinux1[45]%
  12. Move things2do.txt from the PersonalBackup directory to your current (home) directory.
    linux1[46]% mv PersonalBackup/things2do.txt .linux1[47]% lscs104 Mail PersonalBackup bin things2do.txt wwwlinux1[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. When you are finished, type the command exit. This will complete the script. All of thecommands you entered will be recorded in the file typescript. If you would like to go backand review the commmands, just type more typescript or less typescript.
    linux1[49]% exitexitScript done, file is typescriptlinux1[2]% 

    If you do not complete the lab today and would like to finish later, you can continue to work on it from home. Before you begin, type the command script -a. The -a flag to the script command will cause it to append your new commands to the end of the original typescript file you created during this lab.

Be sure to logout completely when you have finished!

Last Modified:
CMSC104 Section 0201 & 0401 (2025)
Top Articles
Latest Posts
Recommended Articles
Article information

Author: Gov. Deandrea McKenzie

Last Updated:

Views: 5597

Rating: 4.6 / 5 (66 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Gov. Deandrea McKenzie

Birthday: 2001-01-17

Address: Suite 769 2454 Marsha Coves, Debbieton, MS 95002

Phone: +813077629322

Job: Real-Estate Executive

Hobby: Archery, Metal detecting, Kitesurfing, Genealogy, Kitesurfing, Calligraphy, Roller skating

Introduction: My name is Gov. Deandrea McKenzie, I am a spotless, clean, glamorous, sparkling, adventurous, nice, brainy person who loves writing and wants to share my knowledge and understanding with you.