
Before we even start with the permissions thing, you have to be sure you understand what a file is and how it is different from a directory. See the page on files and directories before reading about permissions. (If you are aware of what files and directories are, you can probably go right to permissions). What follows is an example of files and directories.
Let's imagine that over the past semesters, you've collected a humonguous number of
files on your
account. doc files, picture files, mp3's!, etc.. To help you organize your stuff, the unix
system
has containers called directories. So now all your doc files can go to a DOC directory, all
your
picture files can go to a PICTURES directory and so forth.
If you had like 100 pictures: 30 from your high school, 30 from your home town, and another 40 from your vacation; you can further organize your stuff by making more directory containers within the PICTURES directory. A directory to hold your high school snaps, another to hold your vacation, home town..
Having separate directories to hold all your stuff leads to a clean directory structure, one in which you can find things efficiently and effortlessly. In the example that we had used above, we should end up with the following directory structure: PICTURES, DOCFILES and MP3FILES directories on top. Within the PICTURES directory, we have the HIGHSCHOOL, HOMETOWN and VACATION directories.
When you login to your class account, you are brought to your top most directory. For
some good
reason, it's called your root directory. It is also referred to as the home directory. It
is from here
that you navigate to other directories. Typing ls (list) at the > prompt brings you a
listing of all
the files in the current directory. For our example a list command will come up with the
following items:
>ls
Mail DOCFILES MP3FILES PICTURES
>
If you wanted to rename the DOCFILES directory to docs you would use the mv command. At the
prompt you
would type: mv DOCFILES docs
>mv DOCFILES docs
>
We still have some work left. If you wanted to access any picture from your web page, it
has to
reside in the public_html directory. As all your pictures are stuck at the root directory
currently,
let's move the whole directory into the public_html directory.
You would type: mv PICTURES public_html
>mv PICTURES public_html/
>
I know mv was the same command you had used earlier to change the name of DOCFILES, and now
you are
being asked to use the same command to physically move PICTURES into the public_html
directory. It
works because public_html is an already existing directory so it can't rename something
else to it
(you are not allowed to have two directories with the exact same name, you can have a
Mail directory together with a mail directory as Unix is case
sensitive).
Every file and directory on the UNIX system has a set of permissions associated
with it. This is not the case in Windows 95, 98 or DOS. Windows NT has the idea of
permissions, but
they are handled very differently. When you create a new file (like the index.html), you as
the owner
have two permissions set for you automatically. You have the right to read your file and
make changes
to the file. Before we try the next
command, let's get into your public_html directory. If you are at your root
directory, you would type: cd public_html
>cd public_html
>
else type: cd and then the
command line listed above
>cd
>cd public_html
>
In the command line "cd public_html" cd stood for change directory, it was followed by the
name of the directory your wished to
change to. The other command, a plain "cd" gets you to the root directory regardless of
wherever you are. Go through the unix
commands on top to learn more about the navigating commands.
You are now in the public_html directory. Here is what would turn up if at the prompt you
typed: ls -l
>ls -l
total 2
drwxr-xr-x 2 c3063gyz cgs3063 512 May
29 20:04 PICTURES
-rwxr--r-- 1 c3063gyz cgs3063 2056 May
29 20:04 index.html
>
What you did was use the same list command but with an option of "-l" This lists
the files along with other details, most importantly for our discussion, the
permissions. Notice the string of characters in front of each entry. If you notice
carefully, the first entry has a leading "d" and the second entry does not. The
"d" tells us that PICTURES is a directory and the absence of "d" in the entry for
index.html tells us that it's a file. The remaining nine characters can be broken
up into sets of three characters each. The first three "rwx" belong to you. The
presence of "r" indicates you have the read permission. The presence of "w"
indicates you have the write permission(make changes). The presence of "x"
indicates that you have the execute permission(play the game if the file were a
game). The next set of three characters belongs to your group. For the purposes of
this class, assume that all your classmates belong to your group. The last set of
three characters belongs to the rest of the world. In the case of PICTURES, your
group and the rest of the world has "read" and "execute" permissions but not
"write." In the case of index.html, your group and the rest of the world has only
"read" permission. Alright, we are cutting to the groovy stuff now. Changing
permissions. As
noted earlier, the three things you can do to a file are read, write and execute.
Read has a value of 4, write a value of 2 and execute a value of 1. To give
yourself or others rwx permissions, you would simply add the values for r,w and x:
4+2+1 for a 7. Let's play around a little. If you typed the following at the
prompt, this is what you'd
get: chmod 777 index.html
>chmod 777 index.html
>
and listed the files with the "-l" option.
>ls -l
>
total 2
drwxr-xr-x 2 c3063gyz cgs3063 512 &nbs$
29 20:04 PICTURES
-rwxrwxrwx 1 c3063gyz cgs3063 2056 &nb$
29 20:04 index.html
>
Did you notice the difference? Your index.html file now has read, write and execute
permissions set for
you, your group and everyone else. Needless to say this is a very dangerous
situation. As anyone in your group or anyone anywhere in the world has write
permissions to your index.html; they can make changes and save them!! You never
want to give your write permission away like that. So let's fix it fast.
You would type at the prompt: chmod 744 index.html
>chmod 744 index.html
>
Since you really don't need execute permissions on your index.html, 644 will
do.
>chmod 644 index.html
>
It's not for nothing that you are fooling around with permissions. For a browser to be able
to access your public_html directory, you need to give the directory
"execute" permissions for "the rest of the world." Within the public_html
directory, the first file to be accessed is the "index.html," which needs to have a
"read" permission for the "rest of the world." Don't get a stoke trying to
figure out what numbers that translates to. Here they are: 755 for the public_html
and all other directories, and 644 for all html files and pictures.
To illustrate all this, let's imagine your friend Buddy Holly now living as a
recluse in Dakovica is terribly interested in how you are doing on your class
assignments. He can view your web page only if you give your public_html,
executable permissions for the rest of the world; and your index.html, read
permissions for the rest of the world.
