Every file and directory says who may do what with it. ls -l shows it in the first column:
-rw-r--r-- 1 learner learner 120 Jan 12 09:00 hello.sh
The first character is the type (- file, d directory). The next nine are three groups of three:
| Characters | Who | Here |
|---|---|---|
rw- | user: the owner (learner) | read and write |
r-- | group: the owner's group | read only |
r-- | others: everyone else | read only |
In each group, r is read (look inside), w is write (change it) and x is execute (run it as a program; for a directory, go into it). A - means that permission is missing.
Running a script
A script is a text file of commands. To run one, you give its path, ./ meaning "in this directory":
cd scripts./hello.shThat fails with Permission denied: nobody has x yet.
chmod changes permissions
chmod (change mode) takes who (u, g, o or a for all), + to add or - to remove, and the permissions:
chmod u+x hello.shls -l hello.shNow the owner's group reads rwx and ./hello.sh runs. Other examples: chmod go-r notes.txt stops the group and others reading, chmod +x adds execute for everyone. Only a file's owner can change its permissions.