chmod命令用於改變linux系統文件或目錄的訪問權限。
該命令有兩種用法:
一種是包含字母和操作符表達式的文字設定法;
另一種是包含數字的數字設定法。
文件或目錄的訪問權限分為只讀,只寫和可執行三種。
chmod常見命令參數
Usage: chmod [OPTION]... MODE[,MODE]... FILE... or: chmod [OPTION]... OCTAL-MODE FILE... or: chmod [OPTION]... --reference=RFILE FILE... Change the mode of each FILE to MODE. -c, --changes like verbose but report only when a change is made --no-preserve-root do not treat `/' specially (the default) --preserve-root fail to operate recursively on `/' -f, --silent, --quiet suppress most error messages -v, --verbose output a diagnostic for every file processed --reference=RFILE use RFILE's mode instead of MODE values -R, --recursive change files and directories recursively --help display this help and exit --version output version information and exit
常用的命令展示
421 分別代表文件的讀、寫、執行的權限
chmod:更改屬性值的
chmod 755 -R / 系統默認臨界 【002:系統的默認掩碼】
chmod 644 / 系統默認臨界 【cat /etc/profile|grep umask可以查看默認的umask值】
增加文件所有用戶組可執行權限
chmod a+x log2012.log 【有的腳本無法執行就是沒有x權限】
同時修改不同用戶權限,逗號分隔
chmod ug+w,o-x log201.log
使用“=”設置權限
chmod u=x hhh.txt ==> chmod 100 hhh.txt
為所有用戶分配讀權限
chmod a=r file
【更多參考】Linux 用戶和用戶組詳解