Quote:
purana:~/Desktop/temp michaelf$ ls -l
total 0
-rw-r--r--* 1 michaelf* michaelf* 0* 1 May 08:14 file
|
Before using chown or chmod I will explain the output above and what part of the directory listing of this file is affected
by the use of either command.
First chown. chown allows us to change the owner and group of a file. As you see above in the example I have our current
owner and group is michaelf:michaelf (or expressed as michaelf.michaelf on some other UNIX variants) To change the owner and/or group you can use
the chown command.
Load terminal.
Quote:
Example;
purana:~/Desktop/temp michaelf$ sudo chown michaelf:nobody file
purana:~/Desktop/temp michaelf$ ls -l
total 0
-rw-r--r--* 1 michaelf* nobody* 0* 1 May 08:14 file
|
As you can see the group has been changed to nobody, owner still remains as michaelf.
Quote:
Example;
purana:~/Desktop/temp michaelf$ sudo chown nobody:nobody file
purana:~/Desktop/temp michaelf$ ls -l
total 0
-rw-r--r--* 1 nobody* nobody* 0* 1 May 08:14 file
|
If we wanted to apply a change to say a directory and all the files/folders below it, then you'd use the following additionial switches
Quote:
Example;
purana:~/Desktop/temp michaelf$ ls -l
total 0
drwxr-xr-x* 6 michaelf* michaelf* 204* 1 May 08:36 dir
-rw-r--r--* 1 nobody* * nobody* * * 0* 1 May 08:14 file
purana:~/Desktop/temp michaelf$ ls -l dir
total 0
-rw-r--r--* 1 michaelf* michaelf* 0* 1 May 08:36 file1
-rw-r--r--* 1 michaelf* michaelf* 0* 1 May 08:36 file2
-rw-r--r--* 1 michaelf* michaelf* 0* 1 May 08:36 file3
-rw-r--r--* 1 michaelf* michaelf* 0* 1 May 08:36 file4
purana:~/Desktop/temp michaelf$ sudo chown -R nobody:nobody dir
purana:~/Desktop/temp michaelf$ ls -l dir
total 0
-rw-r--r--* 1 nobody* nobody* 0* 1 May 08:36 file1
-rw-r--r--* 1 nobody* nobody* 0* 1 May 08:36 file2
-rw-r--r--* 1 nobody* nobody* 0* 1 May 08:36 file3
-rw-r--r--* 1 nobody* nobody* 0* 1 May 08:36 file4
|
Now we have owner nobody and group as nobody. The chown command will take many swithes, so if you want to dig deeper be sure
to consult the man page for the command. This can be done by using man (man chown).
That concludes chown, now lets discuss chmod.
Lets start with the following;
Quote:
purana:~/Desktop/temp michaelf$ ls -l
total 0
drwxr-xr-x* 6 nobody* nobody* 204* 1 May 08:36 dir
-rw-r--r--* 1 nobody* nobody* * 0* 1 May 08:14 file
|
The bits in front of the files/directories as shown above can be changed using chmod, but first I will break down the bits
and tell you an easy way to remember values etc.
(-) --- --- ---
The first bit as shown above is reserved for showning special bits, in the example above it shows
us a dir contains this field as a d, where as a file it is blank. This is all we really need to concentrate on at the moment.
- (---) --- ---
The next 3 bits relate to the owners permission to this file and/or directorey (contains any combination of rwx)
- --- (---) ---
The next 3 bits relate to the groups permission to this file and/or directory (contains any combination of rwx)
- --- --- (---)
The next 3 bits relate to the group other and what permission other has to this file and/or directory (contains any combination of rwx)
To change the various permissions for each of the bits, its expressed using a 3 digit number. To remember the various combinations for
setting these permissions, we can use the following rules.
(rwx) (rwx) (rwx)
(421) (421) (421)
For a file, r= read, w= write and x= execute (can run/launch a file)
For a dir, r= read, w= write and x= execute (can list (ls) a dir and see the files inside it)
Just add up the numbers below the bits to get your final permissions.
ie. Say I wanted to give the permissions of rw-rw-rw, then I would add up the numbers accordingly.
(4+2=6) (4+2=6) (4+2=6), which then means my 666 would be the 3 digit number passed to my file.
Quote:
Example;
purana:~/Desktop/temp michaelf$ ls -l
total 0
drwxr-xr-x* 6 nobody* nobody* 204* 1 May 08:36 dir
-rw-r--r--* 1 nobody* nobody* * 0* 1 May 08:14 file
purana:~/Desktop/temp michaelf$ sudo chmod 666 file
purana:~/Desktop/temp michaelf$ ls -l
total 0
drwxr-xr-x* 6 nobody* nobody* 204* 1 May 08:36 dir
-rw-rw-rw-* 1 nobody* nobody* * 0* 1 May 08:14 file
|
And as you can see our file now has the rw-rw-rw permissions.
Very easy isn't it. I won't do another example, I think people can go off and explore it for themselves.
And if you wanted to do a whole dir of files, then you could use the -R switch as shown previously.
This concludes my quick tutorial. I hope people find it of benefit.