s是set_uid的權限
除了所有者之外的其他使用者臨時擁有所有者的身份。(前提是一個二進制可執行檔案),目錄頁可以設定但是沒意義
[root@localhost ~]# ll /usr/bin/passwd
-rwsr-xr-x. 1 root root 27832 6月 10 2014 /usr/bin/passwd
[root@localhost ~]# ll -d /usr/bin/ls
-rwxr-xr-x. 1 root root 117616 6月 10 2014 /usr/bin/ls
[root@localhost ~]# chmod u+s /usr/bin/ls
[root@localhost ~]# ll /usr/bin/ls
-rwsr-xr-x. 1 root root 117616 6月 10 2014 /usr/bin/ls
[root@localhost ~]# chmod u=rws /usr/bin/ls
[root@localhost ~]# ll /usr/bin/ls //S也可以執行
-rwSr-xr-x. 1 root root 117616 6月 10 2014 /usr/bin/ls
[root@localhost ~]# chmod u+x /usr/bin/ls
s是set_gid的權限
執行檔案的普通使用者擁有所有組的身份
[root@localhost ~]# chmod g+s /usr/bin/ls
-rwxr-sr-x. 1 root root 117616 6月 10 2014 /usr/bin/ls
給目錄增加set_gid權限後,在目錄下建立子目錄或者檔案所屬組的名字都是設定set_gid的組名保持一緻
[root@localhost ~]# chmod g+s lsx
[root@localhost ~]# touch lsx/2.txt
[root@localhost ~]# ll lsx/
總用量 0
-rw-r--r--. 1 root root 0 10月 21 02:34 1.txt
-rw-r--r--. 1 root user1 0 10月 21 02:37 2.txt
stick_bit:防删除位(靠父級目錄決定的)
[root@localhost ~]# ll -d /tmp/ //該目錄下防止其他使用者删除自己的檔案。除了root
drwxrwxrwt. 10 root root 4096 10月 21 02:28 /tmp/
[user1@localhost tmp]$ whoami
user1
[user1@localhost ~]$ pwd
/home/user1
[user1@localhost ~]$ mkdir lsx
[user1@localhost ~]$ mkdir lsx/lshx
[user1@localhost ~]$ mkdir lsx/1.txt
[user1@localhost ~]$ ll //目錄可讀寫、執行
drwxrwxrwx. 4 user1 user1 29 10月 21 03:01 lsx
[user1@localhost ~]$ ll lsx/ //
drwxrwxr-x. 2 user1 user1 6 10月 21 03:01 1.txt
drwxrwxr-x. 2 user1 user1 6 10月 21 03:01 lshx
User2使用者
[user2@localhost lsx]$ ls
1.txt lshx
[user2@localhost lsx]$ rm -rf 1.txt/ //其他使用者可以删除user1使用者建立的目錄下的檔案是因為該檔案所在目錄的檔案權限為777,而不是看删除檔案本身的權限
[user2@localhost lsx]$ ll
[root@localhost ~]# ls -l /bin //bin是軟連結,源檔案在/usr/bin
lrwxrwxrwx. 1 root root 7 10月 15 22:36 /bin -> usr/bin
軟連結:
[root@localhost ~]# ln -s 源檔案 軟連結檔案
[root@localhost ~]# ln -s /tmp/yum.log /root/111 //軟連結檔案
[root@localhost ~]# ll
lrwxrwxrwx. 1 root root 12 Oct 21 03:56 111 -> /tmp/yum.log
[root@localhost ~]# ln -s /tmp/lsx /root/222 //軟連結目錄
lrwxrwxrwx. 1 root root 8 Oct 21 03:59 222 -> /tmp/lsx
相對路徑設定軟連結弊端,當目錄改名時會出現問題。盡量使用絕對路徑設定軟連結
[root@localhost tmp]# ln -s yum.log lsx.log //相對路徑設定軟連結
[root@localhost tmp]# ls -l
lrwxrwxrwx. 1 root root 7 Oct 21 04:04 lsx.log -> yum.log
生産場景:
[root@localhost tmp]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 11G 903M 9.8G 9% /
devtmpfs 260M 0 260M 0% /dev
tmpfs 265M 0 265M 0% /dev/shm
tmpfs 265M 4.4M 261M 2% /run
tmpfs 265M 0 265M 0% /sys/fs/cgroup
/dev/sda1 197M 81M 117M 41% /boot
比如:有一個服務lsx,寫日志到了/boot/lsx.log下面,把/boot/lsx.log寫的很大。
怎麼把/boot/lsx.log,挪到/分區下。因為這個服務路徑不能動,是以
cp /boot/lsx.log /lsx.log
ln -s /lsx.log /boot/lsx.log
total 4
-rw-------. 1 root root 973 Oct 15 22:41 anaconda-ks.cfg
drwxr-xr-x. 2 root root 16 Oct 21 04:19 lsx
硬連結:
1.不支援目錄做硬連結
2.硬連結時間和大小、inode和源檔案一樣
3.删除源檔案對硬連結沒影響,軟連接配接異常
4.真正存檔案的是inode(多個硬連結指向一個inode,但是至少留一個硬連結),裡面存放資料的資訊,inode隻占一份空間
5.硬連結不能跨分區(各個分區初始化inode已經分好了)
[root@localhost ~]# ln anaconda-ks.cfg 1_hard.txt
[root@localhost ~]# ln -s anaconda-ks.cfg 1_soft.txt
-rw-------. 2 root root 973 Oct 15 22:41 1_hard.txt
lrwxrwxrwx. 1 root root 15 Oct 21 04:41 1_soft.txt -> anaconda-ks.cfg
-rw-------. 2 root root 973 Oct 15 22:41 anaconda-ks.cfg
本文轉自 蝦米的春天 51CTO部落格,原文連結:http://blog.51cto.com/lsxme/1975890,如需轉載請自行聯系原作者