CSE 490c - Homework 1

Due: Friday, April 9, 2:30 pm, by email.

The purpose of this homework is to get you acquainted with the Unix shell, including (1) learning to use the Unix help system; (2) familiarity with using common commands; (3) some idea of how you might use these tools in everyday programming.

Write your answers in a plain Unix text file and send it in the body of an email message to Charlie with a subject that begins with the string: 490c-hw1. Make sure you indicate clearly which answer goes to which question.

You should write your answer to this homework alone. However, feel free to consult with your friends about Unix in general. A great deal of Unix culture has always been transmitted orally. On the other hand, you should not just ask your friend for the answer to any question! So, for example, it is acceptable to ask: "Do you know what command can do foo?" To which your friend may reply: "Do 'man foobar'". Your friend may not answer: "The answer to question 7 is foobar -f -n -q -X:!{#}.".

Questions

  1. We'll start with creating a place to work. What commands could you use to do the following tasks?

    1. If you haven't already, create a directory in your home directory named courses and a subdirectory within that named cse490c. Next, within cse490c, create a hw1 directory. (Variations on these names are ok.)
    2. From your home directory, prevent anyone else except you from accessing (r, w, or x) the courses directory or any subdirectories inside it.
  2. To get some interesting data to work with, we'll use a command called wget, which can download files from the Web.

    1. How can you learn about wget?
    2. Say you were downloading a large file from the URL http://www.cs.washington.edu/education/courses/cse490c/04sp/homework/hw1/reallyBigFile.txt with wget. If your download was interrupted, what command could you use to resume where you left off?
    3. Go ahead and download this file to your courses/cse490c/hw1 directory. What are its contents?
  3. What command could you use to view the contents of this file, excluding any lines that contain the words "garbage" or "junk"?

  4. What command could you use to replace every occurence of "big" with "large" when viewing the file, while also excluding lines with "garbage" and "junk"? (Be sure to replace all the occurrences of "big"!)

  5. It's often convenient to create compressed archives of files, either for copying or backup. A common way to do this is with tar and gzip. Show the commands you could use to:

    1. Create a copy of reallyBigFile.txt called anotherFile.txt.
    2. Create a sampleFiles.tar archive containing all the files that end in .txt from this directory. (Hint: you might have to tell the command to write to an archive file instead of a device, and telling it to be verbose can be helpful to see what it's including.)
    3. Compress this into sampleFiles.tar.gz.
    4. Create sampleFiles2.tar.gz containing the same two files, but only using the tar command!
  6. Ok, no point in having identical files lying around. How could you use rm to remove anotherFile.txt and sampleFiles2.tar.gz, but have it prompt you for confirmation first?

  7. Now for something a little more realistic! Unix is built for programmers, so let's see how some of these commands could be useful in programming tasks. For this problem, turn in the series of commands you used to accomplish each part.

    1. First we need some code to look at. From your shell, download http://www.cs.washington.edu/education/courses/cse490c/04sp/homework/hw1/jedit41source.tar.gz to your hw1 directory.
    2. Decompress and extract the files in this archive. It contains the source code for a fairly popular open source project called jEdit. According to the jEdit/doc/README.txt file, what is jEdit?
    3. Go into the jEdit/modes directory. What is the timestamp of the most recently modified file? (Hint: it might help to list them in order of modification.)
    4. Go to the jEdit/org/gjt/sp/jedit directory, which contains most of the code for jEdit itself. How could you view all the lines that include the word "JEditTextArea", in all the files of all the subdirectories?
    5. In which line numbers of which files does "JEditTextArea" appear in a single-line comment ("//")?
    6. Suppose we'd like to revisit the decision to make some methods static. Which methods in the org.gjt.sp.jedit.browser package are static void?

    Note: keep these files around, since we'll use them for Homework 2 as well.

  8. Finally, let's customize your shell. You can use either tcsh or bash; just say which one you used. For this problem, submit the changes you make to your .cshrc or .bash_profile files.

    1. Your path tells the shell where to find executable files. Add another directory to the end of your path, so that it is remembered each time you log in. (For example, you might want to add /uns/bin to your path on the Instructional Linux machines. This directory has lots of "unsupported" / student-maintained software that you might find useful, like the firefox web browser.)
    2. Change the text of your prompt to be something different from the default or what we've seen in class. There are plenty of useful bits of information you might include, but you probably don't want to make it too long!

Side note for the curious: If you want to try to compile and play with the jEdit source and you're logged into attu, go to the jEdit directory and run ant dist. (Ant is a build tool in /uns/bin, sort of like make.) You can run your newly compiled jar file with java -jar jedit.jar.