1 特殊權限set_uid
<code>[root@chy ~]</code><code># ls -l /usr/bin/passwd 當s出現在檔案所有者的x的權限上說明是set_uid</code>
<code>-rwsr-xr-x. 1 root root 27832 6月 10 2014 </code><code>/usr/bin/passwd</code>
<code>set_uid 是普通使用者臨時擁有所有者的身份(前提是這個檔案是可執行的二進制檔案)</code>
<code>[root@chy ~]</code><code># chmod u+s /usr/bin/ls (給ls賦予set_uid權限)</code>
<code>[root@chy ~]</code><code># chmod u=rws /usr/bin/ls (第二種賦予權限的方法)</code>
<code>[root@chy ~]</code><code># ls -l /usr/bin/ls</code>
<code>-rwSr-xr-x. 1 root root 117656 11月 6 2016 </code><code>/usr/bin/ls</code>
<code>[root@chy ~]</code><code># chmod u+x /usr/bin/ls</code>
<code>-rwsr-xr-x. 1 root root 117656 11月 6 2016 </code><code>/usr/bin/ls</code>
2 特殊權限set_gid
該權限隻對目錄有效. 目錄被設定該位後, 任何使用者在此目錄下建立的檔案都具有和該目錄所屬的組相同的組.
<code>當s在使用者組x時稱為set_gid</code>
<code>[root@chy ~]</code><code># chown :chy /lsm 更改這個lsm目錄下的所屬組,這樣好差別。</code>
<code>[root@chy ~]</code><code># ls -ld /lsm 檢視權限</code>
<code>drwxr-xr-x 2 root chy 4096 6月 9 06:49 </code><code>/lsm</code> <code>沒有任何變化</code>
<code>[root@chy ~]</code><code># mkdir /lsm/1 (先建立一個檔案便于後面區分)</code>
<code>[root@chy ~]</code><code># ls -ld /lsm/1</code>
<code>drwxr-xr-x 2 檢視這個目錄的權限 root root 4096 6月 9 06:50 </code><code>/lsm/1</code>
<code>[root@chy ~]</code><code># chmod g+s /lsm/ 給/lsm加上+s的權限</code>
<code>[root@chy ~]</code><code># ls -ld /lsm 發現所屬組改變</code>
<code>drwxr-sr-x 3 root chy 4096 6月 9 06:50 </code><code>/lsm</code>
<code>[root@chy ~]</code><code># mkdir /lsm/234 重新建立一個後發現</code>
<code>[root@chy ~]</code><code># ls -ld /lsm/234 發現了差別 </code>
<code>drwxr-sr-x 2 root chy 4096 6月 9 06:51 </code><code>/lsm/234</code>
3 特殊權限stick_bit
<code>[root@chy ~]</code><code># stick_bit =防删除位 </code>
<code>[root@chy ~]</code><code># ls -ld /tmp/</code>
<code>drwxrwxrwt. 18 root root 4096 6月 9 06:33 </code><code>/tmp/</code>
<code>stick_bit防止其它使用者删除檔案(root除外)</code>
4 軟連接配接檔案
>另外一種連接配接稱之為符号連接配接(Symbolic Link),也叫軟連接配接。軟連結檔案有類似于Windows的快捷方式。它實際上是一個特殊的檔案。在符号連接配接中,檔案實際上是一個文本檔案,其中包含的有另一檔案的位置資訊。
<code>[root@chy ~]</code><code># ls -s 源檔案 軟連結檔案 (目标檔案)</code>
<code>[root@chy tmp]</code><code># ln -s /tmp/passwd 軟連結目錄 /root/111/passwd</code>
<code>[root@chy ~]</code><code># ls -l /root/111</code>
<code>總用量 0</code>
<code>lrwxrwxrwx 1 root root 11 6月 9 08:11 </code><code>passwd</code> <code>-> </code><code>/tmp/passwd</code>
<code>軟連接配接成功)</code>
<code>相對路徑的軟連接配接弊端:當把源檔案移動位置,軟連接配接将會失效</code>
5 硬連結
硬連接配接指通過索引節點來進行連接配接。在Linux的檔案系統中,儲存在磁盤分區中的檔案不管是什麼類型都給它配置設定一個編号,稱為索引節點号(Inode Index)。在Linux中,多個檔案名指向同一索引節點是存在的。一般這種連接配接就是硬連接配接。硬連接配接的作用是允許一個檔案擁有多個有效路徑名,這樣使用者就可以建立硬連接配接到重要檔案,以防止“誤删”的功能。其原因如上所述,因為對應該目錄的索引節點有一個以上的連接配接。隻删除一個連接配接并不影響索引節點本身和其它的連接配接,隻有當最後一個連接配接被删除後,檔案的資料塊及目錄的連接配接才會被釋放。也就是說,檔案真正删除的條件是與之相關的所有硬連接配接檔案均被删除。
<code>[root@chy ~]</code><code># ln 1.txt 1_head.txt</code>
1.隻能對檔案做硬連結檔案不能對目錄做硬連結
2.硬連結是互相的為硬連結,不分原連結目标連結。硬連結是相同的inode
3.硬連結不能跨分區
6 find 指令綜合
尋找檔案的指令:which
whereis
locate(預設沒有這個指令)
[root@chy ~]# yum install -y mlocate
手動生成的指令updatedb
快捷鍵介紹
[root@chy ~]# ctrl+l 清屏
[root@chy ~]# ctrl+d 退出一個終端
[root@chy ~]# ctrl+c 不想要執行的指令
[root@chy ~]# ctrl+u 删除光标前的所有内容
[root@chy ~]# ctrl+e 後把光标移到最後
[root@chy ~]# ctrl+a 把光标移到最開始
<code>find</code><code>的小案例</code>
[root@chy ~]# find /etc/ -name "sshd_config" 尋找一個檔案所在的路徑
[root@chy ~]# find /etc/ -name "sshd*" 廣布式搜尋一個檔案
[root@chy ~]# find /etc/ -type d -name "sshd*" (-type d 是搜尋一個目錄)
[root@chy ~]# find /etc/ -type f -name "sshd*" (-type f 搜尋一般正規檔案)
[root@chy ~]# find /etc/ -type l (-type l 搜尋連接配接檔案)
[root@chy ~]# find /dev/ -type b (-b與-c都是搜尋裝置檔案)
[root@chy ~]# stat 2.txt (stat 檢視檔案的具體資訊)
檔案:"2.txt"
大小:0 塊:0 IO 塊:4096 普通空檔案
裝置:fd00h/64768d Inode:146705 硬連結:1
權限:(0642/-rw-r---w-) Uid:( 0/ root) Gid:( 0/ root)
最近通路:2017-06-08 07:17:01.341855735 +0800
最近更改:2017-06-08 07:00:10.258873841 +0800
最近改動:2017-06-08 07:11:53.380861250 +0800
建立時間:-
mtime (最近更改)
atime (最近通路)
ctime (最近改動)
通路時間(-atime/天,-amin/分鐘):使用者最近一次通路時間。
修改時間(-mtime/天,-mmin/分鐘):檔案最後一次修改時間。
變化時間(-ctime/天,-cmin/分鐘):檔案資料元(例如權限等)最後一次修改時間。
[root@chy ~]# echo "1111" >>2.txt 當追加一個檔案後,ctime 與mtime時間都會改變)
[root@chy ~]# stat 2.txt
大小:5 塊:8 IO 塊:4096 普通檔案
最近更改:2017-06-10 16:31:02.055929915 +0800
最近改動:2017-06-10 16:31:02.055929915 +0800
[root@chy ~]# find / -type f -mtime -1 查找一天以内改動檔案
[root@chy ~]# find /etc/ -type f -o -mtime -1 -o -name "*.conf" (-o是或者的意思 ,不加就是并且的意思)
[root@chy ~]# find / -inum 146706 查找硬連結)
/root/3.txt
/tmp/1.txt.bak
[root@chy ~]# find /root/ -type f -mmin -60
/root/2.txt (查找一個小時以内更改的檔案)
[root@chy ~]# find /root/ -type f -mmin -60 -exec ls -l {} \;查找一個小時以内的更改的檔案并列出是哪些檔案改動的。
-rw-r---w- 1 root root 5 6月 10 16:31 /root/2.txt
[root@chy ~]# find /root/ -type f -size -10k -exec ls -lh {} \;
查找/root下小于10k的檔案并列出
[root@chy ~]# find /root/ -type f -size -10M -exec ls -lh {} \;(查找10M以上的檔案,其中-exec 是将對比對的檔案執行該參數給出的shell指令,-exec 等同于-ok,但是這兩者之間還是有點差別的差別是exec直接進行處理,而ok是在處理之前提示資訊,供使用者選擇是否進行進一步的操作)
7 檔案名字尾
inux 下常見的檔案字尾名
1:系統檔案*.conf配置檔案
.rpm rpm包
.a 一種存檔檔案
.lock 一種瑣檔案
.~ 備份檔案
. 隐藏檔案
2:程式或腳本.c c語言源程式檔案
.cpp c++語言源程式
.h c或c++頭檔案
.o 程式對象檔案
.pl perl語言源程式
. php php語言源程式
.tcl tcl腳本程式
.so/.lib 庫檔案
.sql sql語言檔案
3:格式檔案
.txt 無格式的ascii碼檔案
.html/.htm 靜态web頁
.ps postScipt檔案
.au 一種聲音檔案
.wav 一種聲音檔案
.xpm一種圖像檔案
.png一種圖形,圖像檔案
4:存檔與壓縮檔案
.tar tar歸檔檔案
.Z/.gz/.bz2壓縮檔案
.tar.gz/.tgz/.tar.bz2/.tbz為壓縮後的tar包
8 linux+windows互傳檔案
linux與windows互傳檔案有一個很好用的工具就是rz/sz,如下介紹(說明這個工具适用用xshell)
<code>[root@chy ~]</code><code># yum install -y lrzsz (此工具須使用x-shell)</code>
<code>[root@chy ~]</code><code># sz 1.txt 把linux上的檔案傳到windo上 </code>
<code>[root@chy ~]</code><code># rz (把windows上檔案上傳到linux上)</code>
本文轉自我不是瘦子51CTO部落格,原文連結:http://blog.51cto.com/chy940405/1983324,如需轉載請自行聯系原作者