Language
English English Vietnamese (Tiếng Việt) Vietnamese (Tiếng Việt) Chinese (简体中文) Chinese (简体中文) Portuguese (Brazil) (Português do Brasil) Portuguese (Brazil) (Português do Brasil) Spanish (Español) Spanish (Español) Indonesian (Bahasa Indonesia) Indonesian (Bahasa Indonesia)
Decimal to Octal

Decimal to Octal

Your script printed 420 and you wanted 644. Turn a plain mode integer back into the three digits chmod, umask and deployment files speak.

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.

Divide by eight, keep the remainders: 420 gives remainders 4, 4 and 6, read upwards as 644. That is rw-r--r--, the mode most freshly written files end up with.

Where the Plain Integer Comes From

Stat Output in a Script

Masking a mode with the low nine bits leaves an integer, and every print statement afterwards shows it in base-10 unless you ask otherwise.

Modes Crossing an API

JSON has no octal notation, so build systems and storage services pass permissions as ordinary numbers and expect you to know what they mean.

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

1

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.

2

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.

3

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.

Going back to an integer: type a mode into the lower field to see the number a comparison in code would use. Swap hands the value to the octal-first page.

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.

IntegerModePermissionsTypical owner
384600rw-------A private key or credentials file
420644rw-r--r--An ordinary document or config
448700rwx------A personal directory
365555r-xr-xr-xA read-only packaged binary
493755rwxr-xr-xA script or a shared directory
511777rwxrwxrwxWide 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.

0123456789
01234567
0o

Mode Integers Seen in Logs

384 = 600
420 = 644
448 = 700
365 = 555
493 = 755
511 = 777

Decimal (Base-10)

What a language prints when a mode is just an integer, with no notation to say the digits mean permissions.

Octal (Base-8)

The three-digit form a system administrator reads at a glance, one digit per permission group.

Mask the mode with the low nine bits before converting
420 comes back as 644, that is rw-r--r--
Four digits means a setuid, setgid or sticky bit is set
The clipboard copy carries the 0o marker for Python
Want to learn more? Read documentation →
1/5
Start typing to search...
Searching...
No results found
Try searching with different keywords