Manpages

名 稱

chmod - 改 變 文 件 模 式 比 特 位

概 述

chmod [選 項 ]... 模 式 [,模 式 ]... 文 件 列 表 ...
chmod
[選 項 ]... 八 進 制 模 式 字 符 串 文 件 列 表 ...
chmod
[選 項 ]... --reference=參 考 文 件 文 件 列 表 ...

描 述

本 手 冊 頁 記 錄 了 GNU 版 本 的 chmodchmod 根 據 給 定 模 式 改 變 每 個 給 出 文 件 的 模 式 比 特 位 , 其 模 式 字 符 串 既 可 以 是 修 改 目 標 的 符 號 表 示 , 也 可 以 是 用 一 個 八 進 制 數 字 來 代 表 新 的 模 式 比 特 位 形 式 。

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