歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> AIX - chmod命令

AIX - chmod命令

日期:2017/3/1 14:47:19   编辑:關於Linux
AIX - chmod命令 AIX - chmod 命令 chmod用於改變文件或目錄的訪問權限。用戶用它控制文件或目錄的訪問權限。 該命令有兩種用法。一種是包含字母和操作符表達式的文字設定法;另一種是包含 數字的數字設定法。 1. 文字設定法 語法:chmod [who] [+ | - | =] [mode] 文件名 命令中各選項的含義為: 操作對象who可是下述字母中的任一個或者它們的組合:   u 表示“用戶(user)”,即文件或目錄的所有者。   g 表示“同組(group)用戶”,即與文件屬主有相同組ID的所有用戶。   o 表示“其他(others)用戶”。   a 表示“所有(all)用戶”。它是系統默認值。 操作符號可以是:   + 添加某個權限。   - 取消某個權限。   = 賦予給定權限並取消其他所有權限(如果有的話)。 設置 mode 所表示的權限可用下述字母的任意組合:   r 可讀。   w 可寫。  x 可執行。   X 只有目標文件對某些用戶是可執行的或該目標文件是目錄時才追加x 屬性。   s 在文件執行時把進程的屬主或組ID置為該文件的文件屬主。 方式“u+s”設置文件的用戶ID位,“g+s”設置組ID位。   t 保存程序的文本到交換設備上。   u 與文件屬主擁有一樣的權限。   g 與和文件屬主同組的用戶擁有一樣的權限。   o 與其他用戶擁有一樣的權限。 文件名:以空格分開的要改變權限的文件列表,支持通配符。    在一個命令行中可給出多個權限方式,其間用逗號隔開。例如: chmod g+r,o+r example % 使同組和其他用戶對文件example 有讀權限。 2. 數字設定法 我們必須首先了解用數字表示的屬性的含義:0表示沒有權限,1表示可執行權限, 2表示可寫權限,4表示可讀權限,然後將其相加。所以數字屬性的格式應為3個從0到7的 八進制數,其順序是(u)(g)(o)。 例如,如果想讓某個文件的屬主有“讀/寫”二種權限,需要把4(可讀)+2(可寫)=6(讀/寫)。 數字設定法的一般形式為: 語法:chmod [mode] 文件名 [b]指令實例:[/b] chmod a+x sort % 即設定文件sort的屬性為:  文件屬主(u) 增加執行權限  與文件屬主同組用戶(g) 增加執行權限  其他用戶(o) 增加執行權限 chmod ug+w,o-x text % 即設定文件text的屬性為:  文件屬主(u) 增加寫權限  與文件屬主同組用戶(g) 增加寫權限  其他用戶(o) 刪除執行權限 chmod u+s a.out % 假設執行chmod後a.out的權限為(可以用ls – l a.out命令來看):  –rws--x--x 1 inin users 7192 Nov 4 14:22 a.out  並且這個執行文件要用到一個文本文件shiyan1.c,其文件存取權限為“–rw-------”, 即該文件只有其屬主具有讀寫權限。   當其他用戶執行a.out這個程序時,他的身份因這個程序暫時變成inin(由於chmod 命令中使用了s選項),所以他就能夠讀取shiyan1.c這個文件(雖然這個文件被設定為 其他人不具備任何權限),這就是s的功能。   因此,在整個系統中特別是root本身,最好不要過多的設置這種類型的文件(除非 必要)這樣可以保障系統的安全,避免因為某些程序的bug而使系統遭到入侵。 chmod a–x mm.txt chmod –x mm.txt chmod ugo–x mm.txt % 以上這三個命令都是將文件mm.txt的執行權限刪除,它設定的對象為所有使用者。 $ chmod 644 mm.txt % 即設定文件mm.txt的屬性為:-rw-r--r--  文件屬主(u)inin 擁有讀、寫權限  與文件屬主同組人用戶(g) 擁有讀權限  其他人(o) 擁有讀權限 chmod 750 wch.txt % 即設定wchtxt這個文件的屬性為:-rwxr-x---  文件主本人(u)inin 可讀/可寫/可執行權  與文件主同組人(g) 可讀/可執行權  其他人(o) 沒有任何權限 增加點其它內容: Sticky bit The most common use of the sticky bit today is on directories, where, when set, items inside the directory can only be renamed or deleted by the item's owner, the directory's owner, or the superuser. Generally this is set on the /tmp directory to prevent ordinary users from deleting or moving other users' files. Examples The sticky bit can only be set by superuser root. Using the chmod command, it can be set using its octal mode 1000 or by its symbol t (s is already used by the setuid bit). For example, to add the bit on the directory /usr/local/tmp, one would type chmod +t /usr/local/tmp. Or, to make sure that directory has standard tmp permissions, one could also type chmod 1777 /usr/local/tmp. In Unix symbolic file system permission notation, the sticky bit is represented by the letter t in the final character-place. For instance, on Solaris 8, the /tmp directory, which by default has the sticky-bit set, shows up as: $ ls -ld /tmp drwxrwxrwt 4 root sys 485 Nov 10 06:01 /tmp If the sticky-bit is set on a file or directory without the execution bit set for the others category (non-user-owner and non-group-owner), it is indicated with a capital T: # ls -l test -rw-r--r-- 1 root other 0 Nov 10 12:57 test # chmod +t test; ls -l test -rw-r--r-T 1 root other 0 Nov 10 12:57 test
Copyright © Linux教程網 All Rights Reserved