chmod Calculator
Convert file permission specifications between numeric (octal) and symbolic notation, and produce the corresponding chmod command.
Input
- - Either a numeric permission string (e.g.
755, 644, 4755) - Or a description of permissions per entity (owner/group/others with read/write/execute)
- Or a symbolic string (e.g.
rwxr-xr-x)
Output
- - Numeric notation (3 or 4 digits)
- Symbolic notation (9 characters, e.g.
rwxr-xr-x) - Numeric chmod command: INLINECODE6
- Symbolic chmod command: INLINECODE7
- Plain-English description of what each entity can do
Instructions
Permission bit values
Each entity (owner/group/others) is a sum of:
- - Read (r) = 4
- Write (w) = 2
- Execute (x) = 1
Special permission bits (4th leading digit)
- - Setuid = 4 (runs as owner)
- Setgid = 2 (runs as group)
- Sticky = 1 (only owner can delete in directory)
Numeric → Symbolic conversion
Given a 3-digit octet
OGO:
- - For each digit, decompose:
r if bit 2 set, w if bit 1 set, x if bit 0 set, else -. - With leading special digit
S: setuid sets s/S in owner execute position; setgid sets s/S in group execute position; sticky sets t/T in others execute position.
Symbolic → Numeric conversion
Map each 3-char group to a digit using the bit values above.
Symbolic chmod command format
Build clauses for each entity with permissions set:
- -
u = owner, g = group, o = others - Emit
{entity}+{perms} for each entity that has any permissions - Special bits:
u+s (setuid), g+s (setgid), +t (sticky)
Common permission reference
| Numeric | Symbolic | Description |
|---|
| 644 | rw-r--r-- | Standard file (owner rw, rest r) |
| 755 |
rwxr-xr-x | Standard directory/executable |
| 600 | rw------- | Private file (owner only) |
| 700 | rwx------ | Private directory/executable |
| 777 | rwxrwxrwx | Full access (avoid in production) |
| 4755 | rwsr-xr-x | Setuid executable |
| 2755 | rwxr-sr-x | Setgid executable |
| 1755 | rwxr-xr-t | Sticky directory |
Options
- - Input can be numeric, symbolic, or a plain-English description of desired permissions.
Examples
Input: 755
Output:
CODEBLOCK0
Input: 644
Output:
CODEBLOCK1
Input: rwxr-xr-x
Output:
CODEBLOCK2
Input: "owner can read and write, group can read, others nothing"
Output:
CODEBLOCK3
Error Handling
- - If numeric input has more than 4 digits or contains non-octal characters, say so.
- If a digit in the octet exceeds 7, explain that each permission digit must be 0–7.
- If symbolic input is not exactly 9 or 10 characters in valid format, ask for clarification.
- Warn the user if they request
777 that this allows full access to everyone and is a security risk.
chmod 计算器
在数字(八进制)和符号表示法之间转换文件权限规范,并生成相应的 chmod 命令。
输入
- - 数字权限字符串(例如 755、644、4755)
- 或按实体(所有者/组/其他用户)描述的权限(读/写/执行)
- 或符号字符串(例如 rwxr-xr-x)
输出
- - 数字表示法(3或4位数字)
- 符号表示法(9个字符,例如 rwxr-xr-x)
- 数字格式的 chmod 命令:chmod 755 filename
- 符号格式的 chmod 命令:chmod u+rwx,g+rx,o+rx filename
- 每个实体权限的通俗英文描述
说明
权限位值
每个实体(所有者/组/其他用户)是以下值的总和:
特殊权限位(第4位前导数字)
- - Setuid = 4(以所有者身份运行)
- Setgid = 2(以组身份运行)
- Sticky = 1(仅所有者可在目录中删除)
数字 → 符号转换
给定一个3位八进制数 OGO:
- - 对每位数字进行分解:如果第2位设置则为 r,如果第1位设置则为 w,如果第0位设置则为 x,否则为 -。
- 带前导特殊数字 S:setuid 在所有者执行位置设置 s/S;setgid 在组执行位置设置 s/S;sticky 在其他用户执行位置设置 t/T。
符号 → 数字转换
使用上述位值将每组3个字符映射为一个数字。
符号格式的 chmod 命令格式
为每个具有权限集的实体构建子句:
- - u = 所有者,g = 组,o = 其他用户
- 对每个拥有任何权限的实体输出 {entity}+{perms}
- 特殊位:u+s(setuid)、g+s(setgid)、+t(sticky)
常见权限参考
| 数字 | 符号 | 描述 |
|---|
| 644 | rw-r--r-- | 标准文件(所有者读写,其余只读) |
| 755 |
rwxr-xr-x | 标准目录/可执行文件 |
| 600 | rw------- | 私有文件(仅所有者) |
| 700 | rwx------ | 私有目录/可执行文件 |
| 777 | rwxrwxrwx | 完全访问(生产环境避免使用) |
| 4755 | rwsr-xr-x | Setuid 可执行文件 |
| 2755 | rwxr-sr-x | Setgid 可执行文件 |
| 1755 | rwxr-xr-t | Sticky 目录 |
选项
- - 输入可以是数字、符号,或所需权限的通俗英文描述。
示例
输入: 755
输出:
数字表示法: 755
符号表示法: rwxr-xr-x
命令(数字格式): chmod 755 filename
命令(符号格式): chmod u+rwx,g+rx,o+rx filename
所有者:读、写、执行
组:读、执行
其他用户:读、执行
输入: 644
输出:
数字表示法: 644
符号表示法: rw-r--r--
命令(数字格式): chmod 644 filename
命令(符号格式): chmod u+rw,g+r,o+r filename
所有者:读、写
组:读
其他用户:读
输入: rwxr-xr-x
输出:
数字表示法: 755
符号表示法: rwxr-xr-x
命令(数字格式): chmod 755 filename
命令(符号格式): chmod u+rwx,g+rx,o+rx filename
输入: 所有者可以读写,组可以读,其他用户无权限
输出:
数字表示法: 640
符号表示法: rw-r-----
命令(数字格式): chmod 640 filename
命令(符号格式): chmod u+rw,g+r filename
错误处理
- - 如果数字输入超过4位或包含非八进制字符,请说明。
- 如果八进制数字中的某位超过7,请解释每个权限数字必须在0–7之间。
- 如果符号输入不是有效的9或10个字符格式,请要求澄清。
- 如果用户请求 777,警告这将允许所有人完全访问,存在安全风险。