Introductory file permission observations

File permissions govern interaction between files on the one hand, and users on the other. They can control which files are (or aren't) available to which users for which purposes. A file's permissions are embodied in a 9-character string produced by the long listing of the ls command (i.e., by "ls -l"). Consider a file named "data.txt" for example:

[david@frausto ~]$ ls -l data.txt
-rw-rw-r-- 1 david david 410108 2009-08-05 16:52 data.txt

Note the first field on the left contains the 10 characters -rw-rw-r--. It's the rightmost 9 of them, rw-rw-r--, that comprise the file's "permission string." The individual characters are called permission characters or permission bits.

A brief permissions overview is provided. Learn to whom each permission character applies, and how. Then experiment with it as follows.

Logged in as a regular (non-root) user, in your home directory, create a file then examine the permissions it got:

echo  "echo hello"  >  printstuff.sh                        [ creates a file named  printstuff.sh ]
ls  -l  printstuff.sh

The permissions given files upon creation are configurable, but rw-rw-r-- is common. In case your file got something else, set it to rw-rw-r-- :

chmod  664  printstuff.sh                                               [ changes the file's permissions ]
ls  -l  printstuff.sh

Now try to read and write it. You'll use "cat" to read and file redirection to write. So:

cat  printstuff.sh                                                     [ performs a read on the file ]

It successfully disgorges the file's content onto the screen.

Question 1. Of the 9 permission bits, which one of them is responsible for this success?
 a. first
 b. second
 c. third
 d. fourth
 e. fifth
 f. sixth
 g. seventh
 h. eighth
 i. ninth

Now what about writing?

echo  "echo goodbye"  >>  printstuff.sh    [ write-appends to the file ]
cat  printstuff.sh

It successfully writes-in the "echo goodbye" phrase, appending to the pre-existing "echo hello".

Question 2. Of the 9 permission bits, which one of them is responsible for the writing success?
 a. first
 b. second
 c. third
 d. fourth
 e. fifth
 f. sixth
 g. seventh
 h. eighth
 i. ninth

This file amounts to a shell script that, if run, will print "hello" followed by "goodbye". Try to run it:

./printstuff.sh                                           [ tries to execute the stuff we have put in the file (which, strategically, was executable stuff not random prose or garbage)  ]

If fails to run. 

Question 3. Of the 9 permission bits, which one of them is responsible for the execution failure?
 a. first
 b. second
 c. third
 d. fourth
 e. fifth
 f. sixth
 g. seventh
 h. eighth
 i. ninth

Remedy the failure:

chmod  u+x  printstuff.sh
ls  -l  printstuff.sh

Note one of the bits changes. Again try to run:

./printstuff.sh

This time running succeeded. Obviously the bit responsible is the one that just changed. Change the other 2 influential bits:

chmod  u-rw  printstuff.sh
ls  -l  printstuff.sh

The re-try reading and writing:

cat  printstuff.sh
echo  "echo goodbye"  >>  printstuff.sh

Note the behavior and make sure you can attribute it to the right bit, in each of those 2 cases.

In the course of answering the above questions asking you to identify bits involved in the observed behaviors, how many of the 9 bits did you indicate? That is, how many of them were involved? What about the remaining ones? Why did they have no bearing and what are they there for?

What to turn in

Submit your answers to the three questions above following these preparation and submittal instructions Put your answer file in your "assignments" subdirectory on the server.. Please name your file "permissionbits.txt". I will grade these using an automated script, so the format of the answer is critical to intelligibility, as is the case (lower) of the filename.