Linux is an operating system with a robust permissions model, allowing for
fine-grained control over who can access and modify files and directories. One
of the cornerstone utilities to manage these permissions is
chmod, short for "
change mode." This article aims to provide a detailed explanation of the
command, starting with its syntax, followed by its various options and examples.
The basic syntax of
chmod [OPTION]... MODE[,MODE]... FILE...
OPTION: Specifies optional flags.
MODE: Represents the new permissions.
FILE: Specifies the file(s) or directories to change.
chmod Options Table
Here is a table of options that
|Recursively changes files and directories.
|Outputs a diagnostic for every file processed.
|Like verbose, but reports only when a change is made.
|Suppresses most error messages.
|Sets permissions to be the same as the referenced file, instead of specifying MODE.
Numeric and Symbolic Modes
chmod supports both numeric and symbolic modes:
- Numeric Modes: Represent permissions with numbers (4 for read, 2 for write, 1 for execute).
- Symbolic Modes: Use characters to represent permissions (
Changing Permissions Using Symbolic (rwx) Modes
While octal numbers provide a quick and compact way to change file
chmod also allows you to set permissions using symbolic
rwx). This can be more intuitive, especially when you want to modify
the permissions without affecting the others.
The symbolic mode is composed of three elements:
- Who: Specifies for whom to set the permissions. It could be the
u), the group (
g), others (
o), or all (
- Operator: Indicates what operation to perform. It can be:
+to add permissions
-to remove permissions
=to set specific permissions
- Permissions: Specifies which permissions to set (
chmod Symbolic Attributes Table
When you're using the symbolic notation to set file permissions with
various attributes come into play. These can be classified into three
categories: the target users, the operation, and the permission types. Below is
a comprehensive table explaining each attribute.
|Owner (User who owns the file)
|Group (Users who are members of the file's group)
|Others (Users who are neither the owner nor members of the group)
|All (Owner, Group, and Others - same as
|Add the specified permissions to the existing permissions
|Remove the specified permissions from the existing permissions
|Set exact permissions, replacing the existing permissions
|Read (Permission to read the file)
|Write (Permission to write or edit the file)
|Execute (Permission to execute the file, or traverse the directory)
How to Read the Table
Target Users: Who will be affected by this operation. For example, if you choose
chmodcommand will only affect the owner of the file.
Operations: What kind of change you want to make. For example, using
+will add the permissions you specify, while
-will remove them.
Permissions: The actual permissions you want to set, remove, or modify. For example,
rgives read permission,
wgives write permission, and
xgives execute permission.
By combining symbols from these three categories, you can form powerful
commands that precisely define file permissions. For instance,
u+rwx means "
add read, write, and execute permissions for the owner," while
o-rwx means "
remove read, write, and execute permissions from others."
Examples of Using Symbolic Modes
1. Basic File Permissions:
Assuming you have a file named
Give read, write, and execute permissions to the owner:
chmod u+rwx example.txt
Give only read and execute permissions to the group:
chmod g=rx example.txt
Give only read permissions to others:
chmod o=r example.txt
2. Combining Multiple Changes in One Command:
You can also combine multiple permission changes in a single
chmod u=rwx,g=rx,o=r example.txt
This does the same as all the individual commands from example 1, but in a single command.
3. Adding and Removing Specific Permissions:
Add write permissions for the group:
chmod g+w example.txt
Remove execute permissions for others:
chmod o-x example.txt
a for All:
You can use the
a attribute to specify a permission change that affects all
categories (owner, group, others):
chmod a+r example.txt
This will add read permissions for everyone.
5. Removing and Adding Multiple Permissions:
You can remove from one category while adding to another in a single command:
chmod g-w,o+r example.txt
This command will remove write permissions from the group and add read permissions to others.
By mastering the use of the symbolic mode in
chmod, you gain a powerful tool
for fine-tuned control over file and directory permissions in Linux.
chmod command is one of the most essential Linux commands for managing
file and directory permissions. Through numeric and symbolic modes, as well as
various options, you can tailor permissions precisely to your needs.
Understanding how to use
chmod effectively will significantly improve your
capability to manage security on a Linux system.
What Can You Do Next 🙏😊
If you liked the article, consider subscribing to Cloudaffle, my YouTube Channel, where I keep posting in-depth tutorials and all edutainment stuff for software developers.