用法:chattr +i 在文件以及目錄+i權限時候,是不能夠更改,移動,刪除等操做,不能作任何操做node
用法:chattr +a 在文件以及目錄+a權限時候,是不能移動,刪除等操做,可是文件能夠追加內容,目錄裏能夠新加文件或目錄。linux
chattr -i 解除 i 的隱藏權限windows
chattr -a 解除 a 的隱藏權限centos
首先給1.txt加上 i 的權限,能夠ls -l 查看1.txt的權限並無什麼不一樣。bash
[root@aming1 ~]# ls 1.txt anaconda-ks.cfg [root@aming1 ~]# chattr +i 1.txt [root@aming1 ~]# ll 1.txt -rw-r--r--. 1 root root 111 5月 13 22:52 1.txt
而後vi編輯添加內容。會有以下提示,提示您正在編輯一個只讀的文件。即便強制保存也會保存失敗。session
連強大的rm -f 都沒法刪除ssh
[root@aming1 ~]# rm -f 1.txt rm: 沒法刪除"1.txt": 不容許的操做
移動更是不能夠的測試
[root@aming1 ~]# mv 1.txt 111.txt mv: 沒法將"1.txt" 移動至"111.txt": 不容許的操做
touch 也不能夠。ui
若是給一個目錄添加隱藏 i 權限,該目錄也和文件同樣不能夠更改,建立新目錄文件,刪除。可是限制的只是目錄自己,若是該目錄設置權限以前原有的文件則能夠追加文件內容。但不能夠更改和刪除。code
chattr +a 試一下 a的隱藏權限。
除了追加文件,能夠成功
[root@aming1 ~]# head -n2 /etc/passwd >> 1.txt [root@aming1 ~]# cat 1.txt root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin
touch也是能夠的
[root@aming1 ~]# touch 1.txt [root@aming1 ~]#
通過測試除了追加內容之外更改以前的其餘內容是不能夠的。
-給目錄加上a 權限能夠在此目錄下的文件追加內容。
[root@aming1 ~]# lsattr 1.txt ----i----------- 1.txt
[root@aming1 ~]# lsattr 1.txt -----a---------- 1.txt
[root@aming1 ~]# lsattr 1.txt ----ia---------- 1.txt
以前用到的一個命令就是更改密碼的時候用到的passwd命令
[root@aminglinux-01 ~]# which passwd /usr/bin/passwd [root@aminglinux-01 ~]# ls -l /usr/bin/passwd -rwsr-xr-x. 1 root root 27832 6月 10 2014 /usr/bin/passwd
能夠看到這個文件是紅色的,而且在全部者的第三位權限是個s
咱們平時普通用戶也是能夠用passwd來更改密碼的。那首先看看密碼文件的權限是怎麼樣的
[root@aminglinux-01 ~]# ls -l /etc/shadow ----------. 1 root root 662 8月 9 21:38 /etc/shadow
全部人都沒有任何權限,( 固然root是有至高無上的權利的)
能夠看到這個保存密碼的文件是很是嚴謹的,可是普通用戶依然有修改密碼的權限。所謂的set_uid就是在執行命令時臨時賦予root權限給沒權限的用戶。
給一個文件設置set_uid前提是這個文件是一個可執行的2進制文件。
file 加命令的絕對路徑,能夠查看文件類型,好比是可讀的test文件仍是不可讀的二進制文,以下顯示的就是二進制文件。
[root@aming1 ~]# file /usr/bin/passwd /usr/bin/passwd: setuid ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=1e5735bf7b317e60bcb907f1989951f6abd50e8d, stripped [root@aming1 ~]#
[root@aminglinux-01 ~]# which ls alias ls='ls --color=auto' /usr/bin/ls [root@aminglinux-01 ~]# chmod u+s /usr/bin/ls [root@aminglinux-01 ~]# ls -l /usr/bin/ls -rwsr-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls
[root@aming1 ~]# useradd aming [root@aming1 ~]# su - aming [aming@aming1 ~]$ ls /root/ ls: 沒法打開目錄/root/: 權限不夠
[aming@aming1 ~]$ su - root 密碼: 上一次登陸:二 5月 15 20:44:43 CST 2018從 192.168.159.1pts/0 上 [root@aming1 ~]# chmod u+s /usr/bin/ls [root@aming1 ~]# ls -l /usr/bin/ls -rwsr-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls [root@aming1 ~]# su - aming 上一次登陸:二 5月 15 22:35:46 CST 2018pts/0 上 [aming@aming1 ~]$ ls /root/ 111 1.txt anaconda-ks.cfg [aming@aming1 ~]$
[root@aming1 ~]# chmod u=rws /usr/bin/ls [root@aming1 ~]# ls -l /usr/bin/ls -rwSr-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls [root@aming1 ~]# chmod u+x /usr/bin/ls [root@aming1 ~]# ls -l /usr/bin/ls -rwsr-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls
能夠再用ls命令設置看一下,s權限做用在了用戶組的位置上,文件顯示爲黃色。
[root@aminglinux-01 ~]# chown linyu aaa/ [root@aminglinux-01 ~]# chmod g+s aaa/ [root@aminglinux-01 ~]# ls -ld aaa/ drwxr-sr-x. 2 linyu root 6 8月 9 22:08 aaa/ [root@aminglinux-01 ~]# mkdir aaa/aming11.txt [root@aminglinux-01 ~]# mkdir aaa/aming12/ [root@aminglinux-01 ~]# ls -l aaa/ 總用量 0 drwxr-sr-x. 2 root linyu 6 8月 10 19:47 aming11.txt drwxr-sr-x. 2 root linyu 6 8月 10 19:47 aming12
[root@aminglinux-01 ~]# ls -ld /tmp/ drwxrwxrwt. 13 root root 4096 8月 10 19:37 /tmp/
/tmp/最後一位權限是「t」,這個t就是防刪除位。
/tmp/默認是777權限,這樣每個用戶均可以更改刪除文件,這樣若是一個用戶把另外一個用戶的文件刪除了,這樣就亂套了。因此有了stick_bit權限,其餘用戶看是能夠得,更改,刪,是不能夠的。
首先用aming用戶在tmp下建立
[root@aming1 ~]# su - aming 上一次登陸:二 5月 15 22:38:42 CST 2018pts/0 上 [aming@aming1 ~]$ cd /tmp/ [aming@aming1 tmp]$ ls systemd-private-f5ee0732c20c480e948ac5116d7bc899-vmtoolsd.service-ZjwF4b [aming@aming1 tmp]$ touch /tmp/1.txt
而後切換爲aming2用戶對tmp下1.txt進行刪除,追加,更改,都是不能夠的。
[root@aming1 ~]# su - aming2 最後一次失敗的登陸:二 5月 15 23:10:37 CST 2018pts/0 上 最有一次成功登陸後有 1 次失敗的登陸嘗試。 [aming2@aming1 ~]$ vi /tmp/1.txt ----------------------------------------------此處vi編輯會提示該文件爲只讀。 [aming2@aming1 ~]$ head -n2 /etc/passwd >> /tmp/1.txt -bash: /tmp/1.txt: 權限不夠 [aming2@aming1 ~]$ rm /tmp/1.txt rm:是否刪除有寫保護的普通空文件 "/tmp/1.txt"?y rm: 沒法刪除"/tmp/1.txt": 不容許的操做
chmod g+s 用數字表示就是2755
chmod o+t 用數字表示就是1755
軟鏈接就像windows裏的快捷方式。
[root@aminglinux-01 ~]# ln -s /tmp/yum.log /root/aaa/yum.log [root@aminglinux-01 ~]# ls -l /root/aaa/ 總用量 0 -rw-r--r--. 1 root root 0 8月 10 19:44 aming1.txt lrwxrwxrwx. 1 root root 12 8月 10 23:04 yum.log -> /tmp/yum.log [root@aminglinux-01 ~]#
軟鏈接若是被刪除源文件並不會受到任何影響。可是源文件被刪除,或者目錄有改動,那麼軟鏈接文件會失效。
[root@aminglinux-01 ~]# ls -l /bin lrwxrwxrwx. 1 root root 7 7月 31 22:54 /bin -> usr/bin
軟連接文件也是有大小的,它的大小根據源文件路徑的長度來變化,源文件所在目錄越長越深,其軟鏈接的大小就會越大,固然在大也就是幾B大小。
[root@aminglinux-01 ~]# ln -s /tmp/111 /root/aming [root@aminglinux-01 ~]# ls -l /root/aming lrwxrwxrwx. 1 root root 8 8月 10 23:12 /root/aming -> /tmp/111 [root@aminglinux-01 ~]#
軟連接有絕對路徑頁遊相對路徑,相對路徑僅限於當前目錄。相對路徑有一些弊端。儘可能使用絕對路徑。由於軟鏈接文件一旦移動位置就會致使軟鏈接失效。
軟連接的用途例子:若是一個分區空間滿了,而服務只讀那個分區。這樣就能夠把當前分區的文件cp到更大的分區裏面。而後作一個軟連接到當前分區。這樣服務依然能夠讀取到文件。還有效的利用了磁盤空間。
硬連接支持對文件作硬連接。不支持目錄。
硬連接的inode號,時間,大小都是同樣的。
[root@aminglinux-01 ~]# ln 456.txt 456_heard.txt [root@aminglinux-01 ~]# ls -li 總用量 8 33575032 -rw-rw-r--. 2 root root 0 8月 9 22:14 456_heard.txt 33575032 -rw-rw-r--. 2 root root 0 8月 9 22:14 456.txt [root@aminglinux-01 ~]#
能夠看到硬連接的源文件456.txt和硬連接後的文件heard_456.txt,二者inode號,時間,大小都是同樣的。
因此硬連接其實是兩個文件是同一個文件。不分源文件和連接文件。二者是互相硬連接。刪除其中一個並不影響文件自己。
一個文件能夠建立多個硬連接。
文件名只是文件自己的一個外皮。真正的文件自己是inode號記住的文件。刪除其中一個外皮對文件自己並無影響。可是外皮須要最後留一個。不然這個文件就真的被刪除啦。
硬連接是不會佔用雙份空間的,由於使用相同的inode。
硬連接沒法跨分區創建,由於每個分區都有一套本身的inode,在格式化分區時都是預先設置好的。
沒法手動硬連接目錄。系統自帶硬連接目錄。
[root@aminglinux ~]# find /etc/ -name "sshd_config" /etc/ssh/sshd_config
[root@aminglinux ~]# find /etc/ -name "sshd*" /etc/rc.d/init.d/sshd /etc/pam.d/sshd /etc/sysconfig/sshd /etc/ssh/sshd_config
[root@aminglinux ~]# find /etc/ -type d -name "sshd*" [root@aminglinux ~]#
[root@aminglinux ~]# find /etc/ -type f -name "sshd*" /etc/rc.d/init.d/sshd /etc/pam.d/sshd /etc/sysconfig/sshd /etc/ssh/sshd_config [root@aminglinux ~]#
用法 find / -type -name -mtime -ctime -atime
首先用stat 命令,查看一個文件的詳細信息
[root@aminglinux ~]# stat 333.txt File: "333.txt" Size: 0 Blocks: 0 IO Block: 4096 普通空文件 Device: 803h/2051d Inode: 791054 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access最近訪問: 2017-03-25 04:39:31.455979690 +0800 Modify最近更改: 2017-03-25 04:39:31.455979690 +0800 Change最近改動: 2017-03-25 04:39:31.455979690 +0800 [root@aminglinux ~]#
Access最近訪問是:-atime (訪問一次就會變化)
Modify最近更改是:-mtine (改文件內容)
Change最近改動是:-ctime (改權限若是改動文件內容ctime也會跟着變化)
瞭解了 三個time後,能夠用進行find 利用三個time查找。
find / -type f -mtime -1(一天之內的意思) 以下能夠看到一天以內更改的文件很是多
[root@aminglinux ~]# find / -type f -mtime -1 /proc/1516/pagemap /proc/1516/attr/current /proc/1516/attr/prev /proc/1516/attr/exec /proc/1516/attr/fscreate /proc/1516/attr/keycreate /proc/1516/attr/sockcreate /proc/1516/wchan /proc/1516/stack /proc/1516/schedstat /proc/1516/cpuset /proc/1516/cgroup /proc/1516/oom_score /proc/1516/oom_adj /proc/1516/oom_score_adj /proc/1516/loginuid /proc/1516/sessionid /proc/1516/coredump_filter /proc/1516/io
find / -type f -mtime +1(一天以上的意思)
find / -type f -mmin -60(查看60分鐘之內的)
還能夠加多個判斷條件,起到而且的意思,首先要是文件,而後要一天內改動的,而後要名字包含.conf的
find /etc/ -type f -ctime -1 -name "*.conf"
[root@aming1 ~]# find /etc/ -type f -ctime -1 -name "*.conf" /etc/resolv.conf
[root@aming1 ~]# find /etc/ -type f -o -ctime -1 -o -name "*.conf"
[root@aming1 ~]# touch 2.txt [root@aming1 ~]# ln 2.txt /tmp/2.txt_heard [root@aming1 ~]# ls -li 總用量 8 50332746 drwxr-xr-x. 2 root root 19 5月 15 21:21 111 33599786 -rw-r--r--. 1 root root 130 5月 15 21:09 1.txt 33623781 -rw-r--r--. 2 root root 0 5月 16 10:50 2.txt 33574987 -rw-------. 1 root root 1422 3月 17 19:03 anaconda-ks.cfg [root@aming1 ~]# find / -inum 33623781 /root/2.txt /tmp/2.txt_heard [root@aming1 ~]#
[root@aming1 ~]# find /root/ -type f -mmin -60 /root/2.txt
做用:把前面查找出的內容,做爲參數在後面讓命令執行。
用法 find /root/ -type f -mmin -120 -exec ls -l {} ;
[root@aming1 ~]# find /root/ -type f -mmin -60 /root/2.txt [root@aming1 ~]# find /tmp/ -type f -mmin -120 -exec ls -l {} \; -rw-r--r--. 2 root root 0 5月 16 10:50 /tmp/2.txt_heard
[root@aming1 ~]# LS -bash: LS: 未找到命令
通常會壓縮文件爲.gz 配置文件爲 .conf 這個不絕對,後綴並不表明什麼, 只是看着方便
yum install -y lrzsz
sz 111.txt 就會彈出一個框,選擇把文件放到windows的哪個文件夾下。
rz 從windows上傳到linux命令。也會彈窗。上傳到當前目錄下。
_oo0oo_ 088888880 88" . "88 (| -_- |) 0\ = /0 ___/'---'\___ .' \\\\| |// '. / \\\\||| : |||//\\ /_ ||||| -:- |||||- \\ | | \\\\\\ - /// | | | \_| ''\---/'' |_/ | \ .-\__ '-' __/-. / ___'. .' /--.--\ '. .'___ ."" '< '.___\_<|>_/___.' >' "". | | : '- \'.;'\ _ /';.'/ - ' : | | \ \ '_. \_ __\ /__ _/ .-' / / ====='-.____'.___ \_____/___.-'____.-'===== '=---=' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 佛祖保佑 iii 永不死機