M.I.T. DEPARTMENT OF EECS
6.033 - Computer System Engineering | UNIX Hands-On Assignment |
This hands-on assignment is due at the beginning of recitation. Please submit your assignment using the online submissions page. Before attempting this hands-on, you should read section 2.5 from the textbook, which is also assigned for this recitation.
This hands-on assignment will guide you in exploring the user visible layers of the UNIX file system.
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
When you log in, the system sets your current working directory to your home directory, your personal name space where you can create your own files, directories and links. You can view the contents of your current working directory with the ls command.
> ls
To learn more about the contents of the directory, you can use
ls with the -l option or any of the other options
listed in the ls manual page; you can read the manual by typing
man ls.
> ls -l
> man ls (read the man page)
Use the pwd command to learn the absolute path of your current working directory. This will tell you where you are in the directory name space even if you move around in the directories.
> pwd
The output of pwd reveals where the Athena administrators
store your home directory. For example,
/afs/athena.mit.edu/user tells us that the your home
directory is stored as a user in the Athena name space.
The stat program reports detailed information about a file including its inode number, link count, file type and other metadata. To use it, type stat followed by a file name at the command prompt. Run stat on your home directory:
> stat .
Now create a directory named 6.033-handson1 in your home directory using the mkdir command. You can learn more about the mkdir command with man mkdir.
> mkdir 6.033-handson1
Use ls to verify that the new directory exists. Now change your current working directory to your new 6.033-handson1 directory using the cd command and verify that your working directory has changed using pwd.
> cd 6.033-handson1
> pwd
View the contents of your new directory using ls -a -l.
ls normally hides the directories "." and "..", but the
-a option forces it to show them.
> ls -a -l
Question 1: Change to the '.' entry in your new directory. What happens to your working directory? Next, change to the '..' entry. What happens to your working directory?
Question 2: Describe a scenario where you might need to use the '.' directory.
Change your current directory back to your new 6.033-handson1 directory and stat the current directory; note the link count. Now create a couple files in your new directory using the touch command and stat the directory again.
> stat .
> touch foo bar
> ls
> stat .
Question 3: What has changed in the stat output and why has it changed?
Now create a subdirectory baz in 6.033-handson1 and stat the directory once more.
> mkdir baz
> stat .
Question 4: What has changed in the stat output this time and why has it changed? Why does the link count only change when you create a new directory?
The ln command can create both hard links and soft (symbolic) links. Read the man page for more information.
> man ln
First stat your file foo and read the output information. Then create a hard-link named foo-lnk and stat both foo and foo-lnk.
> stat foo
> ln foo foo-lnk
> stat foo
> stat foo-lnk
Note that everything about foo and foo-lnk is identical except for their names. If you modify foo you will see the modifications in foo-lnk.
> echo Hello >> foo
> cat foo-lnk
Now create a symbolic link to foo and note that the symbolic link differs from the original file in several ways. Creating the symbolic link does not increase the link count of foo and the symbolic link does not share an inode with foo.
> stat foo
> ln -s foo foo-slnk
> stat foo
> stat foo-slnk
Now cd to the 6.033 Athena locker with the command:Question 5: One reason for supporting symbolic links is to allow linking from one disk to another disk, but you can also create a symbolic link to a file on the same disk. Name one advantage and one disadvantage of using symbolic links on the same disk.
> cd /mit/6.033
Your home directory is accessible by the path /mit/YOUR_USERNAME
(replace YOUR_USERNAME with your username). Try to change to your home
directory with the command:
> cd ../YOUR_USERNAME
Like your home directory, the 6.033 locker's absolute path is much longer than /mit/6.033 and /mit/6.033 is only a symbolic link. You can learn the absolute path name by typing pwd or by typing:Question 6: What happened? Why?
> ls -l /mit
Question 7: You can reach the 6.033 locker with the path /afs/athena.mit.edu/course/6/6.033. Why does Athena also provide the /mit/6.033 symbolic link?
Question 8: How would you change the file system to make this command (
cd /mit/6.033; cd ../YOUR_USERNAME
) actually change to your home directory?
> echo $PATH
You can configure your shell to search the current working directory
by adding '.' to the PATH using these commands:
> setenv OLDPATH $PATH
> setenv PATH .:$PATH
Now, cd to /mit/6.033 and run our demo program using the
following commands. Your shell will find the "demo" program
because it is in your working directory.
> cd /mit/6.033
> demo
Oh no, something terrible just happened! Just kidding, the demo
program did not actually do anything. Verify that nothing happened
with ls.
> ls -l
Usually, it is a bad idea of have '.' in your PATH, because it is easy to run the wrong programs by accident. Instead, you can use '.' explicitly to run programs in your working directory like this:Question 9: What happened to ls? Why isn't it listing files like it did before? (Hint: set your path back to its original state:
setenv PATH $OLDPATH
)
> ./demo
Question 10: How long did this assignment take you to complete up to this point?
Question 11: Chapter 2.5 describes how (in UNIX) a file's inode maps to the file's data blocks using direct pointers and indirect blocks. An alternative strategy, as used in FAT, stores a file's data as a linked list of FAT entries, each corresponding to a block (cluster). Name one advantage and one disadvantage of the linked list strategy.
Question 12: Some shells like bash try to make '..' always work propery, namely, cd /mit/6.033; cd ../$USER will place you in your home directory. Does bash always get this behavior correct?
Go to 6.033 Home Page |