红穆笔记

chmod

修改文件或目錄的訪問權限

100% 瀏覽器本地處理 0 數據上傳

常用示例

授予所有者[u]執行[x]文件的權限

chmod u+x {{文件}}

授予所有者[u]讀[r]和寫[w]文件或目錄的權限

chmod u+rw {{文件或目錄}}

移除用戶組[g]的文件執行[x]權限

chmod g-x {{文件}}

授予所有用戶[a]讀[r]以及執行[x]文件的權限

chmod a+rx {{文件}}

授予其他用戶[o](不在所有者用戶組)和用戶組[g]同樣的權限

chmod o=g {{文件}}

移除其他用戶[o]的所有權限

chmod o= {{文件}}

遞歸授予用戶組[g]和其他用戶[o]目錄下所有文件和子目錄的寫[w]權限

chmod {{[-R|--recursive]}} g+w,o+w {{目錄}}

遞歸授予所有用戶[a]目錄下文件的讀[r]權限和子目錄的執行[X]權限

chmod {{[-R|--recursive]}} a+rX {{目錄}}

提示:花括號{{…}}是需要替換的參數(路徑、文件名等);命令只在本機終端執行,本站不保存任何輸入。

英文原文對照

展開英文說明與示例(來源 tldr-pages)

Change the access permissions of a file or directory. More information

Give the [u]ser who owns a file the right to e[x]ecute it

chmod u+x {{path/to/file}}

Give the [u]ser rights to [r]ead and [w]rite to a file/directory

chmod u+rw {{path/to/file_or_directory}}

Remove e[x]ecutable rights from the [g]roup

chmod g-x {{path/to/file}}

Give [a]ll users rights to [r]ead and e[x]ecute

chmod a+rx {{path/to/file}}

Give [o]thers (not in the file owner's group) the same rights as the [g]roup

chmod o=g {{path/to/file}}

Remove all rights from [o]thers

chmod o= {{path/to/file}}

Change permissions recursively giving [g]roup and [o]thers the ability to [w]rite

chmod {{[-R|--recursive]}} g+w,o+w {{path/to/directory}}

Recursively give [a]ll users [r]ead permissions to files. Also give e[X]ecute permissions to files that have at least one execution permission and to all sub-directories

chmod {{[-R|--recursive]}} a+rX {{path/to/directory}}

命令信息

命令名chmod
用途修改文件或目錄的訪問權限
適用平臺通用
示例數量8 條
官方文檔https://www.gnu.org/software/coreutils/manual/html_node/chmod-invocation.html
數據來源tldr-pages(CC-BY-4.0)· 社區中文翻譯

常見問題

chmod 命令是做什麼的?

修改文件或目錄的訪問權限

chmod 怎麼用?

頁面按場景列出了8 條常用示例:每條示例先說明用途,再給出可直接複製的完整命令(花括號裏是需要替換的參數)。

chmod 最常用的操作是什麼?

授予所有者[u]執行[x]文件的權限:chmod u+x {{文件}}

命令裏的花括號是什麼意思?

花括號{{…}}表示需要替換成你自己的值,例如路徑、文件名;同名參數方括號(如 [-C|--directory])表示可選寫法。