Homework 1

Due Thursday, August 31

The following homework exercises various simple Unix/Linux utilities. Each of the questions has various subquestions. Answer all questions and subquestions. If there is an instruction that does not specifically ask a question (e.g. "Remove the file 'foo'"), then you should tell me what you did to follow that instruction. If I ask a question like "who owns the files in your directory", then you should show me a listing that demonstrates your answer.

One generally useful thing to know is how to use the manual pages. Most commands that you will encounter are described in the manual pages. If you want to figure out how to use the "date" command, for instance you would type:

man date
This will give you a list of arguments and descriptions of their behavior. From within emacs you can type "M-x man", after which emacs will prompt you for the name of a command. In some problems in the homeworks I will assume knowledge that was not necessarily covered in the readings or in class. In that case you should resort to the man page for the command(s) in question to find out how to solve the problem.

  1. Create a directory called "Homework" in your home directory. This will be the repository of all homeworks that you do. For this homework you would create a plain text files called "homework1.txt", and your answers to the questions should be placed there. I will copy the contents of your individual "Homework" directories when the homework is due, and I will take whatever version of the homework that's there as final.
  2. List the (top-level) contents of your home directory. How many files are there? Don't forget the "dot" files. What is the largest file? The smallest file? The most recently modified file? The least recently modified file?
  3. Who owns the files in your directory? Which group owns them? Can anyone in your group read these files? Write these files?
  4. Using the line editor "ed", create a file called "foo" in your home directory containing the words "This is a test":

    
    $ ed foo				<== you type
    foo: No such file or directory		<== system responds
    a					<== you type
    This is a test.				<== you type
    .					<== you type
    w					<== you type
    16					<== system responds
    q					<== you type
    

    What are the permissions on this file? Now make it so that nobody except you can read it or write it.

    Remove the file "foo"

  5. How many files do you have that are executable? (List them)
  6. How many subdirectories do you have? (List them)
  7. From your home directory issue the following command:

    cd ..
    mkdir foo
    

    Did it work? Why or why not?

  8. Return to your home directory: Did you get there by the simplest route, and what was that route?
  9. In your home directory issue the following command:
    mkdir ..
    
    What happened? Why?
  10. In your home directory is a directory called "S". Draw me the tree diagram of the directory "S", showing all subdirectories and files. The "drawing" should be in "ascii art", as in:

                    S
                   / \
                  X1  X2
                 / \  | \
                x3 x4 x5 x6
    
    
    
  11. Translate the following numeric invocations of chmod into symbolic notation:

    chmod 755 foo
    chmod 622 foo
    chmod 155 foo
    chmod 322 foo
    

    Translate the following symbolic invocations of chmod into numeric equivalents:

    chmod u=rwx,go=rx foo
    chmod u=x,go=rw foo
    chmod u=rw,go=r foo
    chmod go=r foo
    

    For the last one, can you specify a numeric code without knowing the current setting? Why or why not?

  12. What happens if you do the following

    touch foo
    chmod 444 foo
    rm foo
    

    Why?
  13. You have a directory "dir" that you want to make accessible to world. You do the following:

    chmod 744 dir
    

    Later on someone complains that they can't do

    cd dir
    

    Who messed up, them or you? Why?

  14. Buried somewhere in your home directory is a directory called "SecretCave". Within that cave you'll find a single file containing some "treasure". The treasure is a text message. Your text message is not necessarily the same as others' so you can't assume your friend's message will be the same as yours. You are to find the Cave, find the file containing the treasure, and tell me what the contents were. The route to the cave is not trivial: I have placed some false turns in there. Not everyone's route to their Cave is the same as everyone else's.

    Explain the means by which you found your cave.

  15. Create two files, "foo" and "bar", containing some text (any text, it doesn't matter what). Now create a file "baz" that is the concatenation of "foo" and "bar".