Hands-on 2: The UNIX Time-Sharing System

Due: 11:59pm February 26, 2019

Before attempting this hands-on, you should read The Unix Time-Sharing System, which is also assigned for two recitations. You might also find Section 2.5 of the book useful.

This hands-on is longer than the DNS hands-on; you should expect to spend a bit more time on it (as such, we've given you more time in which to do it).
For many of you, this will be your first experience using a shell (minus the few commands we had you run in the DNS hands-on). That's okay! Please stop by office hours or post a question on Piazza if you need help getting comfortable using a shell.

Warmup

Log into an Athena machine (athena.dialup.mit.edu is ok) and get access to the Athena command prompt. If you logged into an Athena dialup machine, you should see the prompt in your ssh client. If you logged into an Athena workstation you may need to open a terminal window. The prompt should look something like this (the "no-knife" part may say something different):

no-knife:~>

Use the add command to gain access to the 6.033 utilities you will use in this assignment.

no-knife:~> add 6.033

Some of the directions in this hands-on assume your UNIX shell is tcsh. Run the following command to ensure you're running the appropriate shell. After you run tcsh -f your prompt will change to a single >.

no-knife:~> tcsh -f

We'll start off with a small example:

> cd /bin
> ls -1 | more
Here, we are first changing into the /bin directory, which contains many of the executable commands for the system. The command ls -1 gives us a listing of all the files in the current directory with one file per line. (Note that -1 is the numeral "one", not the letter "L".) We then pipe the output from ls to the command more, which displays the results one page at a time. (Press the space bar to show the next page. In order to quit the enumeration, press q.) You can refer to the manual pages for ls and more to see more details and options for each command. Manual pages let you read information about various commands on UNIX systems; to use them, run
> man command

where command is the command you are interested in. If you are unfamiliar with manual pages, try running

> man man
for information on the man command itself. Keep in mind that the manual pages for basic commands vary from system to system (much as the commands themselves do).

Now, try this:

> cd /bin
> ls -1 | grep p | more
This runs the same ls -1 command, but only lists the executable files which happen to contain the letter "p" somewhere in their names.

The point here is to observe that you can chain together multiple commands using the pipe character (| ), and the output from each command will be passed to the input of the next, in left-to-right order. This allows you to treat any command that uses standard input and output as a primitive from which you can build more complex and useful commands.

Building Blocks

Now, we'd like you to figure out on your own how to solve some problems by chaining different commands together.

If you aren't already familiar with these commands, you may want to briefly skim through their man pages to familiarize yourself with what they do. You will probably need to use some of the options for the different commands in order to solve these problems.

Here are the commands you may find useful:

cat
fmt
grep
head
ls
ps
sort 
tail
top
wc
yes (*)

(*) On some Athena machines, the yes command isn't available. However, if you are doing this assignment on Athena you can use the command gyes, which is functionally equivalent. gyes is located in the "gnu" locker, so before you can use it you need to add the locker. You can do so with the following command:

> add gnu

(If you are curious about Athena's locker system, you can run man lockers for more information. The command whichlocker can be used to determine which locker contains a given command. The whichlocker command itself resides in the "outland" locker. For more info on other lockers, look at this SIPB article)

Once you have added the gnu locker, you can use gyes instead of yes. Some Athena machines seem to lack the manual pages for both yes and gyes (hereafter referred to just as yes). In case the man pages are missing on the machine you are using, here is a brief description of what yes does. yes is very simple; it just outputs a string repeatedly until killed. It takes either one or zero arguments; if you give it a string as an argument it will output that string until it is killed (you can kill a process by pressing control-c). If you give it no arguments, it will output the string "y" until it is killed, which explains why it is named yes.

III. Questions

Now you're ready for this week's questions.

Like before, the questions are in a read-only google doc. Make sure to enter quesitons in the page indicated and upload them as a PDF to Gradescope. See more detailed instructions at the end of last week's hands-on. If you are having Gradescope questions, please post a question on Piazza!