How do file permissions and chmod work?
Assesses fundamental understanding of Shell & Bash conventions, runtime behavior, and memory/performance considerations.
Hiring managers look for precision, avoidance of ambiguous jargon, and ability to explain trade-offs under real production conditions.
Every file has permissions for owner, group and others, each with read (4), write (2) and execute (1). chmod changes them in symbolic or octal form.
chmod 644 notes.txt # rw- r-- r--
chmod 755 script.sh # rwx r-x r-x
chmod u+x script.sh # add execute for the owner
chmod g-w file # remove write for the group
Directories need execute permission to enter or traverse them, and read permission to list names. Special bits include setuid, setgid and the sticky bit, as in 1777 on /tmp, which lets only the owner delete their own files.
chown user:group file changes ownership, and umask controls default permissions for new files. A common umask of 022 yields 644 files and 755 directories.
A script must be readable by the interpreter and executable, or you invoke it as bash script.sh. Follow least privilege and avoid 777.
Candidate Response Strategy & Interview Tips
- Start with a concise one-sentence summary: Deliver a direct, confident answer first before expanding into nuances.
- Demonstrate real-world trade-offs: Discuss where this approach excels and when you would avoid it in production systems.
- Discuss complexity & edge cases: Proactively explain time/space complexity or boundary conditions (null values, scale limits).
- Prepare for interviewer follow-ups: Technical hiring panels frequently probe deeper into concurrency, backward compatibility, or alternative libraries.