UMBC CMSC 121 CSEE

CMSC 121, Section 0201 - Fall 2005
Introduction to UNIX

Homework Assignments


Homework 1 - Due Monday, 9/26/2005

Topics: UNIX, Linux, and the UMBC Computing Environment. The goal of this assignment is to get you to become familiar with Linux, Gnome, KDE, and the UMBC UNIX Environment.

Homework 2 - Due Friday 9/30/2005

This assignment was taken from Dan Hood's CMSC 121 website.

In order for the whole assignment to be logged to a file, you will need to sit down and complete the whole thing from beginning to end without logging out. If you make mistakes or typos as you go, do not worry about it. Fix and re-issue the command.

I strongly recommend that you figure out what command and what arguments you are going to be typing for each step before you actually issue the command. This way you can test out the command before you actually sit down and log the entire assignment.

  1. Connect via SSH to linux.gl.umbc.edu. You will be doing this assignment via a SSH connection to one of the Linux servers. You may use the SSH client of your choice.
     
  2. Make sure that you are in you home directory before you proceed further into the assignment.
     
  3. First type script at the command prompt. This will allow for the entire interaction that you have with the UNIX environment to be logged to a file called "typescript". You should see the message "Script started, file is typescript".
     
  4. Verify that you are in your home directory. Meaning issue the command that prints out the current working directory.
     
  5. Make a directory called "courses". If for whatever reason this directory already exists (you already created it as part of organizing your account) then simply skip this step.
     
  6. Change the current working directory to this newly created directory called "courses".
     
  7. Again issue the command to verify that the current working directory is now in this "courses" directory.
     
  8. From within this directory make 2 different directories called "cmsc121" and "temp".
     
  9. Now do a normal listing of this directory. You should note the 2 new directories now show up in this listing.
     
  10. Now let's create an empty file called "file0".
     
  11. Now do a long directory listing.
     
  12. Copy "file0" into the directory "cmsc121"
     
  13. Let's copy some more files. This time we will get them out of my public directory. Copy the "file1" from /afs/umbc.edu/users/e/e/eeaton1/pub/cmsc121/hw2/ into the directory called "cmsc121"
     
  14. Now copy all 3 of these files out of my public directory. Copy "file1", "file2" and "file3" all into the directory called "temp".
     
  15. Now do a directory listing of each of the 2 directories "cmsc121" and "temp"
     
  16. Move "file0" (the one that is in this current directory) into the "temp" directory.
     
  17. Copy "file3" (which is in the "temp" directory) into the "cmsc121" directory
     
  18. Change directories into the "temp" directory
     .
  19. Show the contents of both of "file2" and "file3" using the command of your choice.
     
  20. There is 1 slight difference between these 2 files. Use the UNIX command that will show the differences between these 2 files to show us what it is.
     
  21. Change the directories to the parent of the current directory. You can do this using one of the special arguments that I showed you for the change directory command or you can type in the full absolute pathname. So once this command is done you should be in the "courses" directory.
     
  22. Now let's issue the command to remove a directory. Let's try to remove the this "temp". Issue the command to remove a directory and note what happens. We get yelled at because the directory is not empty.
     
  23. So let's fix this. Remove all files that are in the "temp" using the commands of your choice. If you changed directories to accomplish this, return back to the "courses" directory.
     
  24. Now you should be able to remove the "temp" directory. Try again to issue the command that will remove this directory. Since the directory is empty it should work.
     
  25. Go ahead and do a directory listing to verify that the directory has been removed.
     
  26. Now change directories into the remaining "cmsc121" directory.
     
  27. There should be 3 files in this directory. Verify that by doing a directory them. Issuse the command to get the total number of words, characters and bytes for the file called "file3". You should see that the total number of bytes matches what the long directory listing showed.
     
  28. Now using a wildcard, issue a command that will get the total number of words, characters and bytes for all files in this directory. Notice now that this command has also returned us grand totals for all of the files combined.
     
  29. Let's go ahead and remove all 3 of the files that are in this current working directory (which is "cmsc121").
     
  30. This directory should now be empty. Verify that using by listing the contents of the directory.
     
  31. Change directories back to your home directory. You could do this using the ..characters, but instead show me another way to change back to your home directory. Do not use an absolute path either (/afs/umbc.edu/users/u/s/username/home/). Part of the goal of this course is to get you to work more efficiently. There are many shortcuts to achieve the same effect.
     
  32. Issue the directory listing command in such a way that you see some of the hidden files and directories that exist in your home directory.
     
  33. Now issue the command that will print out the current date and time
     
  34. Issue the command that will print a list out of all the users that are logged onto the computer that you are.
     
  35. Type exit at the command prompt. This will close the session that logged all of your activity to a file. You should see something like "Script done, file is typescript".
     
  36. Now that all of the assignment has been logged to the file called "typescript", I want you to make sure that it logged everything correctly. Use one of the commands that we discussed to see the contents of the file.
     

