![]() |
![]() |
| Linux news | Newbie's Linux manual | Linux links | Link us | ||
| The Linux columns | Book reviews | ||
| DistroWatch + TuxReports | November 2, 2002 | |
Contents | Previous | Next | Download
Every user belongs to atleast one group, their login group - given the same name as their user account.
Every file belongs to an owner and group. Usually the user that created the file and that user's login group. To display the owner and group a file belongs to, enter:
ls -l
...and examine the third (owner) and fourth (group) columns:
-rw-rw-r-- 1 john john 10760 Nov 20 16:50 report.txt
groups
Display groups you belong to.
groups john
Display groups john belongs to.
chgrp john report.txt
Change group of file report.txt, to john.
chgrp -R john .
Change group of all files and subdirectories (i.e. -R for recursively) in the current (.) directory, to john.
chown john report.txt
Change owner of file report.txt, to john.
chown -R john .
Change owner of all files and subdirectories (i.e. -R for recursively) in the current (.) directory, to john.
chown -R john:john .
Change owner and group (owner:group) of all files and subdirectories (i.e. -R for recursively) in the current (.) directory, to john.
Entering ls -l will display in the first column, the permissions for each file and directory, in the current directory.
For example:
-rw-rw-r-- 1 john john 10760 Nov 20 16:50 report.txt
Here's how it breaks down:
| Type | Owner | Group | Other |
| - | rw- | rw- | r-- |
| Character | Description |
| - | Normal file. |
| d | Directory. |
| l | Symbolic link. |
The owner, group, and other sections, each have three entries: r (read); w (write); x (execute)
An r, w, or x, means that permission is given, a hypen (-) means it isn't. For example:
-rw-rw-r--
...indicates a normal file, with read/write but no execute permissions given to the owner and group, and all other users just have read permission.
| Example | Description |
| chmod +r report.txt | Give read permission to all. |
| chmod -r report.txt | Remove read permission from all. |
| chmod =r report.txt | Give nothing but read permission to all. |
| chmod +w report.txt | Give write permission to owner and group. |
| chmod -w report.txt | Remove write permission from owner and group. |
| chmod =w report.txt | Give nothing but write permission to owner and group. |
| chmod +x report.txt | Give execute permission to all. |
| chmod -x report.txt | Remove execute permission from all. |
| chmod =x report.txt | Give nothing but execute permission to all. |
In front of any of the above you can add:
| Example | Short for |
| u | user |
| g | group |
| o | other |
| a | all (same as: ugo) |
chmod a+rw report.txt
Give all users read and write permission (what's called making the file report.txt, world readable and world writable).
chmod go-w report.txt
Remove write permission (-w) from report.txt for group and others (go), allowing only the owner modify the file (as long as they had write permission beforehand).
chmod go= report.txt
Remove all permissions for group and others (go), making the file report.txt private to owner.
Permissions can also be set in octal (base 8), where read permission is a four, write is two, and execute is one. These you add up separately for user, group and other for between 000 (---------) and 777 (rwxrwxrwx), like so:

Contents | Previous | Next | Download
| About us | |
| Latest stable kernel: 2.4.19 | Latest development kernel: 2.5.44 Copyright © 1998-2002 Linuxdot.org. Linux ® is a registered trademark of Linus Torvalds. |
|