Chinaunix首页 | 论坛 | 博客
  • 博客访问: 488912
  • 博文数量: 138
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 716
  • 用 户 组: 普通用户
  • 注册时间: 2015-03-03 21:48
文章分类

全部博文(138)

文章存档

2019年(1)

2017年(5)

2016年(99)

2015年(33)

我的朋友

分类: LINUX

2016-08-18 10:53:23

Sticky 位是一个访问权限标志位,可以用来标示文件和路径。
历史:
粘滞位是在1974年Unix的第5版中引入的,用来设置可执行文件。当可执行文件设置粘滞位之后,它能够指示操作系统在程序退出后,保留程序的代码段到swap空间。当程序再次执行时,内核只需将程序从swap搬到内存即可,这能够加速程序的执行。所以,频繁使用的程序比如编辑器能够更快的打开。目前,这种应用只是适用于HP-UX, NetBSD和UnixWare,Solaris在2005年放弃了这种应用,linux没有版本支持过这种行为。
当今使用:
当今,粘滞位最常用是应用于路径。当路径被设置粘滞位后,路径下的文件只有文件的owner,路径的owner, 或者root 才能够重命名、删除文件。如果没有粘滞位,任何用户,不管是不是owner, 只要有路径的写/执行权限就可以重命名、删除文件。典型的应用就是/tmp路径,粘滞位可以阻止一般用户删除/重命名其他用户的文件。这种特性首次引入是在1986年4.3BSD, 今天在现在的Unix系统中都可以找到这个特性。另外,Solaris定义了独有的行为:当粘滞位设置到非执行文件时,当访问这种文件时,内核将不会缓存。这常用于设置swap文件,用来阻止访问这些文件时冲刷掉系统缓存中更重要的数据。
Sticky bit在不同系统中的异同
HP-UX:当程序的最后一个用户退出时,阻止系统丢弃程序段swap-space image. 当下一个用户执行这个程序时,系统只需要swap in,而不需要重从磁盘新读入文件到内存,节约程序启动时间。
[...] prevents the system from abandoningthe swap-space image of the program-text portion of the file when its last userterminates. Then, when the next user of the file executes it, the text need notbe read from the file system but can simply be swapped in, thus saving time.
Linux: 当粘滞位设置到文件时,内核将会忽略。当设置路径时,路径中的文件只能够被root或者文件的owner重命名或者unlinked。
[...] the Linux kernel ignores the stickybit on files. [...] When the sticky bit is set on a directory, files in thatdirectory may only be unlinked or renamed by root or their owner.
举例:
Sticky bit 设置:
chmod 命令,可以用八进制模式1000或者它的符号t.


比如:添加粘滞位到路径/usr/local/tmp,


1.      chmod +t /usr/local/tmp
2.      chmod 1777 /usr/local/tmp
在Unix 文件系统 符号中,sticky bit t 是在最后一位。比如:在Solaris 8, /tmp路径默认有粘滞位,如下:
$ ls -ld /tmp
 drwxrwxrwt   4 root     sys          485 Nov 10 06:01 /tmp
如果粘滞位设置的路径或者文件没有可执行(x)位,它的符号用T(大些的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 tes

阅读(844) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~