Linux for Developers Course
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)

NumberBinaryPermission Granted
4100Read (r) only
2010Write (w) only
1001Execute (x) only
5101Read + Execute (4 + 1)
6110Read + Write (4 + 2)
7111Read + 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`?

Flash Cards

Question

What does +x do?

Click to reveal answer
Answer

It adds 'Execute' permission, allowing the file to be run as a program.

Question

u+x vs a+x?

Click to reveal answer
Answer

`u+x` gives execute permission ONLY to the User (owner) of the file. `a+x` gives execute permission to All users on the system.