A Capital S in ls -l Means Your setuid Bit Is Doing Nothing
chmod 4655 shows -rwSr-xr-x. The capital S means setuid is set but inert because the owner lacks execute. How S/T case works, plus symbolic modes like u+x,go-w.
Run chmod 4655 file, then ls -l. You get -rwSr-xr-x. That capital S is not a typo and not the same as the lowercase s in -rwsr-xr-x you get from 4755. The kernel writes a capital letter to tell you something specific: the setuid bit is set, but the owner has no execute bit for it to attach to, so the bit does nothing. Paste 4655 into most online chmod calculators and they print rwsr-xr-x — lowercase, no warning — quietly lying about a permission that has zero effect at runtime.
The Capital Letter Most Calculators Render Wrong
Three special bits live above the usual nine: setuid (4000), setgid (2000), and sticky (1000). In ls -l output they don't get their own column — they overload the execute position of owner, group, and other respectively. Which means a single character has to encode two facts: is the special bit set and is the execute bit also set. Unix solves this with case:
| Octal | Symbolic | What the case means |
|---|---|---|
4755 | rwsr-xr-x | setuid set, owner has execute → lowercase s (active) |
4655 | rwSr-xr-x | setuid set, owner lacks execute → capital S (no effect) |
2755 | rwxr-sr-x | setgid set, group has execute → lowercase s |
2745 | rwxr-Sr-x | setgid set, group lacks execute → capital S |
1777 | rwxrwxrwt | sticky set, other has execute → lowercase t (e.g. /tmp) |
1666 | rw-rw-rwT | sticky set, other lacks execute → capital T (no effect) |
The rule in one sentence: uppercase = the special bit is set but the matching execute bit is missing, so the special bit is inert. A calculator that always prints lowercase tells you 4655 is a working setuid binary. It isn't. The whole render is three calls to one helper:
function execChar(exec, special, lower, upper) {
if (special) {
return exec ? lower : upper; // s/t when active, S/T when inert
}
return exec ? "x" : "-";
}
// owner: execChar(mode & 0o100, mode & 0o4000, "s", "S")
// group: execChar(mode & 0o010, mode & 0o2000, "s", "S")
// other: execChar(mode & 0o001, mode & 0o1000, "t", "T")
And because a capital letter is a footgun in production — you think you set setuid and you didn't — the tool raises an explicit warning whenever it sees one:
if (mode & 0o4000 && !(mode & 0o100)) warn("S"); // setuid, no owner exec
if (mode & 0o2000 && !(mode & 0o010)) warn("S"); // setgid, no group exec
if (mode & 0o1000 && !(mode & 0o001)) warn("T"); // sticky, no other exec
Parsing u+x,go-w — the Syntax Almost Nobody Implements
The other half of chmod is symbolic mode: chmod u+x file, chmod go-w file, chmod u=rwx,go=rx file. It's the form people actually type at a shell, and it's the form online calculators almost universally refuse to parse. They give you a checkbox grid and an octal box; type go-w and nothing happens.
The POSIX grammar is small enough to fit in one regex per clause: clause = [ugoa]*[+-=][rwxXst]*, clauses joined by commas.
const CLAUSE_RE = /^([ugoa]*)([+\-=])([rwxXst]*)$/;
// "go-w" → who="go", op="-", perms="w"
// "u=rwx" → who="u", op="=", perms="rwx"
The operators differ in one important way. + and - set and clear the named bits. = first clears every rwx bit (and special bit) for that class, then sets only what you listed — that's why u=rwx,go=rx applied to 644 lands on exactly 755, not 755 OR-ed with leftovers:
op === "+" ? mode | add | special
: op === "-" ? mode & ~(add | special)
: (mode & ~clearMask) | add | special; // "=" wipes the class first
One genuine simplification: a browser has no filesystem, so there's no umask to consult and no way to know if a target is a directory. The tool applies every clause to all classes when none is named (so a bare +x means a+x), and treats X (conditional execute) as "add execute only if some execute bit is already set in the current mode." Both choices are noted in the tool itself, because the alternative — pretending to know your umask — would be worse.
The parseInt("785", 8) Trap
Validating an octal string looks trivial until you reach for parseInt. JavaScript's parseInt does not reject bad digits — it stops at the first one and returns whatever it parsed so far:
parseInt("785", 8) // → 7 (stops at the 8, no error thrown)
parseInt("855", 8) // → NaN (8 is invalid immediately) → NaN & 0o7777 = 0
parseInt("644", 8) // → 420 (correct: 0o644)
So a user who fat-fingers 785 gets mode 7 — a perfectly valid-looking ------rwx — with no indication anything went wrong. 855 collapses to 0. Neither throws. The fix is to validate the string before it ever reaches parseInt:
if (!/^[0-7]{1,4}$/.test(input)) {
return { ok: false, error: "octal" };
}
Everything downstream is a 12-bit integer (special nibble + owner/group/other), so the rest of the tool is pure bit math: O(1), no allocation, sub-microsecond. There's no debounce, no Web Worker, no cache — the entire input space is 4,096 modes and a single keystroke recomputes six short strings. It's all pure functions with no Date, no Math.random, no window, so it renders identically on the server and the client and never hydration-mismatches.
Try It
Open the Chmod Calculator.
- Type
4655in the octal box. The symbolic output readsrwSr-xr-x— capitalS— and a warning appears explaining the setuid bit has no effect. Change it to4755and theSdrops to lowercases, warning gone. - Type
1666. You getrw-rw-rwT, capitalT, sticky-bit-is-inert warning.1777gives yourwxrwxrwt(lowercase) — the real/tmppermission. - In the operation box, with the mode at
644, enteru=rwx,go=rx. Everything snaps to755/rwxr-xr-x/chmod 755 file. - Enter
666then applygo-w— you land on644, the canonical "make this file not world-writable" move, computed without you doing the bit arithmetic in your head.