Chmod

chmod (abbreviation of CH angel MOD E) is achievable an Unix order in an environment of the type Unix which makes it possible to change the permissions of access (special or not) on a file.

History

This order appeared for the first time in AT&T UNIX version 1.

Use

The options placed to the order chmod are indicated like this:

chmod options modes files

For a file: chmod G O has - = W X nom_du_fichier

For a repertory (in a recursive way):
chmod - R G O has - = W X nom_du_répertoire

Examples

  • chmod u+rw mon_fichier I give to the owner the rights in writing and reading to the file mon_fichier .
  • chmod - R a+rx mon_dossier I give to all the users the rights in reading and execution to all that the file mon_dossier contains. To note, is optional to it chmod has - R +rx mon_dossier functions just as easily.
  • chmod 755 mon_dossier I give to the owner all the rights, to the members of the group and to the others the rights of reading and access. It is a right used traditionally on the repertories.
  • chmod 644 mon_fichier I give to the owner the rights of modification and reading, to the members of the group and to the others only the rights of reading. It is a right used traditionally on the files.

To know which figure to use, one uses an attribute bases 8 of them (octal): the first figure is intended for the user, the second with the group and the last with tous.
--- - > 0 thus no droit
--X - > 1 only exécution
- W - > 2 only écriture
- wx - > 3 only writing and exécution
R-- - > 4 only lecture
r- X - > 5 only reading and exécution
rw- - > 6 only reading and écriture
rwx - > the 7 all rights (reading, writing and execution)

In fact, it is easy to calculate these figures without having to memorize all these results. Indeed, the first figure corresponds to the user, the second with the group and the third with the others. This should be kept at the head:
4 - > lecture
2-> écriture
1-> exécution


Thus, if one wants to give to a file (or a repertory):
- the owner can read, write and carry out: 4+2+1=7
- the group can read and write: 4+2=6
- the others can only read it: 4

Syntax supplements will be chmod 764 monfichier

Options

chmod has a certain number of options which can modify the result. Some of these options are:
  • -c, --changes: as verbeux (- v) but posts only the changes carried out.

  • --no-preserve-root: do not treat/(the root of the filing system) especially (default option).
  • --preserve-root: failure of the recursive treatment (- R) on/(the root of the filing system).
  • -f, --slient, --quiet: remove the majority of the error messages.
  • -v, --verbose: verbeux mode. Post the list of all the files in the course of modification.
  • -R, --recursive: change the modes of all the files in the sub-directories in a recursive way.
  • --help: post the assistance of the order chmod.
  • --version: post information on the version of chmod.

Modes

For each file given, the permissions apply to the owner of the file (U), to the users in the group of the file (G) or to all the other users (O). To apply the modifications to all in only once, one uses the order (A) for all.

The modes can be specified in two ways, with letters or numbers in octal. For the letters, there exist operators of change like +, a mode of addition, = defines the mode and -, to remove the right of the mode. For the octal one it is necessary to add the numbers for each type of owner.

The permissions are (octal values between brackets):

  • r (4): authorization of reading
  • w (2): authorization of writing
  • x (1): authorization of execution. It should be noted, that the permission of execution also governs the access to a repertory (if the execution is not authorized on a repertory, one cannot make a Chdir (order Cd) on this repertory).

Special modes

There exist two special modes usually used: the sticky bit (T), it to use/group ID bit (S).

Permission to change the rights

A user has the right to make a chmod on a file:
  • if it is root
  • if he is the owner

Others chmod

Function C

chmod

chmod exists in the library standard C. It with the same function as the Unix order.

int chmod (const tank *path, int amode);

Where:

  • path is the name of the file to be modified.
  • amode is the new attribute to be put at the file.
  • In return one to value 0 (successful operation) or -1 (error).

fchmod

int fchmod (int descriptor of the file, mode_t mode) The difference between chmod and fchmod , it is that chmod takes the way of the file as argument (what is readable by an human being, example: /tmp/toto.txt ), whereas fchmod takes the Descripteur of file like argument.

Function Perl

chmod exists in the bookstores Perl to change the permissions of a list of files. The second parameter must be the value OCTAL. The function turns over the number of files there was success.

$cnt = chmod 0755, “fichier1”, “fichier2”; $cnt = chmod 0755, @list;

Function PHP

chmod exists in the library standard. It with the same function as the Unix order and the same parameters as the function C.

cacls and attrib of Microsoft

Under MS-DOS and Windows, the utility attrib makes it possible to change certain attributes (reading, writing, hidden, system) of the files, nonrelated to the owner.

Under Windows NT, cacls is the more complete utility in line of order equivalent to chmod and Chown.

See too

  • Orders UNIX

External bonds

  • Rights of access with the files under Linux
  • the official man and in French of order CHMOD

Random links:César of the best original screenplay or adaptation | Writers of French language, alphabetically Q | Bazouge-of-Chemeré | Karim Saoula | Beaumont (Texas) | Bement,_l'Illinois