Bash File Permissions
File permissions decide who may read (r), write (w) and execute (x) a file. There are three sets: the owner, the group, and everyone else.
They are written as letters, like rw-r--r--, or as numbers where read is 4, write is 2 and execute is 1, so rwx is 7 and r-x is 5. Change them with chmod.
See the permissions of a new file
The owner can read and write, everyone else can only read:
touch notes.txt
stat -c '%A %n' notes.txt
-rw-r--r-- notes.txt
Set permissions with a number
755 gives the owner rwx and everyone else r-x. Like most commands, chmod prints nothing when it works:
chmod 755 script.sh
Common Numbers
| Number | Letters | Meaning |
|---|---|---|
| 755 | rwxr-xr-x | Owner can do everything, others can read and run |
| 644 | rw-r--r-- | Owner can read and write, others can read |
| 600 | rw------- | Only the owner can read and write |