Linux for Developers
/Intermediate
chmod
Definition
Change Mode. The command used to change the read, write, and execute permissions of a file or directory.
Explain Like I'm New
Giving or taking away the keys to a file. You can say 'Only I am allowed to edit this file, but anyone can read it'.
Real World Example
You write a Bash script `deploy.sh`. By default, Linux won't let you run it. You type `chmod +x deploy.sh` to add 'execute' permission, allowing the script to run.
Common Use Cases
- •Making scripts executable
- •Securing sensitive files
Numeric Permissions Breakdown (755)
| Number | Binary | Permission Granted |
|---|---|---|
| 4 | 100 | Read (r) only |
| 2 | 010 | Write (w) only |
| 1 | 001 | Execute (x) only |
| 5 | 101 | Read + Execute (4 + 1) |
| 6 | 110 | Read + Write (4 + 2) |
| 7 | 111 | Read + Write + Execute (4 + 2 + 1) |
Interview Questions
basic
- What does `chmod +x` do to a file?
intermediate
- What is the difference between `chmod u+x` and `chmod a+x`?