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.
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.
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?
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?
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:
Copy all the contents of the /usr/share/pixmaps
folder to a new images
folder in your AFS home directory.
Rename this new images
folder in your home directory to pixmaps
.
Move this new pixmaps
folder to /tmp/$USER-pixmaps
(where $USER
is
your netid)
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 |
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:
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.
Similarly, explain why removing the /tmp/$USER-pixmaps
operation is
faster than the move operation.
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
How would you use I/O redirection to process the math.txt
file with
bc?
How would you use I/O redirection to process the math.txt
file with
bc and save the output to results.txt
?
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?
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?
Recall that the Unix Philosophy can be summarized as:
Write programs that do one thing and do it well.
Write programs to work together.
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.
Determine how many accounts in the /etc/passwd
file have /sbin/nologin
as their shell.
Determine how many unique users are logged into the current system.
Determine the top 5
largest files or directories in the /etc
directory
while suppressing any errors.
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.
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.
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.
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.
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.
Explore passing different signals to the TROLL
program. Which ones
lead to interesting messages that are not taunts or insults?
For extra credit, read the following chapters from The Linux Command Line:
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:
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.
If you have any questions, comments, or concerns regarding the course, please
provide your feedback at the end of your README.md
.
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