![]() |
The permissions or mode of a file or directory can be changed with the chmod command. This can only be done by the owner of the file, or super-user (root).
You cannot change a directory to a file, or a file to directory, with the chmod command.
There are several specifications that chmod accepts. The symbolic mode which uses the letters (ugoa), (+-=), (rwxXstugo). The letters 'ugoa' control which users' access will be changed. The owner (u), other users in the group (g), others not in the group (o), or all users (a). The '+' and '-' operators determine whether the permissions are add or removed, while the '=' operator causes the permissions to be the only ones set for the file.
root@localhost # ls -l thatfile
-rw-r-r- 1 joe joe 0 Mar 30 21:46 thatfile
root@localhost # chmod u+x thatfile
-rwxr-r- 1 joe joe 0 Mar 30 21:46 thatfileThe letters 'rwxXstugo' select the new permissions for the affected users:
read (r)
write (w)
execute (x) or access for directories
execute (X) only if the file is a directory or already has execute permissions for some users
suid (s) set user or group ID on execution, in other words, execute the program as the owner of the file instead of the user that called the program
save program text (t) ``sticky bit'' ignored by Linux on files, on directories only owners of file in that directory can delete it.
user (u) permissions that the user that is owner of the file currently has
group(g) permissions that the files group has for it.
others (o) permissions that others not user or group of the file have for it.
The numeric mode is derived by adding up the bites with values of 4 (r), 2 (w), and 1 (x). Omitted digits are assumed to be leading zeros.
Difficult unless you know binary arithmetic. Starting from left to right, each mode is represented as follows.
root@localhost # ls -l thisfile
-rw-rw-r- 1 joe joe 29 Mar 26 19:23 thisfile
root@localhost # chmod 666 thisfile
-rw-rw-rw- 1 sam sam 29 Mar 26 19:23 thisfileThe octal representations may seem difficult at first. Once you understand the octal representations, you may find them the easiest to use. Here are some of the common one: