名 称
chmod - 改 变 文 件 模 式 比 特 位
概 述
chmod
[选 项 ]... 模 式
[,模 式 ]... 文 件
列 表 ...
chmod [选 项 ]... 八
进 制 模 式 字 符
串 文 件 列 表 ...
chmod [选 项 ]...
--reference=参 考 文 件 文
件 列 表 ...
描 述
本 手 册 页 记 录 了 GNU 版 本 的 chmod。 chmod 根 据 给 定 模 式 改 变 每 个 给 出 文 件 的 模 式 比 特 位 , 其 模 式 字 符 串 既 可 以 是 修 改 目 标 的 符 号 表 示 , 也 可 以 是 用 一 个 八 进 制 数 字 来 代 表 新 的 模 式 比 特 位 形 式 。
The format of a symbolic mode is [ugoa...][[-+=][perms...]...], where perms is either zero or more letters from the set rwxXst, or a single letter from the set ugo. Multiple symbolic modes can be given, separated by commas.
A combination of the letters ugoa controls which users’ access to the file will be changed: the user who owns it (u), other users in the file’s group (g), other users not in the file’s group (o), or all users (a). If none of these are given, the effect is as if (a) were given, but bits that are set in the umask are not affected.
The operator + causes the selected file mode bits to be added to the existing file mode bits of each file; - causes them to be removed; and = causes them to be added and causes unmentioned bits to be removed except that a directory’s unmentioned set user and group ID bits are not affected.
The letters rwxXst select file mode bits for the affected users: read (r), write (w), execute (or search for directories) (x), execute/search only if the file is a directory or already has execute permission for some user (X), set user or group ID on execution (s), restricted deletion flag or sticky bit (t). Instead of one or more of these letters, you can specify exactly one of the letters ugo: the permissions granted to the user who owns the file (u), the permissions granted to other users who are members of the file’s group (g), and the permissions granted to users that are in neither of the two preceding categories (o).
A numeric mode is from one to four octal digits (0-7), derived by adding up the bits with values 4, 2, and 1. Omitted digits are assumed to be leading zeros. The first digit selects the set user ID (4) and set group ID (2) and restricted deletion or sticky (1) attributes. The second digit selects permissions for the user who owns the file: read (4), write (2), and execute (1); the third selects permissions for other users in the file’s group, with the same values; and the fourth for other users not in the file’s group, with the same values.
chmod never changes the permissions of symbolic links; the chmod system call cannot change their permissions. This is not a problem since the permissions of symbolic links are never used. However, for each symbolic link listed on the command line, chmod changes the permissions of the pointed-to file. In contrast, chmod ignores symbolic links encountered during recursive directory traversals.
SETUID 和 SETGID 比 特 位
chmod clears the set-group-ID bit of a regular file if the file’s group ID does not match the user’s effective group ID or one of the user’s supplementary group IDs, unless the user has appropriate privileges. Additional restrictions may cause the set-user-ID and set-group-ID bits of MODE or RFILE to be ignored. This behavior depends on the policy and functionality of the underlying chmod system call. When in doubt, check the underlying system behavior.
For directories chmod preserves set-user-ID and set-group-ID bits unless you explicitly specify otherwise. You can set or clear the bits with symbolic modes like u+s and g-s. To clear these bits for directories with a numeric mode requires an additional leading zero, or leading = like 00755 , or =755
RESTRICTED DELETION FLAG OR STICKY BIT
The restricted deletion flag or sticky bit is a single bit, whose interpretation depends on the file type. For directories, it prevents unprivileged users from removing or renaming a file in the directory unless they own the file or the directory; this is called the restricted deletion flag for the directory, and is commonly found on world-writable directories like /tmp. For regular files on some older systems, the bit saves the program’s text image on the swap device so it will load more quickly when run; this is called the sticky bit.
选 项
将 每 个 文 件 的 权 限 模 式 变 更 至 指 定 模 式 。 使 用 --reference 选 项 时 , 把 指 定 文 件 的 模 式 设 置 为 与 参 考 文 件 相 同 。
-c, --changes
类 似 verbose 选 项 ,
但 只 在 做 出 修
改 时 进 行 报 告
-f, --silent, --quiet 隐 藏
大 多 数 错 误 信
息
-v, --verbose 对 每 一 个
处 理 的 文 件 输
出 诊 断 信 息
--no-preserve-root 不 要 对
“/”特 别 对 待 (
默 认 )
--preserve-root 不 要 在
“/”下 进 行 递 归
操 作
--reference=参 考 文 件
使 用 参 考 文 件
的 模 式 作 为 具
体 模 式 值
-R, --recursive 递 归 修
改 文 件 和 目 录
--help 显 示 此 帮 助 信 息 并 退 出 |
--version 显 示 版 本 信 息 并 退 出 每 个 模 式 字 符 串 都 应 该 匹 配 如 下 格 式 : "[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+"。
作 者
由 David MacKenzie 和 Jim Meyering 编 写 。
报 告 错 误
GNU coreutils 的 在 线 帮 助 : <https://www.gnu.org/software/coreutils/> 请 向 <https://translationproject.org/team/zh_CN.html> 报 告 翻 译 错 误 。
版 权
Copyright
© 2020 Free Software Foundation, Inc. License GPLv3+:
GNU GPL version 3 or later
<https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and
redistribute it. There is NO WARRANTY, to the extent
permitted by law.
参 见
chmod(2) 完 整 文 档 请 见 : <https://www.gnu.org/software/coreutils/chmod> 或 者 在 本 地 使 用 : info '(coreutils) chmod invocation'
跋
本 页 面 中 文 版 由 中 文 man 手 册 页 计 划 提 供 。 中 文 man 手 册 页 计 划 : https://github.com/man-pages-zh/manpages-zh