The goal of this homework assignment is to allow you to practice examining file permissions, manipulating files, redirecting I/O, and signaling processes in a Unix environment.

For this assignment, record your responses to the following activities in the README.md file in the homework01 folder of your assignments GitLab repository and push your work by 11:59 PM Friday, January 27, 2017.

Activity 1: Permissions & ACLs (2 Points)

On the student machines, your home directory is stored on AFS, which is a distributed filesystem. While it has support for traditional Unix permissions, it also has an additional layer of ACLs or Access Control Lists for managing who can access files and directories.

  1. Use the fs listacl command to view the ACLs on your HOME directory, your Private directory, and your Public directory.

    a. What are the differences in the ACLs for those three folders?

    b. What ACLs make the Private directory private and the Public directory public?

  2. Use the touch command to create a file at /afs/nd.edu/web/$USER.txt (where $USER is your netid).

    a. What was the result of this command? That is, were you able to create the specified file?

    b. Considering this result, which takes precedence on AFS: the Unix permissions or the ACLs?

Activity 2: File Operations (3 Points)

The /usr/share/pixmaps folder is found on many Linux machines. It usually contains images such as icons and wallpapers used by desktop environments and graphical applications.

On the student machines, you are to perform the following operations while using the time command to measure how long each operation took:

  1. Copy all the contents of the /usr/share/pixmaps folder to a new images folder in your AFS home directory.

  2. Rename this new images folder in your home directory to pixmaps.

  3. Move this new pixmaps folder to /tmp/$USER-pixmaps (where $USER is your netid)

  4. Remove the /tmp/$USER-pixmaps folder

Record your answers by filling out the following Markdown table:

| Command                             | Elapsed Time  |
|-------------------------------------|---------------|
| cp ...                              | 0 seconds     |
| mv ...                              | 0 seconds     |
| mv ...                              | 0 seconds     |
| rm ...                              | 0 seconds     |

Reading Time

The time command is typically a Unix shell built-in which executes the specified program and outputs something like the following:

$ time sleep 1
real  0m1.001s
user  0m0.000s
sys   0m0.002s

In the example above, the time command is used to execute the sleep command and measure how long it took. Normally, we are interested in the real or wall-clock time, which in this case is 1.001 seconds.

After performing and timing the operations above, answer the following questions:

  1. Both renaming and moving the pixmaps folder use the mv command but the former operation takes significantly less time than the latter. Explain why this is.

  2. Similarly, explain why removing the /tmp/$USER-pixmaps operation is faster than the move operation.

Activity 3: Redirection (3 Points)

The bc command, which was introduced in Reading 01, is another example of an interactive interpreter. In this case, bc processes and executes basic arithmetic operations (ie. it is a calculator).

Suppose you had a file named math.txt, with the following contents:

1 + 1
2 * 4
(3 - 7) * 8
2^3
4/0
  1. How would you use I/O redirection to process the math.txt file with bc?

  2. How would you use I/O redirection to process the math.txt file with bc and save the output to results.txt?

  3. How would you use I/O redirection to process the math.txt file with bc, save the output to results.txt, and suppress any errors?

  4. How would you use cat and a pipeline instead of I/O redirection to process the math.txt file with bc?

    Why is this considered less efficient than using I/O redirection?

Activity 4: Pipelines (4 Points)

Recall that the Unix Philosophy can be summarized as:

  1. Write programs that do one thing and do it well.

  2. Write programs to work together.

  3. Write programs to handle text streams, because that is a universal interface.

The ultimate example of these tenets in action is the Unix pipeline.

For each of the following tasks, construct a pipeline that combines multiple commands to accomplish each task.

  1. Determine how many accounts in the /etc/passwd file have /sbin/nologin as their shell.

  2. Determine how many unique users are logged into the current system.

  3. Determine the top 5 largest files or directories in the /etc directory while suppressing any errors.

  4. Determine how many instances of bash are running on the current machine.

Hint: You may need to combine any of the following commands: awk, cut, du, grep, head, ps, sort, uniq, wc, who.

Field Extraction

You can use either awk or cut to extract fields from a line of text. For instance, the following returns the first field separated by spaces of each line in the input file:

cat file | awk '{print $1}'

You can accomplish something similar with cut:

cat file | cut -d ' ' -f 1

This returns the first field separated by a single space.

Activity 5: Processes & Signals (3 Points)

For the last activity, you are to run the following program on the student machines:

/afs/nd.edu/user15/pbui/pub/bin/TROLL

This is a program that will taunt you and insult you... until you figure out how to terminate it.

  1. Using a single terminal window, run the TROLL program and figure out a way to terminate it:

    a. Describe what commands or operations failed to terminate the process.

    b. Describe what commands or operations finally succeeded in terminating the process.

  2. Using two terminal windows, run the TROLL program in the first window and figure out a way to terminate it from the second terminal window:

    a. Describe a pipeline that can be used to terminate the process from the second terminal window.

    b. Describe a single command that can be used to terminate the process from the second terminal window.

  3. Explore passing different signals to the TROLL program. Which ones lead to interesting messages that are not taunts or insults?

Guru Point (1 Extra Credit Point)

For extra credit, read the following chapters from The Linux Command Line:

  1. Chapter 11 - The Environment
  2. Chapter 13 - Customizing the Prompt

Once you have read these chapters, you are to customize your bash shell prompt by adding useful information and colors and setting $EDITOR to your preferred text editor.

Here are some additional resources to help you customize your bash shell:

  1. How to Customize your Bash Prompt on a Linux VPS
  2. How to: Change / Setup bash custom prompt (PS1)
  3. Customize Your Bash Prompt
  4. Bash/Prompt customization
  5. In Unix, how do I set my default (preferred) editor?

Bash as Default Shell

Normally, to change your default shell, you would use the chsh command. Unfortunately, the student machines do not allow for this operation and so we cannot use this mechanism. Instead, you have to use the following unsupported workaround to make bash the default shell:

if ($?prompt) then
    setenv SHELL /bin/bash
    exec /bin/bash
endif

Append the code above to the bottom of your ~/.cshrc file. This code snippet checks if the session is interactive; if so, it sets the SHELL environment variable to /bin/bash and then executes the bash shell.

With this in place, you will automatically be given the bash shell whenever you login rather than tcsh.

To get credit for this Guru Point, show your bash shell customizations to the instructor or a TA to verify.

Feedback

If you have any questions, comments, or concerns regarding the course, please provide your feedback at the end of your README.md.

Submission

To submit your assignment, please commit your work to the homework01 folder in your assignments GitLab repository:

$ cd path/to/repository                   # Go to assignments repository
$ cd homework01                           # Go to Homework 01 directory
...
$ $EDITOR README.md                       # Edit appropriate README.md
$ git add README.md                       # Mark changes for commit
$ git commit -m "homework01: complete"    # Record changes
...
$ git push                                # Send changes to GitLab