CMSC 121, Section 0201 - Fall 2006
Introduction to UNIX

Homework Assignments

Homework 1 - Due Monday, 10/02/2006

Reminder: Don't forget to put the statement of sources used at the top of your homework!

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 10/06/2006

This assignment was adapted 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.

  • Connect via SSH to 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.
  • Make sure that you are in you home directory before you proceed further into the assignment.
  • 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".
    1. Verify that you are in your home directory. Meaning issue the command that prints out the current working directory.
    2. Make a directory called "courses". If for whatever reason this directory already exists, then simply skip this step.
    3. Change the current working directory to this newly created directory called "courses".
    4. Again issue the command to verify that the current working directory is now in this "courses" directory.
    5. From within this directory make 2 different directories called "cmsc121" and "temp".
    6. Now do a normal listing of this directory. You should note the 2 new directories now show up in this listing.
    7. Now let's create an empty file called "file0".
    8. Now do a long directory listing.
    9. Copy "file0" into the directory "cmsc121"
    10. Let's copy some more files. This time we will get them out of my public directory. Copy the "file1" from /afs/ into the directory called "cmsc121"
    11. Now copy all 3 of these files out of my public directory. Copy "file1", "file2" and "file3" all into the directory called "temp".
    12. Now do a directory listing of each of the 2 directories "cmsc121" and "temp"
    13. Move "file0" (the one that is in this current directory) into the "temp" directory.
    14. Copy "file3" (which is in the "temp" directory) into the "cmsc121" directory
    15. Change directories into the "temp" directory
    16. Show the contents of both of "file2" and "file3" using the "cat" command.
    17. There is 1 slight difference between these 2 files. Use the UNIX command that will show the differences between these 2 files to discover what it is.
    18. 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.
    19. Now let's issue the command to remove a directory. Let's try to remove the "temp" directory. Issue the command to remove a directory and note what happens. We get yelled at because the directory is not empty.
    20. 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.
    21. 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.
    22. Go ahead and do a directory listing of the "courses" directory to verify that the "temp" directory has been removed.
    23. Now change directories into the remaining "cmsc121" directory.
    24. There should be 3 files in this directory. 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 a long directory listing would show.
    25. 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.
    26. 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/ Part of the goal of this course is to get you to work more efficiently. There are many shortcuts to achieve the same effect.
    27. Issue the command to delete the "cmsc121" directory and all files within it recursively. You should only be using one command for this. If you wish, you can use the argument that will "force" the deletion. Be careful if you decide to use the "force" option!
    28. 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.
    29. Now issue the command that will print out the current date and time
    30. Issue the command that will print a list out of all the users that are logged onto the same computer that you are.
  • 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".
  • Now that all of the assignment has been logged to the file called "typescript", 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 after we go over the command in class and make certain it is working for everyone.

    Homework 3 - Due Wednesday, 10/11/2006

    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.

    For any questions asking you for a UNIX command, it is not necessary to run these commands under UNIX and log them with the script command, as in the previous homework. All you should submit is the command you would use to perform each of the actions listed below.

    I highly recommend that you 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 list all locations in your PATH variable where the more command may be found.
    3. Give the command to display the instance of the emacs command that is executed when you type in the emacs command.
    4. 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".
    5. Give the command to forceably terminate (kill) the process with process ID 2401.
    6. 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.
    7. 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.
    8. Give the command that will add the directory ~/projects/bin to your PATH variable.
    9. Give the command to create a tar file called proj2.tar of all files under the directory ~/CMSC201/proj2/.
    10. Give the command to create an alias in bash such that you can type quota to check on your account quota without having to explicitly use the -v option every time.
    11. 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

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