chmod 命令速查表

Linux 权限变更速查表

The chmod command changes file and directory permissions in Unix/Linux.

🧑 User Classes

SymbolMeaning
uUser (owner)
gGroup
oOthers
aAll (u+g+o)

🔐 Permission Types

SymbolMeaningNumeric
rRead4
wWrite2
xExecute1

📝 Symbolic Mode

Use +, -, or = to modify permissions:

chmod u+x file # Add execute to user chmod go-w file # Remove write from group and others chmod a=r file # Set read-only for all 

🔢 Numeric (Octal) Mode

Combine values for user, group, and others:

ModePermissionsMeaning
777rwxrwxrwxFull access
755rwxr-xr-xCommon for scripts
644rw-r–r–Common for text files
chmod 755 script.sh chmod 644 notes.txt 

🧪 Special Permission Flags

These flags go beyond basic read/write/execute and control execution context and deletion behavior.

🔸 setuid (Set User ID on Execution)

  • Octal prefix: 4
  • Applies to: Executable files
  • Effect: When executed, the process runs with the file owner’s privileges (not the user’s).
  • Use case: Programs like passwd need elevated privileges to modify system files.
chmod 4755 /usr/bin/somebinary # -rwsr-xr-x → 's' replaces 'x' in user field 

⚠️ Security risk if misused — avoid setting on scripts or user-controlled binaries.

🔸 setgid (Set Group ID)

  • Octal prefix: 2
  • Applies to:
    • Files: Runs with the file group’s privileges.
    • Directories: New files inherit the directory’s group.
  • Use case: Shared project folders where all files should belong to the same group.
chmod 2755 /shared/folder # drwxr-sr-x → 's' in group field 

📁 On directories, this ensures group consistency for collaborative environments.

🔸 sticky Bit

  • Octal prefix: 1
  • Applies to: Directories only
  • Effect: Only the file owner (or root) can delete or rename files inside.
  • Use case: /tmp directory — prevents users from deleting each other’s files.
chmod 1777 /tmp # drwxrwxrwt → 't' in others field 

🧷 Think of it as a “delete lock” for shared spaces.

📂 Execute (x) Flag: Files vs Directories

ContextEffect of x Permission
FileAllows execution as a program/script
DirectoryAllows entering the directory (cd) and accessing contents by name

🔍 Directory Access Matrix

PermissionCan List (ls)Can Enter (cd)Can Access Files
r✅ (if name known)
x✅ (if name known)
r+x

🧠 Without x on a directory, you can’t cd into it — even if you can list its contents.

🔍 Quick Reference

CommandDescription
chmod +x fileMake file executable
chmod -R 755 dirRecursively set permissions
chmod u=rwx fileSet user to rwx only
chmod a-x fileRemove execute from all

💡 Tip: Use ls -l to view current permissions.

相关工具 (17)

chmod 命令速查表
Linux 权限变更速查表
常用正则表达式备忘单
常用正则表达式模式备忘单。
CSS选择器备忘单
CSS选择器语法备忘单。
Docker Compose 备忘单
Docker Compose 格式备忘单
Docker备忘单
Docker命令备忘单。
Docker SWARM 备忘单
Docker Swarm 模式速查表
Dockerfile 备忘单
Dockerfile 语法和构建备忘单
Git语义提交备忘单
使用语义前缀提交Git的备忘单
JQ备忘单
JQ命令备忘单
JSONPath语法备忘单
JSONPath语法备忘单
Markdown备忘单
Markdown备忘单
Nano备忘单
Nano编辑器备忘单
正则表达式备忘单
JavaScript正则表达式备忘单
Sed 备忘单
sed unix 命令速查表
XPath语法备忘单
XPath语法备忘单
chmod计算器
通过此在线chmod计算器计算您的chmod权限和命令。
ZPool 备忘单
OpenZFS/ZPool 使用命令和信息
留言区