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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值