Chmod Calculator: Octal and Symbolic Unix Permissions
By FindMySum · Last reviewed
A chmod calculator converts Unix file permissions between the two ways they are written: an octal number such as 755 and the symbolic string such as rwxr-xr-x that ls -l prints. Type either form, or tick the boxes, and it gives the other, the matching chmod commands and what each part means. It also shows the modes a umask leaves on new files and directories.
Three classes, three permissions
Every file on Linux, macOS and other Unix-like systems has an owner and a group. Its mode says what three classes of user may do:
- Owner (u): the user who owns the file.
- Group (g): members of the file's group.
- Others (o): everyone else.
For each class there are three permissions. Read (r) lets you read a file or list a directory. Write (w) lets you change a file, or create and delete names in a directory. Execute (x) lets you run a file as a program, or open a directory and reach the files in it.
From letters to digits
Each permission has a value: read 4, write 2, execute 1. Add the values a class has and you get one octal digit from 0 to 7:
| Digit | Letters | Meaning |
|---|---|---|
| 7 | rwx | read, write, execute |
| 6 | rw- | read, write |
| 5 | r-x | read, execute |
| 4 | r-- | read only |
| 0 | --- | nothing |
Write the digits in the order owner, group, others. The default in the calculator is 755: the owner has 7 (rwx), and the group and others have 5 (r-x). ls -l shows a file with that mode as -rwxr-xr-x, where the first character is the type: - for a regular file, d for a directory.
To go the other way, split the nine letters into three groups and add the values. rw-r----- is 4 + 2, then 4, then nothing: 640, a common mode for files that a group of service accounts may read but nobody else.
The special bits
An optional fourth digit goes in front of the other three:
- Setuid (4000). A program runs with its owner's rights instead of the rights of the user who started it.
passwduses it to update the password file.ls -lshowssin the owner's execute position. - Setgid (2000). A program runs with the file's group; on a directory, new files inherit the directory's group instead of the creator's main group, which keeps shared project folders consistent. Shown as
sin the group's execute position. - Sticky bit (1000). On a directory, only a file's owner (or the directory's owner, or root) may delete or rename it, even if others can write to the directory.
/tmpis 1777:drwxrwxrwt.
A capital S or T means the special bit is set but the execute bit under it is not. On a regular file that usually signals a mistake, and the calculator flags it.
Two ways to write the command
The calculator gives two chmod commands for the same mode. The octal one, chmod 755 filename, replaces the whole mode in one go. The symbolic one, chmod u=rwx,g=rx,o=rx filename, sets each class with =. Both leave the file in exactly the same state. Symbolic mode also has + and - to add or remove single permissions, such as chmod g+w to let the group write. Those depend on the file's current mode, so the calculator doesn't convert them.
umask: the starting point for new files
Programs normally ask for mode 666 when they create a file and 777 when they create a directory. The umask removes bits from that request. With the usual umask 022, the write bit for group and others is removed, so new files get 644 and directories 755. A umask of 002, common on systems that give every user their own group, gives 664 and 775. A strict 077 gives 600 and 700: only you can see what you create. The umask only takes bits away; it never adds execute to a file.
Choosing permissions
Some modes that come up again and again:
- 644 for ordinary files and 755 for programs and directories that others need to read.
- 600 for private files such as SSH keys and 700 for private directories such as
~/.ssh. - 640 / 750 when a service's group needs read access and others need none.
- 2775 for a shared team directory, so new files keep the team's group.
- 1777 for a shared scratch directory where everyone can write but nobody can delete other people's files.
Avoid 777 and 666 on anything that matters. If a program needs to write a file, give the program's user ownership, or put it in the right group and grant group write, instead of opening the file to every account on the machine.
More questions
Why does a directory need execute permission?
On a directory, execute means search: permission to open the directory and reach the files inside it by name. Read lets you list the names; without execute you can see them but not open them. That is why directories are usually 755 or 700 rather than 644 or 600.
What is the difference between chmod 755 and chmod u=rwx,g=rx,o=rx?
Nothing in the result: both set the mode to rwxr-xr-x. The octal form always replaces the whole mode. The symbolic form with = also sets each class completely, while + and - change only the bits you name and leave the rest as they were, which is handy in scripts.
How do I change permissions on every file in a folder?
chmod -R applies a mode recursively, but one mode rarely suits both files and directories. A common pattern is find dir -type d -exec chmod 755 {} + for directories and find dir -type f -exec chmod 644 {} + for files. The capital X in symbolic mode (chmod -R a+X dir) adds execute only to directories and to files that already have it.
Can I see a file's mode as a number?
Yes. On Linux, stat -c '%a %n' file prints the octal mode (for example 644 file); on macOS and BSD use stat -f '%Lp %N' file. ls -l shows the symbolic form, which this calculator converts.
Do file permissions apply to the root user?
Mostly not. The superuser can read and write any file regardless of its mode. Execute is the exception: root can run a file only if at least one execute bit is set. Permissions protect users from each other, not from an administrator.
Sources
This article explains how the calculator works and is general information, not financial, tax, legal or medical advice. Rules change; check the sources above or a qualified professional before you act.