Change Selected Bits Symbolically
Change Selected Bits Symbolically
The teacher's report already has useful permissions, and she wants to add just group read without clearing other bits. Symbolic mode gives you a way to express that limited change. You select a class, an operation and one or more permissions.
Read g+r as 'for the group class, add read.' The symbols +, - and = have different meanings: add, remove and assign. Choosing between them is the main reasoning step, not simply learning another spelling for a numeric mode.
What you’ll learn
- Add, remove or replace permissions for a specified access class.
- Distinguish +, - and = before changing existing bits.
Symbolic mode selects who and how to change bits
Select class
g identifies the file’s group permission class.
gSelect operation
+ adds the requested permission rather than replacing the triplet.
+rResult
Starting from 600, adding group read gives the ordinary mode 640.
rw------- → rw-r-----
Add group read without clearing other permissions
Prepare the example
Use a new folder and an owned empty report. We first set ordinary mode 600 so the group has no bits. The next change adds one group bit, giving you a clear before-and-after result to inspect.
Bash · Linux terminal
touch marks.txt
chmod 600 marks.txt
chmod g+r marks.txt
ls -l marks.txtExpected behavior; machine-dependent details
The mode begins -rw-r-----.chmod 600 marks.txt prepares owner read/write and no group or others bits. chmod g+r marks.txt then adds group read. The resulting ordinary mode is 640, which ls -l displays as the familiar triplets.
Now compare g=r. That assigns the group triplet to read rather than merely adding read, so it removes other ordinary group bits that were present. The current example starts with none, making the result look similar, but the distinction matters on a differently configured file. Select the operator based on what should be preserved.
Choose a class, an operator and the selected bits
Symbolic chmod describes a permission change with letters. It is useful when you want to modify one part of a mode without replacing every permission bit.
What is chmod?
The chmod command is used to change the permissions of files and directories in Linux. Permissions decide who can read, write, or execute a file.
Understanding Symbolic Mode
In symbolic mode, we use letters and symbols to describe permissions:
- u = user (owner)
- g = group
- o = others
- a = all (u+g+o)
Then we use operators:
- + = add permission
- - = remove permission
- = = set exact permission
- r = read
- w = write
- x = execute
Let's Practice!
Step 1: Create a sample file
touch demo.txt
Step 2: Check the current permissions
ls -l demo.txt
-rw-r--r-- 1 user user 0 Jul 2 10:00 demo.txt
This means the owner can read and write, and group/others can only read.
Add execute permission for the user
chmod u+x demo.txt
Check again:
ls -l demo.txt
-rwxr--r-- 1 user user 0 Jul 2 10:00 demo.txt
Now the user has execute permission too.
Remove read permission from others
chmod o-r demo.txt
ls -l demo.txt
-rwxr----- 1 user user 0 Jul 2 10:00 demo.txt
Others can no longer read the file.
Set group permissions to exactly read and execute
chmod g=rx demo.txt
ls -l demo.txt
-rwxr-x--- 1 user user 0 Jul 2 10:00 demo.txt
The group now has only read and execute permissions.
Tip: Use a to affect all
chmod a-w demo.txt
ls -l demo.txt
-r-xr-xr-- 1 user user 0 Jul 2 10:00 demo.txt
This removes write permission from everyone.
Target user, group and other permissions symbolically
chmodin symbolic mode is readable and intuitive- Use
u,g,o,ato choose who you're modifying - Use
+,-,=to set permissions - Use
r,w,xto define permission types
Practice with different combinations and try it out on both files and directories!
Try it, then check the worked answer
Your task: Add group read without requesting group write.
Use a new folder and an owned empty report. We first set ordinary mode 600 so the group has no bits. The next change adds one group bit, giving you a clear before-and-after result to inspect.
Bash · complete example for this question
touch marks.txt
chmod 600 marks.txt
chmod g+r marks.txt
ls -l marks.txtExpected behavior; machine-dependent details
The mode begins -rw-r-----.Worked answer
chmod g+r marks.txt
Use chmod g+r marks.txt for the add operation. g+w asks for write instead. g=r requests assignment, which may clear pre-existing group bits. The requirement describes a limited change, so the preservation behavior is part of the answer.
Check your decision
Adding a bit and replacing a triplet differ
Say the symbolic expression in words before running it: whose bits, which operation, which permission. Adding, removing and replacing are different tasks. Inspect the updated mode afterward, especially when the starting file had other permissions you intended to keep.
Reaching the recap and completing the quizzes are separate milestones.