Master Linux File Permissions: A Hands‑On Guide to Using chmod
This tutorial explains the Linux chmod command, covering permission basics, how to view permissions with ls‑l, numeric and symbolic modes, recursive changes, reference files, and special cases like applying execute rights only to directories, all with clear examples and command syntax.
Linux’s chmod command changes or assigns permissions for files and directories. Permissions determine who can read, write, or execute a resource and are based on three classes—owner (u), group (g), and others (o)—each with read (r), write (w), and execute (x) bits.
Viewing Permissions
Use ls -l to list files in long format; the leftmost column shows the file type and nine permission bits, grouped in three triples for user, group, and others. A leading ‘-’ indicates a regular file, ‘d’ a directory, and ‘l’ a symbolic link. linuxmi@linuxmi:~/www.linuxmi.com$ ls -l Example output:
-rw-rw-r-- 1 linuxmi linuxmi 1087 Oct 3 20:23 linuxmi.com.cppThe first three characters ( rw-) are the owner’s permissions, the next three ( rw-) the group’s, and the final three ( r--) others’ permissions.
chmod Syntax
$ chmod [options] mode file
Only the root user or a user with sudo privileges can modify permissions.
Example 1 – Numeric (Octal) Mode
Permissions can be set with a three‑digit octal number where read=4, write=2, execute=1. The sum of the desired bits for each class forms the mode.
Read = 4
Write = 2
Execute = 1
For owner=rwx (7), group=rx (5), others=r (4), the mode is 754: chmod 754 filename Common usages:
chmod 744 www.linuxmi.com.txt # owner rwx, group & others r chmod 750 www.linuxmi.com.txt # owner rwx, group rx, others --- chmod 755 linuxmi.txt # owner & group rwx, others r-xExample 2 – Recursive Directory Changes
Apply permissions to a directory and all its contents with -R:
chmod -R 755 /home/linuxmi/linuxExample 3 – Symbolic Mode
Use symbolic notation to modify specific classes: chmod [ugoa][+-=][rwx] file Classes:
u – user (owner)
g – group
o – others
a – all (u,g,o)
Operators:
- removes the specified permissions
+ adds the specified permissions
= sets exactly the specified permissions, clearing others
Examples:
chmod o=r file.txt # give others read only chmod ug+x linuxmi.txt # add execute to owner and group chmod u=rwx,g=rw,o=r file # owner rwx, group rw, others r chmod o= file.txt # remove all permissions from othersExample 4 – Reference File
Copy permissions from a reference file:
chmod --reference=ref_file target_fileExample 5 – Apply Execute Only to Directories
Use capital X to set execute bits only on directories:
chmod a+X *Summary
The article covered the purpose and syntax of chmod, demonstrated how to view permissions, explained numeric and symbolic modes, showed recursive changes, reference‑file copying, and the special a+X usage for directories, providing a comprehensive guide for managing Linux file permissions.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
