chmod
Who can read, write and run a file: chmod in letters (u+x) and numbers (755), with a calculator.
>_ Try it: a simulated Linux, right herenothing runs on your computer
Loading the terminal…
Examples
-
chmod +x deploy.sh -
./deploy.sh -
chmod 644 deploy.sh -
chmod u=rwx,go=rx deploy.sh -
chmod 600 deploy.sh -
chmod -R 755 site
How it works
Every file has three sets of permissions: the owner (u), the group (g) and everyone else (o). Each set can read (r), write (w) and execute (x). ls -l shows them as rwxr-xr-x.
Numbers are a shortcut: r = 4, w = 2, x = 1. Add them up for each set: rwx = 7, r-x = 5, so 755. And 644 is rw- r-- r--: the owner writes, everyone reads.
Syntax
chmod [OPTION] MODE FILE...
Options
| Option | What it does |
|---|---|
u g o a | who: user (owner), group, others, all |
+ - = | add, remove, or set exactly |
r w x | read, write, execute |
755 | the same in numbers (owner, group, others) |
-R | a folder and everything inside it |
Good to know
chmod 777gives everyone everything: almost never the fix you want.- A script needs
xto run with./; a folder needsxto be entered withcd.