CS010 Practice 10

More Unix File System and

Preprocessor Commands, Make

Unix File System

File Protection

Unix is a multi-user operating system. We have seen that you need to login to use Unix. One major reason for logging in is so that Unix can support file protection. File protection allows the creator of a file to decide who should be able to view a file, modify a file, or execute a file. Every file that you create is created with the following protections by default:

Viewing the file protection

To see how a file is currently protected, you list the file in long format using "ls -l":

-> ls -l
total 30
-rwxr-xr-x  1 jcool    20000     27488 Jan 15 11:02 face*
-rw-r--r--  1 jcool    20000      2173 Jan 15 11:02 face.c

Let's dissect this output. The total line indicates how many K of memory the files use. Next each file appears on a separate line. The first chunk of text is the file protection information (more on this below). Next is the number of hard links to the file. This is usually 1. We wil not discuss hard links further. Next is the user id of the file's owner. Next is the name of the group the user belongs to (more on this below). In this case the name is a number (20000). Following that is the size of the file in bytes. Next is the date and time that the file was last modified. Finally, the name of the file appears.

Each file has an owner and a group as listed above. File protection is divided into 3 categories: permissions for the owner, permissions for the members of the group, and permissions for all other users. As mentioned earlier there are 3 types of permission:

The file protection string consists of 10 characters and defines the permission for each category of user (owner, group memebers, others) as follows. The first character is - for normal files. It is d for directories. The remaining characters are 3 character sequences. The first 3 characters define the permissions for the owner of the file, the next 3 define the permissions for the group and the last 3 define the permissions for all other users. The characters are always in the same order:

File protection of directories

The meaning of protection is a little bit different for directories than for ordinary files. For directories, they are interpreted as:

Changing the file protection

Only the owner of a file may change the file protection. To change file protection use the chmod command. You need to tell chmod how to change the protection and which files to change. To specify the protection changes, you identify the class(es) of users:

Next you indicate if you want to add or remove permission:

Finially, you indicate which type of permission you are adding or removing, using r, w, and x. So, if you want to change your files so that nobody else can read or execute them, you would say:

-> chmod go-rx *

Now, if you viewed the protections, you would see:

-> ls -l
total 30
-rwx------  1 jcool    20000     27488 Jan 15 11:02 face*
-rw-------  1 jcool    20000      2173 Jan 15 11:02 face.c

Symbolic Links

Sometimes it is convenient for one program to have more than one name. This is particularly useful if multiple users want to have the same file in their local directories, not a copy of the file. When the file is modified through any of its names, the modified version is immediately visible through all of its names. (A lot like a pointer, right!) You currently have several symbolic links in your home directory. This is how sysadmin ensures that you all have a standard setup to your accounts initially. All the symbolically linked files happen to be files whose names begin with .. These do not show up when you list your files unless you use the -a argument:

-> ls -a
.saves-10041-boran.cs.williams.edu~  <a bunch of these>
   <and all your regular files>

The files whose names end in @ are symbolic links. These files were created by sysadmin to make the standard configuration. To see where the real file lives, use the "ls -l" command:

-> ls -l .emacs
lrwxr-xr-x  1 jcool  20000  33 Jan  2 18:00 .emacs@ -> /home/cs-students/standard/.emacs

Note that the first letter of the protection string is l. This indicates that it is a symbolic link. Symbolic links always have all protections listed. After the .emacs file name is the name of the file that this points to. We can look at the permission of the file being pointed to:

-> ls -l /home/cs-students/standard/.emacs
-rwxr-xr-x  1 root  daemon  1524 Jul 25  2000 /home/cs-students/standard/.emacs*

The owner is root, the sysadmin. Since you are not the owner, you can read and execute the file, but you cannot modify it. (Actually, x only means you can try to execute it. The contents are not executable and an attempt to execute it will report an error). This means that you cannot change .emacs in place. You could delete the .emacs file in your home directory. That jus removes the name from your directory but does not delete the file that it is linked to. So, you could create your own .emacs file but then if anybody updated the default version, you would not get those changes. Instead, as we saw last time, the default .emacs file loads your private .local_emacs file. In general, if you want to customize Emacs, you should modify your .local_emacs and leave the .emacs file alone.

If you want to create a symbolic link, you do that with the "ln -s" command:

-> ln -s face happy_sad_face

The order of the arguments is the same as for cp or mv. This creates a new file named happy_sad_face that is symbolically linked to face.


  1. Take the list.c program from my shared directory and break it into multiple files. You should end up with a list.c, list.h and main.c file.
  2. Create a makefile that will build this program for you.
  3. Add debugging statements to your functions in the list program. Use conditional compilation so that they are only executed if debugging is set at compile time. Use a #define statement to turn debugging on and off.
  4. Remove the #define in your source code that controls debugging. Instead, change the value of your CFLAGS variable in your makefile to turn debugging on and off.

Return to CS 010 Home Page