In Linux/Unix, every file has an string of letters associated with it which tells you who is allowed to view it/use it. If you type ll (short form of ls -l) in any directory in your filespace, you should get a list of files and directories contained in the present directory, like this:
-rw-r--r-- 1 maman stats 997 Jun 2 2003 testfile.txt -rw-r--r-- 1 maman stats 5215 Jun 5 2003 functions.R -rw-r--r-- 1 maman stats 647 May 21 2003 helpfile.html -rw-r--r-- 1 maman stats 1318 Jun 3 2003 package.zip -rw-r--r-- 1 maman stats 860 May 22 2003 tune.mp3 -rw-r--r-- 1 maman stats 1356 Jun 4 2003 anotherfile.tex drwxr-xr-x 2 maman stats 4096 Jul 16 14:33 mynewfilesThe list tells you all the information about the files you have: the permissions, who owns it, the group they belong to, the file size, date and time created, and the name.
Changing Permissions
the command to change file permissions is chmod. On the lefthand column, there are some letters against each file or directory. What the letters mean...
d: directory
r: readable
w: writeable
x: executable
The character string spaces tell you the file permissions: the first is whether it is a directory, the next three give the permissions of the user (you), the three after that give the permissions of the group, and the last three give the permissions of other users. So the maximum character string would be drwxrwxrwx, indicating that the object is a directory, and all the users can read, write and execute it.
To change the permissions, we use chmod [who]=[permissions] [file] or chmod [who] +/- [permissions] [file]. Substitute a combination of the letters u (user),g (group) and o (others) or a (all) in the place of [who] and a combination of the letters r, w and x in the place of [permissions]. I realize that this make no sense, so here is an example. Suppose I wanted to change the permissions of functions.R so that other people could execute and read it. Then I would type chmod o=rw functions.R. Or if I wanted to make it so that only I could read it, I would do chmod go-r functions.R, which says,"take away readable permissions for the group and other users from the file functions.R". Then a ls -l command would show the information:
-rw-r--r-- 1 maman stats 997 Jun 2 2003 testfile.txt -rw------- 1 maman stats 5215 Jun 5 2003 functions.R -rw-r--r-- 1 maman stats 647 May 21 2003 helpfile.html -rw-r--r-- 1 maman stats 1318 Jun 3 2003 package.zip -rw-r--r-- 1 maman stats 860 May 22 2003 tune.mp3 -rw-r--r-- 1 maman stats 1356 Jun 4 2003 anotherfile.tex drwxr-xr-x 2 maman stats 4096 Jul 16 14:33 mynewfilesSo now, I can read and write to the file functions.R, but no-one else can do anything. If I then wanted to give writeable and executable permissions to the members of the stats group, I would issue the command chmod g=wx functions.R or chmod g+wx functions.R. And then the information would be:
-rw--wx-wx 1 maman stats 5215 Jun 5 2003 functions.RAnother way of setting permissions...adding up!
Making the connections r=4, w=2 and x=1, we can set the permissions with arithmetic. 4+2+1=7 and 4+2=6 (surprisingly!!) so if we wanted to set the permissions of eg anotherfile.tex to rwxrw-rw- (readable and writeable for everyone and executable for just the user (me)), we could say chmod 766 anotherfile.tex. Good, eh? Another example... chmod 444 * tells the computer to make all files in the directory readable (to all users), but to have no files executable or writeable.
Still stuck?
Try typing man chmod or info chmod at your Linux prompt.
[top]