chmod octal to symbolic
A free medium coding practice problem from sysadmin. Solve it in JavaScript, TypeScript or Python and check your solution against fresh hidden tests — edge cases and random inputs — as often as you like.
- Difficulty
- Medium
- Type
- Function
- Topic
- Sysadmin
- Languages
- JavaScript, TypeScript or Python
Problem
Convert a Unix permission mode in octal to the 9-character symbolic form ls -l shows (without the file-type character). mode is a string of 3 or 4 octal digits. The last three digits are user, group and other; each digit's bits are read 4 → r, 2 → w, 1 → x, missing bits shown as -.
With 4 digits, the first is the special digit: 4 = setuid, 2 = setgid, 1 = sticky (they can combine). Setuid replaces the USER execute character with s if execute is set, else S; setgid does the same on the GROUP execute character; sticky replaces the OTHER execute character with t if execute is set, else T.
Function signature
// JavaScript
function modeToSymbolic(mode)
// TypeScript
function modeToSymbolic(mode: any): any
// Python
def mode_to_symbolic(mode):Examples
modeToSymbolic("755")→"rwxr-xr-x"modeToSymbolic("0644")→"rw-r--r--"modeToSymbolic("4755")→"rwsr-xr-x"
How checking works
Run your code against the examples above, then submit a check: it runs on the server against hidden tests built fresh each time, including edge cases and random inputs. Practice is untimed and never affects a verified score; when you are ready, take a graded coding challenge to earn a badge.