Chmod is used to set files permissions (on Linux). It takes a 3-digit code as an argument. Syntax:
chmod [-R] xyz file_or_foldername
where:
* -R is optional and means recursive (changes files in subdirectories too)
* xyz is the 3-digit code (see below)
* file_or_foldername is the file or folder name, but note that you can match several names if using a syntax using partial names, like *stuff* or fi*nam.*
For xyz:
* x is privileges for the owner
* y is privileges for the group (NB: it’s NOT the owner’s group, it’s the group the file belongs to!)
* z is privileges for all other users
x, y and z all work the same way, otherwise: they are a bitflag where:
* 1 = execute (x)
* 2 = write (w)
* 4 = read (r)
This means that to say “read and write” you should use number 6 (=4 + 2). Of course, for giving no permission (no read, write or execute), use 0.
For instance:
chmod 754 helloworld.sh
Will give the following privileges:
* for owner: read, write and execute (4 + 2 + 1)
* for group: read and execute (4 + 1)
* for all others: read (4)
To read the privileges of the files in a folder, use:
ls -l [optionally filename]
This will output stuff using the letter format, like -rwxr-xr– (equivalent to 754: first dash is a d for a directory but a dash otherwise, the 3 following characters are for owner, the 3 after for group, the 3 last for others)
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.