$_ CLI In Depth
Learning progress 0%
lesson permissions users sudo

chmod: Symbolic and Octal Modes

5 min read Module 5: Users, Permissions & sudo Updated Dec 5, 2026
Cheat Sheet
0:00 / 3:12

Who may change a mode

Only the owner of a file, or root, may change its permission bits. The kernel checks the UID of the process against the owner of the file before it allows a change. This rule is separate from the read, write, and execute bits themselves. A file can be read-only for you and still be yours, and you can change its mode because you own it.

That is why the labs in this module work on files that you own. You can change the mode of a file that you own, but you cannot change a file that belongs to another account. The same restriction applies to the owner and the group, which the next unit covers.

Symbolic mode

A symbolic mode has three parts: who, the operation, and the permission. The who part is a combination of u for the owner, g for the group, o for other, and a for all three. If you leave it out, chmod acts on all three classes, but only the bits that are allowed by the umask, which the umask unit explains. The operation is + to add bits, - to remove them, or = to set them exactly. The permission part is any of r, w, x, and in later units s and t.

BASH3 lines
touch tool.sh
chmod u+x tool.sh
stat -c "%A %a %n" tool.sh

The first command creates the file, which starts with a default mode. The second adds execute for the owner only. The third prints the result, which shows the owner triplet with an x and leaves the group and other triplets alone. This is the safest kind of change, because it names exactly the class you mean.

The equals operator is different. The command chmod u=rw tool.sh sets the owner triplet to exactly read and write, and it clears execute if it was present. Use equals when you want to know the final state of a class, and use plus or minus when you want to change one bit and leave the rest alone.

Octal mode

An octal mode sets all nine bits at once. The three digits are the owner, the group, and other, in that order, and each digit is the sum of read as 4, write as 2, and execute as 1. The command chmod 640 notes.txt sets the owner to read and write, the group to read, and other to nothing. The command chmod 755 run.sh gives the owner full access and everyone else read and execute.

DigitOwnerGroupOther
7rwxrwxrwx
6rw-rw-rw-
5r-xr-xr-x
4r--r--r--
0---------

The table shows the digits that appear most often. An octal mode is a complete statement, so it is the right choice when a script must produce a known result, and it is the wrong choice when you only want to add one bit to a file whose other bits you have not checked.

Recursive changes are dangerous

The -R option applies the change to a directory and everything inside it. It is convenient, but it is easy to set execute bits on ordinary data files, or to remove the owner write bit from a directory that you need to change later. Before you use -R, list the files with find and check which ones the change would touch. A capital X in a symbolic mode is useful here, because it adds execute only to directories and to files that already have some execute bit.

Warning

Never set mode 777 on a file to make a permission error go away. That gives every account on the system write access, which is usually the real problem. Find the class that is missing the bit, and add only that bit.

Choosing a notation

Pick the notation that matches the question you are answering. If you are asking what a file should look like after the change, octal is clearer, because the whole mode is visible in three digits. If you are asking how to add one capability to a file you already have, symbolic is clearer, because the command names only the bit you want. Scripts usually prefer octal, because a script that says 644 produces the same result on every machine, while a script that says g-w depends on the current mode.

A common compromise is to use symbolic mode in an interactive shell and octal mode in a script that is meant to run again. An interactive change is quick to check by eye. A repeated script must set a known state, and an octal value is that state written down.

Symbolic modes can combine several operations in one command. The expression u+x,go-w adds execute for the owner and removes write for the group and other classes. Commas separate the clauses, and each clause is applied to the result of the one before it. Read the expression from left to right, the same way the kernel and the chmod program apply it.

The chmod command also accepts a reference file. The option --reference=FILE copies the mode of another file, which is useful when two files should match. That option is less common, but it removes the need to retype octal digits by hand, and it avoids the arithmetic mistakes that appear when a mode is written from memory.

Hands-on: change modes on your own files

Create a file, then change it with a symbolic mode, and check the result with stat -c %a. Repeat the work with an octal mode and compare the two. The labs for this unit ask you to add execute for the owner, to set a file to 640 with octal, and to remove write for the group and other classes with a symbolic command. Each check confirms the final mode, so you can see whether the notation did what you intended.

Reading, changing and defaulting permission bits

Visualizer

A mode is nine bits in three triplets. Decode one, change it with chmod, then see how umask produces the defaults for new files and directories.

1 / 4
-type
rowner
w
-
rgroup
-
-
-other
-
-
mode
-rw-r-----

The first character is the file type: - regular file, d directory, l symlink. The next nine are three triplets: owner, group and other, each with r, w and x.

f="$(mktemp -d /tmp/perm.XXXX)/p.txt"; touch "$f"; chmod 640 "$f"; stat -c "%a %A %n" "$f"
Terminal lab · 3 steps · real Linux in your browser

chmod: Symbolic and Octal Modes

Change the mode of your own files with a symbolic expression and with an octal value, then check each result with stat.

01
Add execute for the owner
The file /workspace/chm/tool.sh starts with mode 600. Use a symbolic mode to add execute for the owner only. Do not change the group or other bits.
Show hint for step 1
The owner class is u, and the operation to add a bit is +.
02
Set an exact mode with octal
The file /workspace/chm/data.txt starts with mode 644. Use an octal mode to set it to 640, which is rw-r----- in symbolic form.
Show hint for step 2
The owner digit is 6, the group digit is 4, and the other digit is 0.
03
Remove write from group and other
The file /workspace/chm/shared.txt starts with mode 666. Use one symbolic command to remove write from the group and other classes. The owner write bit must stay.
Show hint for step 3
Use the go class with the minus operator and the w permission.
Check yourself Question 1 of 4
Concept Check Owner execute only recall

Which command adds execute permission for the owner only?

Recap & Key Takeaways

A symbolic mode names who, the operation, and the permission, such as u+x, go-w, or u=rw.
An octal mode sets all nine bits at once, with each digit equal to the sum of 4 for read, 2 for write, and 1 for execute.
Use plus or minus to change one bit and leave the rest, and use equals or octal when you need the exact final state.
Check recursive changes with find first, and never use mode 777 to fix a permission error.

Primary Sources & Further Reading

Was this lesson helpful? Spot an issue or have a suggestion? Let us know on GitHub.
Report an issue