CS2023 Assignment 1

Winter 2004

Due Wednesday, January 21, 10:30 AM, in the assignment bin on E-Level
This assignment will be marked out of 30 points. The worth of each question is given below.
  1. Consider the following partial UNIX directory structure:
    1. What are the absolute pathnames for: root, bin, green, and Pickup? (2 points)
    2. Suppose that basketball is your working directory. What are the relative pathnames of root, bin, green and wrestling? (2 points)

    3. Suppose that green is now your working directory. Show how you could accomplish the following tasks using a single command:

    4. List the contents of the basketball directory. (1 point)
    5. List the contents of the swimming directory. (1 point)
    6. Make a copy of red's hockey Ateam file and place it in the wrestling directory with the name Trial. (1 point)

    7. Suppose that red is now your working directory. Show how you could accomplish the following:

    8. Copy the contents of the basketball directory into red's hockey directory. (1 point)
    9. Delete the basketball directory and all the files inside it. (1 point)
    10. Change the name of red's hockey directory to teams. (1 point)
    11. Make a new directory inside the teams directory called reserve(1 point)

     
    1. Assuming you have completed the above questions, draw the current directory structure of the red directory. (4 points)
  1. (2 points) Create a file called sig in your home directory that contains your full name, program (e.g., Computer Science) and e-mail address. For example:
  2. Eric Aubanel
    Computer Science
    aubanel@unb.ca
    Once you have this file created, use the cat command to display its contents.
  3. (1 point) From your home directory, create a subdirectory for each of 8 assignments (such as: assn1, assn2, ...).
  4. (1 point) List the contents of your home directory, redirecting the output to a file called dlist.
  5. (1 point) Move this file to the directory for assignment 1.
  6. (1 point) In the directory for assignment 1 create a file, oneline.c, containing the following:

  7. #include <stdio.h>

    int main()
    {
      int c;

      while((c = getchar()) != EOF){
        if(c != '\n') putchar(c);
        else putchar(' ');
      }
      putchar('\n');
      return 0;
    }

    Compile oneline.c, and store the executable in a file called oneline.
     

  8. (1 point) Run oneline, redirecting stdin to the file dlist you created in 4 above and stdout to a file called dlist1.
  9. (1 point) Using oneline and a pipe, list the contents of your directory for assignment 1 on one line.

  10. Now, you will run oneline without redirecting stdin or stdout:

    1. (2 points) Run oneline, and type some characters followed by the <enter> key. Then type more characters, again followed by <enter>. Notice that the output is not displayed until after each <enter>. Explain this behaviour using the concept of an I/O buffer.
    2. (1 point) How can you terminate the input to oneline?
    3. (2 points) Run oneline, type some characters followed by ctrl-d, without typing <enter> first. Explain what happens.
  11. (2 points) Finally, exit the shell you were using to do the above, using a keystroke (i.e., not using your mouse). Why does this keystroke work?

Deliverables

Your assignment must include printouts of all your sessions (all that you see on the screen when executing the commands to answer the questions), either making use of the script command or cutting and pasting from the terminal window into an editor.
 
Eric Aubanel, Jan. 14 2004