Finally you will hand in the typescript file that you created. You will not email me this project, instead we will use UMBC's submit command. You will issue the following command to submit the typescript file: "submit cs121_0201 hw2 typescript". You can then issue the submitls command "submitls cs121_0201 hw2" to see what you submitted. If you messed up and would like to re-submit you can simply issue the submit command again, and the file that you previously submitted will be overwritten.

Note that you will not be able to issue the "submit" command until Monday Sept 26, after we go over the command in class and make certain it is working for everyone.


Homework 3 - Due Wednesday, 10/05/2005

You will hand these answers into me in typed hard copy. Do not forget to include a statement of the sources you used in this assignment, even if you did not use any sources.

Let me be clear that for any questions where I am asking you for a UNIX command, I am not asking you to run these commands under UNIX and log them with the script command. I merely want you to tell me what command you would use to perform each of the actions listed below.

Note that you can test out your commands on the command line before submitting them as answers in this homework. For each question asking for a UNIX command, give a one-line answer. That is, if your solution requires multiple commands, separate them by semicolons.

  1. Give the command to open a file named temp.txt in emacs, and set emacs to run in the background.
     
  2. Give the command to repeat the 6th command in your tcsh shell's history.
     
  3. Give the command to list all locations in your PATH variable where the more command may be found.
     
  4. Give the command to display the instance of the emacs command that is executed when you type in the emacs command.
     
  5. Give the command to find instances of the string "Answer" in the file ./homework.shtml along with the line numbers at which these instances occur. Also, ignore case, meaning that your command should find instances of "answer" as well as "Answer".
     
  6. Give the command to find the location of all files with a name matching the pattern "proj*.c" and having a timestamp later than 10/1/2005 12:00 within the directory tree rooted at the current directory.
     
  7. Give the command to use the output of the who command as input to the wc command to see how many users are logged on to the host machine on which you are working. Use the flag with the wc command that only displays the number of lines.
     
  8. Give the command to forceably terminate (kill) the process with process ID 2401.
     
  9. Give the command that would allow you to determine the process ID of an emacs job you have running in the background. This command should only print out lines of information about emacs processes.
     
  10. Give the command to create an alias in tcsh such that whenever you use the mv command, you will be prompted before overwriting an existing file.
     
  11. Give the command that will add the directory ~/projects/bin to your PATH variable.
     
  12. Give the command to create a tar file called proj2.tar of all files under the directory ~/CMSC201/proj2/.
     
  13. Give the command to create an alias in bash such that you can type quota to check on your account quota without having to use the -v option.
     
  14. This question requires a paragraph answer and is worth 25% of this homework grade. Describe in detail how you would implement the automatic keeping of a log file of login and logout times in the tcsh shell. Note that this may require writing UNIX commands and describing how to execute them. You must describe in detail how your proposed solution works. The filename of the log file should be timesheet.log. It should be of the following format:
        Time in:
        Wed Sep 28 11:04:25 EDT 2005
        Time out:
        Wed Sep 28 11:10:28 EDT 2005
        
        Time in:
        Wed Sep 28 12:23:34 EDT 2005
        Time out:
        Wed Sep 28 15:34:19 EDT 2005
        
        Time in:
        Thu Sep 29 23:37:17 EDT 2005
        Time out:
        Thu Sep 29 23:42:23 EDT 2005

     
  15. This question requires a paragraph answer and is worth 25% of this homework grade. Describe UNIX file permissions to a novice user.
    * What are the purpose of file permissions?
    * What are the meanings of the terms "owner", "group", and "public", and how can we change these for a file or directory?
    * Explain how to read and interpret the file permissions listed by "ls -l".
    * How can we change the permissions for a file?
    * Explain how the permissions of the directories along a file's path affect access to that file.