The Decimal Number Your Script Prints for a File Mode
Ask Python for a file's permissions and it answers 420. Log the mode from a Node script, read it out of an audit table, or pull it from an API response, and you get a plain integer where you expected 644. Nothing is broken: the language printed the same value in base-10. Convert it here and the familiar mode comes back.
rw-r--r--, the mode most freshly written files end up with.Where the Plain Integer Comes From
Stat Output in a Script
Modes Crossing an API
The reverse trip matters as much: a mode you decided on as three octal digits has to be converted before it can be compared with the integer a script already holds.
Getting a chmod Argument out of a Mode Integer
Paste the integer your tool printed
Use the value after the permission bits have been isolated. A raw st_mode also carries file-type bits, which would push the answer well past three digits.
Check the digit count
Three digits is a normal mode. Four means a special bit is set, and anything longer says the file-type bits are still attached.
Paste it where it belongs
The copy button delivers 0o644, ready for a Python or JavaScript literal. Drop the marker for a shell command and keep the digits alone.
File Modes Your Script Prints as Decimal
These six integers cover almost everything a deployment script or an audit report will show you. Recognising them on sight saves a conversion most of the time.
| Integer | Mode | Permissions | Typical owner |
|---|---|---|---|
| 384 | 600 | rw------- | A private key or credentials file |
| 420 | 644 | rw-r--r-- | An ordinary document or config |
| 448 | 700 | rwx------ | A personal directory |
| 365 | 555 | r-xr-xr-x | A read-only packaged binary |
| 493 | 755 | rwxr-xr-x | A script or a shared directory |
| 511 | 777 | rwxrwxrwx | Wide open, almost always a mistake |
Only Digits Survive the Paste
Copying a number out of a log brings brackets and commas with it; the field keeps the digits and discards everything else.
Clipboard Ready for Python
The octal field copies with the 0o marker, which is exactly what os.chmod and modern JavaScript expect to see.
Attach the Working to a Ticket
A ?v= parameter in the link opens the conversion already done, so a reviewer sees the same numbers you did.
Questions About Modes and umask
Why does my script report 33188 instead of a mode?
That is the whole st_mode field, permission bits plus file-type bits. Mask it with the low nine bits first — in Python, mode & 0o777 — and you are left with 420, which converts cleanly.
My umask shows as 18. What does that mean?
Converted it is 022, the default on most systems: new files lose group and other write access. A umask lists what gets removed, not what gets granted.
What integer stands for the setuid bit?
2048 on its own, which converts to 4000. Add it to the permission value: 2048 plus 493 is 2541, and that comes back as 4755.
Is a leading zero needed in the answer?
The command line does not require it, but configuration languages do. YAML in particular reads an unquoted 644 as decimal, so write "0644" in quotes and the intent stays clear.
Why does the result never contain an 8 or a 9?
Base-8 only has the digits 0 to 7. Reaching eight rolls the count into the next column, which is exactly why three permission switches fit in one digit with nothing left over.
No comments yet. Be the first to comment!