Change file permissions for names starting with 'emp' and ending with 1, 2, or 3 so that the user (owner) gains execute permission: which chmod command is appropriate?
-
Achmod u+x emp[1-3]
-
Bchmod 777 emp*
-
Cchmod u+r ??? emp
-
Dchmod 222 emp?
-
ENone of the above
Answer
Correct Answer: chmod u+x emp[1-3]
Explanation
Introduction / Context:Managing permissions in Unix/Linux often involves applying changes to sets of files selected by shell globs. Understanding chmod symbolic modes and bracket patterns ensures precise, minimal changes to the correct targets without over-permissive settings.
Given Data / Assumptions:
- Target files are named 'emp1', 'emp2', or 'emp3' (i.e., start with 'emp' and end with 1–3).
- Goal: add execute permission for the user (owner) only.
- We prefer symbolic mode for clarity (u+x).
Concept / Approach:
The shell glob emp[1-3] matches exactly the names ending in 1, 2, or 3. The chmod symbolic form u+x adds execute permission to the owner without altering group or others. Combining them gives chmod u+x emp[1-3], which is specific and safe.
Step-by-Step Solution:
Select files by pattern: emp[1-3].Decide permission change: add execute to user = u+x.Run: chmod u+x emp[1-3].Verify with: ls -l emp[1-3].Verification / Alternative check:
Run stat emp1 before and after to confirm mode changes only for the user execute bit. If scripts are in these files, test execution with ./emp1 (assuming proper shebang and path).
Why Other Options Are Wrong:
- chmod 777 emp*: over-permissive, affects many files, not just 1–3, and changes group/others unnecessarily.
- chmod u+r ??? emp: malformed; adds read, not execute; and incorrect glob usage.
- chmod 222 emp?: sets write-only for user/group/others; also matches any single extra character, not just 1–3.
- None of the above: incorrect since the correct command is listed.
Common Pitfalls:
- Using * and modifying too many files.
- Confusing symbolic and octal modes.
Final Answer:
chmod u+x emp[1-3].