Skip to content

Files Permissions

image.png

image.png

image.png

image.png

image.png

Bit Position123456789
Permissionrwxrwxrwx
Binary Value421421421

Common Numeric Combos:7 (4+2+1): Full Access (r w x) • 6 (4+2): Read/Write (r w —) • 5 (4+1): Read/Execute (r — x) • 4: Read Only (r — —) • 0: No Access (— — —)

CommandSyntax TypeExample CommandLogical Result / Use Case
chmodNumericchmod 755 fileOwner: Full, Group/Other: Read/Run. Standard for scripts.
Symbolic (+/-)chmod g+w fileAdd write permission to the group only. Leaves others alone.
Symbolic (=)chmod o=rx fileExplicitly set Others to Read/Run. Wipes out any previous w bit.
Recursivechmod -R 700 dir/Advanced: Locks a folder and everything inside to the Owner only. -R means recursive
Verbosechmod -v 644 fileAdvanced: Prints a message explaining the change (e.g., mode of 'file' changed to 0644).
Referencechmod --reference=A BAdvanced: Makes File B have the exact same 9 bits as File A.
chownBasicchown pavan2 fileChanges the primary owner to pavan2.
Combinedchown pavan:devops fileAdvanced: Changes both Owner and Group in one command.
Group Onlychown :prod fileAdvanced: Changes only the group (shorthand for chgrp).
Conditionalchown --from=root pavan fileAdvanced: Only swaps owner if the current owner is root.
Recursivechown -R pavan:devops dir/Advanced: Fixes ownership for a whole project directory tree.
chgrpBasicchgrp devops fileChanges the group to devops. No sudo needed if you are in that group.
Recursivechgrp -R prod dir/Advanced: Mass-updates group for entire directory structures.
Changes Onlychgrp -c devops *Advanced: Only reports if a file actually changed its group (ignores correct ones).
Silentchgrp -f prod fileAdvanced: Suppresses “Permission Denied” errors if you hit a file you don’t own.
Pattern (rwx)Identity of UserAction AttemptedResultDeep Logic
rwx------OwnerRead/Write/RunAllowedYou are the owner; you have full bits.
rwx------Group memberRead/Write/RunDeniedYou aren’t the owner; the group bits are all ---.
---rwx---OwnerReadDeniedThe Owner Trap: You are the owner, but your specific bits are ---. Linux stops here and ignores the group’s rwx.
---rwx---Group memberRead/Write/RunAllowedYou aren’t the owner, but you match the Group which has rwx.
rw-r-----Group memberWriteDeniedYou match the group, but they only have r-- (Read). Write is missing.
-------r-EveryoneReadAllowedNo one owns it or groups it with rights, but the “Others” bit allows everyone to read.
r-xr-xr-xAny UserRun ScriptAllowedEveryone has the x (Execute) bit.
Scenario PatternYour IdentityLogic ResultWhy?
---rwx---OwnerDENIEDYou matched “Owner” first. Your bits are ---. You are blocked.
---rwx---Group MemberGRANTEDYou are not the owner. You matched “Group.” Group bits are rwx.
rw-r--r--OwnerREAD/WRITEYou matched “Owner.” You can Read and Write.
rw-r--r--Group MemberREAD ONLYYou matched “Group.” Group bits only allow r--.
---------Root UserGRANTEDThe Exception: Root (UID 0) bypasses this algorithm entirely.

https://www.youtube.com/watch?v=eWsCbBfxZ04&list=PLbvUFWvKlQnmiDGAW7T_gZNgJN2bmQsFu&index=10