UNIX file permissions: Which chmod command sets read-only permission for all categories (user, group, and others) on a file named note, removing any write or execute rights?

Difficulty: Easy

Correct Answer: chmod ugo=r note

Explanation:


Introduction / Context:
The chmod command adjusts read (r), write (w), and execute (x) permissions for the owner (u), group (g), and others (o). A common requirement is to make a file readable by everyone while disallowing modifications and execution. Understanding symbolic modes helps you express that concisely and safely.


Given Data / Assumptions:

  • Target file is named note.
  • Desired permission: read-only for user, group, and others.
  • Any previously set write/execute bits should be cleared.


Concept / Approach:
Symbolic mode ugo=r sets the permissions for all three classes to exactly read-only. The equals sign (=) assigns the specified set and clears all other bits. This guarantees there is no lingering execute or write access for any class. Using additive modes (+ or -) can be ambiguous if you do not also remove unwanted bits.


Step-by-Step Solution:

Run: chmod ugo=r noteConfirmation: ls -l note should show -r--r--r-- (assuming a regular file and no special bits).Optionally, verify with stat note to view octal mode (444).


Verification / Alternative check:
Compare with chmod 444 note which is the octal equivalent of read-only for all. Both approaches yield the same result.


Why Other Options Are Wrong:
chmod go+r note: adds read for group/others but does not restrict user or clear execute/write that may exist. chmod a-rw: removes read and write for all, not read-only. chmod u+r,g+r,o-x note: adds some permissions and removes only others’ execute; it does not ensure a universal read-only state.


Common Pitfalls:
Using +r without removing w/x; forgetting that execute is needed for directories to traverse; applying read-only to scripts that still need execute permission to run.


Final Answer:
chmod ugo=r note

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion