UNIX/Linux file permissions Which single chmod command assigns read-only permission to all three classes (user, group, and others) for a file named 'letter'?
-
Achmod u + r, g + r, o - x letter
-
Bchmod ugo = r letter
-
Cchmod a - rw letter
-
Dchmod go + r letter
-
ENone of the above
Answer
Correct Answer: chmod ugo = r letter
Explanation
Introduction / Context:UNIX/Linux permissions protect files by specifying what actions each class of user can perform: read, write, and execute for user (u), group (g), and others (o). The chmod command modifies these bits either symbolically or numerically, and it is common to grant uniform read-only access to all classes for shared documents.
Given Data / Assumptions:
- Target file name: letter.
- Goal: read-only for user, group, and others.
- Single command preferred, using symbolic mode.
Concept / Approach:Read-only means setting read and clearing write and execute for u, g, and o. Using symbolic mode, chmod ugo=r letter sets exactly the read bit for all classes at once. Alternatives either fail to remove existing write/execute bits or do not set all classes correctly.
Step-by-Step Solution:Desired permissions: r-- r-- r-- (octal 444).Symbolic equivalent: ugo=r.Apply: chmod ugo = r letter.Confirm with ls -l to see -r--r--r-- for the file.
Verification / Alternative check:Octal mode provides a quick check: chmod 444 letter yields the same result as ugo=r. Verifying with ls -l ensures correct application.
Why Other Options Are Wrong:Option A only adds read for u and g and removes execute for o, leaving other bits unchanged.Option C removes read and write for all (a-rw) and leaves execute unchanged; not read-only.Option D adds read for g and o only, leaving user and other bits undefined.
Common Pitfalls:
- Using + instead of =, which can leave unwanted write or execute bits set.
- Forgetting to include all classes (ugo) when uniform permissions are required.
- Confusing octal and symbolic modes.
Final Answer:chmod ugo = r letter