Linux 文(wen)件(jian)目錄權限
							時間(jian):2018-09-28      來源:未(wei)知 
							# 文件參數
d:表示(shi)是(shi)一個目錄(lu)
-:表示這是一個普(pu)通的文件
l: 表示這是一(yi)個符(fu)號鏈接(jie)文件,實際上它指向另一(yi)個文件
b、c:分別表示區塊設(she)備和(he)其他的(de)(de)外圍設(she)備,是特殊類型的(de)(de)文件(jian)
s、p:這些文(wen)件關系到系統的數據結構和管道
x :執行文件(jian)或者進(jin)入目錄的權限
一(yi)、將一(yi)個(ge)文件設置成其他人不能讀(du)
# 先用(yong) root 用(yong)戶(hu)修改一個文件的權限:
[root@Demon data]# touch 1.txt
[root@Demon data]# ls -lh
總(zong)用量 4.0K
-rw-r--r--. 1 root root 0 1月(yue) 15 19:54 1.txt
[root@Demon data]# chmod 600 1.txt
[root@Demon data]# ls -l
總用量 4
-rw-------. 1 root root 0 1月 15 19:54 1.txt
# 用(yong)demon 用(yong)戶打開文(wen)件(jian):
demon@Demon data]$ cat 1.txt
cat: 1.txt: 權(quan)限(xian)不夠
二(er)、將一個目錄設(she)置成其它人不可(ke)進入
# 還是(shi)先用 root 對(dui) /data/test 目錄進行操作
[root@Demon data]# chmod 744 test
[root@Demon data]# ls -l
總用量 8
drwxr--r--. 2 root root 4096 1月 15 20:00 test
# 用(yong) demon 用(yong)戶進入 /data/test 目錄
[demon@Demon data]$ cd test/
bash: cd: test/: 權(quan)限不(bu)夠
三(san)、將(jiang)一個(ge)腳本設置成不可執(zhi)行
[demon@Demon data]$ ls -l test.sh
-rwxrwxr-x. 1 D D 26 1月 15 20:07 test.sh
[demon@Demon data]$ ./test.sh
Demon
[demon@Demon data]$ chmod 666 test.sh
[demon@Demon data]$ ./test.sh
bash: ./test.sh: 權限不夠
四、改變(bian)文件 / 目錄的所有者
chown root /u 將 /u 的屬主更(geng)改為"root"。
chown root:staff /u 和(he)上面類(lei)似(si),但同時也將其屬(shu)組更改為"staff"。
chown -hR root /u 將 /u 及其子目錄下所有(you)文件的(de)屬主更改為"root"。
1、改(gai)變文件(jian)的(de)所有者
[root@Demon data]# ls -l 1.txt
-rw-------. 1 root root 0 1月 15 19:54 1.txt
[root@Demon data]# chown demon 1.txt
[root@Demon data]# ls -l 1.txt
-rwxrw-rw-. 1 demon root 0 1月(yue) 15 19:54 1.txt
2、改變目錄的所有者
[root@Demon data]# ls -l
總用量 12
drwxr--r--. 2 root root 4096 1月 15 20:00 test
[root@Demon data]# chown demon test
[root@Demon data]# ls -l
總用量 12
drwxr--r--. 2 demon root 4096 1月(yue) 15 20:00 test