Bash Change Permissions
Every file and directory in Linux carries a permission set that controls who can read, write, or execute it, and chmod is the command used to change those permissions.
How Linux Permissions Work
Every file has three permission groups: the owner (the user who created or owns the file), the group (a set of users sharing access), and others (everyone else on the system). Each group can independently be granted read (r), write (w), and execute (x) permissions.
Viewing Permissions
$ ls -l notes.txt
-rw-r--r-- 1 alice staff 2048 Jul 16 09:12 notes.txtReading the ten-character string from ls -l: the first character is the file type (- for a regular file, d for a directory), followed by three groups of three characters for owner, group, and others, in that order. In the example above, the owner has read and write, while the group and others only have read.
Symbolic Notation
Symbolic notation lets you add, remove, or set permissions using letters. Use u for owner, g for group, o for others, and a for all three, combined with +, -, or = and a permission letter: r, w, or x.
Symbolic chmod
$ chmod u+x deploy.sh
$ ls -l deploy.sh
-rwxr--r-- 1 alice staff 512 Jul 16 09:20 deploy.shOctal Notation
Octal notation represents each permission triad as a single digit from 0 to 7. Read is worth 4, write is worth 2, and execute is worth 1; add the values together for the permissions you want each group to have. A chmod command then takes three digits, one each for owner, group, and others.
Octal chmod
$ chmod 755 deploy.sh
$ ls -l deploy.sh
-rwxr-xr-x 1 alice staff 512 Jul 16 09:20 deploy.sh- chmod 644 file — owner reads and writes, everyone else reads only (typical for regular files)
- chmod 755 script.sh — owner has full control, everyone else can read and execute (typical for scripts and directories)
- chmod 700 secret.key — only the owner can do anything with the file
- chmod -R 755 folder/ — apply recursively to every file and subdirectory inside folder