Unix Systems Programming: Introductory Lab
Due: Friday, January 13, 2017, by 5:00 pm
Purpose and rationale
The purpose of this lab is to quickly get students up to speed with basic
usage of the Unix development environment, as a preparation for all future
lab activities.
Recources
FAQ(submission
instructions and other useful stuff)
You should refer to relevant sections of the man pages for assistance for
this lab, in addition to materials in your assigned primary texts for this
week.
For printing out your documents, you might find the following commands
useful during your year(s) in this department:
- lpr - off line print. Note that this command is called
when you print from acroread (for .pdf files) or gv
(for .ps files)
- lpq - shows the printer queue
- lprm - removes jobs from the printer queue
- enscript - converts text files to PostScript (useful when
you want to print out text files)
All work should be done on a machine in the department's
Linux cluster. You can refer to ssh for
more
information on
how to log into a remote machine.
Marks Distribution
Exercise 1 |
2 points |
Exercise 2 |
8 points |
Exercise 3 |
2 points |
TOTAL |
12 points |
Introductory LAB
- EXERCISE 1: In your home directory create the subdirectory ~/cspp51081/labs/lab1
. (Use multiple mkdir commands or consult the -p option for mkdir in the
man page for mkdir).
- cd ~/cspp51081/labs/lab1
- Copy or create a file named myfile into ~/cspp51081/labs/lab1
(if you create it, type something into it). For information on how
to create a quick empty file, man touch.
- Create a soft link soft_link and a hard link hard_link
to that file.
- Based on the output returned by stat and ls commands
(using all relevant options), explain in detail (but briefly) the differences
between the three files.
- EXERCISE 2: Read the man pages for the following commands:
- script
- who, w
- finger
- touch
- top
- mkdir
- umask: umask [value] (shell built in command)
- text utilities: sort, uniq, tr, expand, unexpand, cut, grep
.
The objective of this exercise is to demonstrate in a reasonably small (the
smaller the better) number of commands that you understood how to use the
commands above and when they are useful.
Create a transcript that shows you understand the commands listed above.
By transcript, I mean a file that shows the output of your session.
See this
example. Yours will be longer. You can use the script
command to create the transcript, or you can cut and paste, whatever works
for you. In your transcript file please show:
- How many John's (first name) have user accounts on the department's computers
[a single pipeline of 3 processes]. Rather than using ypcat to access the list of users, cat the file on the linux cluster at /stage/classes/archive/2017/winter/51081-1/labs/introlab/ypcat.out or here. Hint: use grep and also look at wc.
- Show the jobs in the printer queue. [3 characters if you're lucky]
(What printer is your default printer, by the way? See it also with echo
$PRINTER. No need to show this in the transcript)
- Change your file permission mask such that by default your colleagues
do not have read permissions for your newly created files. Please show in
the transcript file the following:
- the initial mask
- how you changed it
- show that people in your user group don't have read permissions
for a new file you're creating.
Change the umask permanently by placing the umask ... command in your .bash_profile
file.
- List the PIDs of all processes running as root on your computer
on a line, separated by commas. E.g.,: 1,2,3,4,5,657,658, ... Use pipes to
create a one-line command that accomplishes this. You'll need some of the
text processing tools presented in class. Hint: man ps (-a and -x flags),
man tr.
- List the usernames and names of the people logged on linux.cs.uchicago.edu
. (NOTE: you may find the finger command option of ssh
helpful.) The list returned should be sorted, should not contain duplicates
(e.g., same user listed multiple times) and should have the following format:
1 <username1> <name1>
2 <username2> <name2>
3 <username3> <name3>
...
Hints: use the "nl" command to number lines.
- EXERCISE 3: Explain in English what information you can get about ~mark/pub/51081
using all (and only) relevant options of ls and stat commands:
(is it a file? a directory? how large? permissions? access info? etc.) Indicate
the fields that reveal these pieces of information.
More information:
GNU
text utilities (renamed "GNU coreutils")
Hobbes' Internet
Timeline (just for fun)
Carefully follow the 4 steps below.
- Create a directory:
username.introlab
- There will be seven (or three) files in this directory: You must have your
name on the first line of each file.
- When you are finished with your directory you will create a
compressed archive file using tar
(this utility stores your directory as a single file, then compresses
its size.)
tar -czvf username.introlab.tgz username.introlab
- You will email your file to our TA as an attachment. He will send an acknowledgement that your assignment has been
received.
To |
Nicholas Flees
(nickflees@uchicago.edu) |
Attachment |
username.introlab.tgz |
Subject |
CSPP51081-introlab |