chmod usage: Which option applies a permission change recursively to all files and all subdirectories under a given directory?

Difficulty: Easy

Correct Answer: -R

Explanation:


Introduction / Context:
Managing file permissions at scale often requires changing modes on an entire directory tree. The chmod utility alters read, write, and execute bits, and offers a recursive option to apply changes to every descendant path in one command.


Given Data / Assumptions:

  • You need to change permissions for a directory and everything beneath it.
  • You are using a standard Linux/UNIX chmod implementation.
  • You want the correct flag that ensures recursion.


Concept / Approach:
The recursive option for chmod is “-R”. Example: chmod -R u+rX,go-rw /project updates permissions for all files and subdirectories of /project. Other letters in chmod denote modes (r, w, x) or symbolic operators (+, -, =), not recursion. Flags like -i or -x in this context are not valid for recursion; -x is typically a mode, not an option.


Step-by-Step Solution:

Identify the need: apply permissions to an entire tree.Use “chmod -R … path” to enable recursion.Verify changes on sample files to ensure the intent matches results.


Verification / Alternative check:
Run “find DIR -type f -exec chmod … {} +” as an alternative to tailor file-only or dir-only changes; compare with chmod -R behavior.


Why Other Options Are Wrong:
-1: not a chmod recursion flag. -i: not standard for recursion. -x: refers to execute bit in modes, not an option. None: incorrect because -R is correct.


Common Pitfalls:
Accidentally removing execute bits from directories (breaking traversal); applying world-writable modes recursively without need; forgetting to preserve special bits when required.


Final Answer:
-R

More Questions from Unix

Discussion & Comments

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