1. 程式人生 > >10月22日學習預習筆記

10月22日學習預習筆記

隱藏許可權lsattr_chattr

chattr 新增隱藏許可權 lsattr 檢視隱藏許可權 +i 新增無更改許可權 -i 刪除無更改許可權 +a 新增只能追加檔案內容許可權 -a 刪除只能追加檔案內容許可權,可更改時間資訊 lsattr -d 檢視目錄本身全程 -a 檢視目錄中所有檔案包含隱藏檔案 +R 檢視目錄及所有子目錄檔案許可權 [[email protected] ~]# chattr +i 123.txt 當給一個檔案新增i許可權時,檔案無法修改內容,名稱等一系列。 使用lsattr檢視隱藏許可權 [[email protected] ~]# lsattr 123.txt ----i----------- 123.txt 刪除隱藏許可權 [

[email protected] ~]# chattr -i 123.txt [[email protected] ~]# lsattr 123.txt ---------------- 123.txt

新增a許可權 [[email protected] ~]# chattr +a 123.txt [[email protected] ~]# lsattr 123.txt -----a---------- 123.txt 追加檔案內容 [[email protected] ~]# cat 123.txt fsfsdgs fsdfdsfsd [[email protected]

~]# head -n2 /var/log/messages >>123.txt [[email protected] ~]# cat 123.txt fsfsdgs fsdfdsfsd Oct 21 19:18:01 localhost rsyslogd: [origin software=“rsyslogd” swVersion=“8.24.0” x-pid=“710” x-info=“http://www.rsyslog.com”] rsyslogd was HUPed Oct 21 19:20:01 localhost systemd: Started Session 5 of user root.

對目錄 [[email protected] ~]# chattr +i 123 [[email protected] ~]# lsattr 123 ---------------- 123/456.txt lsattr預設檢視的是目錄下檔案的許可權 -d 檢視該目錄許可權 [[email protected] ~]# lsattr -d 123 ----i----------- 123 針對目錄的許可權對目錄下的檔案無效,只對目錄本身有效。

特殊許可權set_uid [[email protected] ~]# ls -l /usr/bin/passwd -rwsr-xr-x. 1 root root 27833 10月 21 21:22 /usr/bin/passwd set_uid=s 簡寫 當一個命令被該使用者賦予s許可權時,則該命令會擁有該使用者的許可權。即普通使用者擁 有該命令所有者的許可權 [[email protected] ~]$ ls /root/ ls: 無法開啟目錄/root/: 許可權不夠 增加s許可權 [[email protected] ~]# chmod u+s /usr/bin/ls [[email protected] ~]# ls -l /usr/bin/ls —sr-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls

[[email protected] ~]$ ls /root/ 1 123 123.txt anaconda-ks.cfg initial-setup-ks.cfg 減少s許可權 [[email protected] ~]# chmod u-s /usr/bin/ls [[email protected] ~]# ls -l /usr/bin/ls ----r-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls

set_gid

set_gid=s 簡寫 [[email protected] ~]# ls -l /usr/bin/ls -rwxr-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls [[email protected] ~]# chmod g+s /usr/bin/ls [[email protected] ~]# ls -l /usr/bin/ls -rwxr-sr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls 當修改某一命令為該命令的所屬組時,普通使用者使用該命令則擁有該使用者組命令許可權 [[email protected] ~]# chmod g+s /usr/bin/touch [[email protected] ~]# ls -l /usr/bin/touch —xr-sr-x. 1 root root 62488 11月 6 2016 /usr/bin/touch 普通使用者使用touch建立檔案 [[email protected] ~]$ touch 12.txt [[email protected] ~]$ ls -l 12.txt -rw-rw-r-- 1 user root 0 10月 21 22:16 12.txt

stick_bit

若一個目錄許可權為777,則其他使用者對於目錄下的檔案及資料夾都具備修改許可權 [[email protected] /]# ls -ld tmp/ drwxrwxrwt. 30 root root 4096 10月 21 23:21 tmp/ t許可權為防刪除許可權

軟連結檔案

軟連結指向原檔案 lrwxrwxrwx. 1 root root 18 10月 18 05:28 libxcb-xv.so.0 -> libxcb-xv.so.0.0.0

新建軟連結 ln -s [[email protected] tmp]# ln -s /tmp/yum.log /root/123/ [[email protected] 123]# ls -l /root/123/yum.log lrwxrwxrwx 1 root root 12 10月 21 23:28 /root/123/yum.log -> /tmp/yum.log 注意事項:做軟連結時原檔案儘量使用絕對路徑 實用例項 當log檔案佔用磁碟空間過大時,可以將log檔案移動到剩餘磁碟大的分割槽,隨後對移動後的檔案建立軟連結指向原目錄既可。 [[email protected] 123]# cp /tmp/yum.log /home/ [[email protected] 123]# rm -rf /tmp/yum.log [[email protected] 123]# ln -s /home/yum.log /tmp/ [[email protected] 123]# ls -l /tmp/yum.log lrwxrwxrwx 1 root root 13 10月 21 23:44 /tmp/yum.log -> /home/yum.log

硬連結檔案

硬連結不支援對目錄做連結,只支援檔案。做的硬連結可以刪除,存在inode相同檔案既可。 建立硬連結檔案 [[email protected] home]# ln 123.txt 1_heard.txt [[email protected] home]# ls -l 總用量 12 -rw-r–r-- 2 root root 12 10月 19 11:20 123.txt -rw-r–r-- 2 root root 12 10月 19 11:20 1_heard.txt inode號相同即檔案相同 注意事項:硬連結不能跨分割槽,不能對目錄連結

lunux遠端快捷鍵 ctrl+l 清屏 ctrl+d 退出遠端連線 ctrl+c 取消命令進入下一行 ctrl+u 清除本行無用命令,往游標前刪除 ctrl+e 游標移動到末尾 ctrl+a 游標移動到開頭 ctrl+s 鎖定遠端連線 ctrl+q 解除遠端鎖定

locate 模糊搜尋檔案命令 [[email protected] home]# yum -y install locate 使用yum安裝 [[email protected] home]# updatedb 使用命令建立db資料庫 [[email protected] ~]# locate 123 此搜尋不夠精確 /usr/share/man/man1/perl5123delta.1.gz /usr/share/man/zh_CN/man1/mpg123.1.gz

find

-name 查詢指定檔案及目錄名 -type 與下面屬性組合使用 -d 查詢目錄 -f 查詢檔案 -o 表示或者 -inum 指定inode查詢檔案 -mtiem 指定時間查詢 最小為1天 -mmin 指定時間查詢 最小為1分鐘 -exec 可在查詢檔案後執行指定命令 -size 指定檔案大小查詢

[[email protected] ~]# find / -name ‘123’ 查詢指定檔案及目錄名 /home/123

[[email protected] ~]# find /etc/ -type d -name ‘network*’ 指定查詢目錄 /etc/selinux/targeted/active/modules/100/networkmanager /etc/sysconfig/network-scripts /etc/libvirt/qemu/networks

[[email protected] ~]# find /etc/ -type f -name ‘network*’ 指定查詢檔案 /etc/sysconfig/network-scripts/network-functions /etc/sysconfig/network-scripts/network-functions-ipv6

stat 檢視檔案具體資訊

[[email protected] ~]# stat /home/123/3.txt 檔案:"/home/123/3.txt" 大小:0 塊:0 IO 塊:4096 普通空檔案 裝置:fd02h/64770d Inode:8409200 硬連結:1 許可權:(0644/-rw-r–r--) Uid:( 0/ root) Gid:( 0/ root) 環境:unconfined_u:object_r:home_root_t:s0 最近訪問:2018-10-23 12:57:08.797447557 +0800 最近更改:2018-10-23 12:57:08.797447557 +0800 最近改動:2018-10-23 12:57:08.797447557 +0800 建立時間:- 英文顯示 [[email protected] ~]# stat /home/123/3.txt File: ‘/home/123/3.txt’ Size: 7 Blocks: 8 IO Block: 4096 regular file Device: fd02h/64770d Inode: 8409200 Links: 1 Access: (0644/-rw-r–r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:home_root_t:s0 Access: 2018-10-23 13:16:38.695908907 +0800 Modify: 2018-10-23 13:16:33.634703842 +0800 Change: 2018-10-23 13:16:33.634703842 +0800

-atimg 最近訪問時間 -mtime 最近更改時間 -ctime 最近改動時間

[[email protected] ~]# cat /home/123/3.txt 12efrg 12efrg [[email protected] ~]# stat /home/123/3.txt File: ‘/home/123/3.txt’ Size: 14 Blocks: 8 IO Block: 4096 regular file Device: fd02h/64770d Inode: 8409200 Links: 1 Access: (0700/-rwx------) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:home_root_t:s0 Access: 2018-10-23 13:21:22.984349917 +0800 Modify: 2018-10-23 13:18:44.162962561 +0800 Change: 2018-10-23 13:20:29.658205286 +0800 Birth: -

此時最近訪問時間變化

[[email protected] ~]# echo “12efrg” >> /home/123/3.txt 追加內容到3.txt [[email protected] ~]# stat /home/123/3.txt File: ‘/home/123/3.txt’ Size: 14 Blocks: 8 IO Block: 4096 regular file Device: fd02h/64770d Inode: 8409200 Links: 1 Access: (0644/-rw-r–r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:home_root_t:s0 Access: 2018-10-23 13:16:38.695908907 +0800 Modify: 2018-10-23 13:18:44.162962561 +0800 Change: 2018-10-23 13:18:44.162962561 +0800 Birth: -

此時最近更改和改動時間都有變化

[[email protected] ~]# chmod 700 /home/123/3.txt 修改檔案許可權 [[email protected] ~]# stat /home/123/3.txt File: ‘/home/123/3.txt’ Size: 14 Blocks: 8 IO Block: 4096 regular file Device: fd02h/64770d Inode: 8409200 Links: 1 Access: (0700/-rwx------) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:home_root_t:s0 Access: 2018-10-23 13:16:38.695908907 +0800 Modify: 2018-10-23 13:18:44.162962561 +0800 Change: 2018-10-23 13:20:29.658205286 +0800 Birth: -

此時最近改動時間變化

得出如檢視檔案內容是則最近訪問時間變化,如追加了檔案的內容則最近更改時間與最近改動時間都會變化,如修改了許可權及增減了檔案 內容則最近改動時間變化。

[[email protected] ~]# find /etc/ -type f -mtime -1 查詢1天以內更改的檔案 /etc/resolv.conf /etc/cups/subscriptions.conf [[email protected] ~]# ls -l /etc/resolv.conf -rw-r–r--. 1 root root 57 Oct 23 12:41 /etc/resolv.conf

[[email protected] ~]# find /etc/ -type f -mtime +100 查詢100天以前修改的檔案 /etc/nfsmount.conf /etc/fcoe/cfg-ethx [[email protected] ~]# ls -l /etc/fcoe/cfg-ethx -rw-r–r--. 1 root root 678 Aug 8 2017 /etc/fcoe/cfg-ethx

[[email protected] ~]# find /etc/ -type f -atime +100 查詢1000天以前訪問的檔案 /etc/setuptool.d/99timeconfig [[email protected] ~]# ls -l /etc/setuptool.d/99timeconfig -rw-r–r--. 1 root root 44 Jun 10 2014 /etc/setuptool.d/99timeconfig

[[email protected] ~]# find /etc/ -type f -atime -10 查詢10天以內訪問的檔案 /etc/gdm/custom.conf /etc/nfs.conf

[[email protected] ~]# stat /etc/nfs.conf File: ‘/etc/nfs.conf’ Size: 955 Blocks: 8 IO Block: 4096 regular file Device: fd00h/64768d Inode: 18370521 Links: 1 Access: (0644/-rw-r–r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: system_u:object_r:etc_t:s0 Access: 2018-10-18 05:39:31.017360770 +0800 Modify: 2017-08-08 05:18:02.000000000 +0800 Change: 2018-10-18 05:31:54.888016974 +0800 Birth: -

並行查詢檔案 [[email protected] ~]# find /etc/ -type f -mtime -1 -name ‘*.conf’ 查詢一天以內被改動且名字以.conf結尾的檔案 /etc/resolv.conf /etc/cups/subscriptions.conf

或查詢檔案 [[email protected] ~]# find /etc/ -type f -o -mtime -1 -o -name ‘*.conf’ 查詢一天以內改動的檔案或查詢名字為.conf結尾的檔案 /etc/nfsmount.conf /etc/fcoe/cfg-ethx

[[email protected] ~]# find /root/ -type f -mmin -200 查詢200分鐘以內更改的檔案 /root/.cache/abrt/lastnotification /root/12345.txt

查詢檔案並且執行相關命令 [[email protected] ~]# find /root/ -type f -mmin -200 -exec ls -l {} ; 查詢200分鐘以內更改的檔案並且檢視其檔案屬性 -rw-------. 1 root root 11 Oct 23 12:41 /root/.cache/abrt/lastnotification -rwxrwxrwx. 1 root root 25 Oct 23 13:32 /root/12345.txt

[[email protected] ~]# find /root/ -type f -mmin -100 /root/12345.txt /root/qaa.txt /root/wss.txt [[email protected] ~]# find /root/ -type f -mmin -100 -exec mv {} {}.bak ; [[email protected] ~]# find /root/ -type f -mmin -100 /root/12345.txt.bak /root/qaa.txt.bak /root/wss.txt.bak

{}一個方括號等於一個檔案 當命令中存在一個方括號時,應加上原命令如ls -l 所以可以對兩個檔案執行

[[email protected] ~]# find /root/ -type f -mmin -200 -exec cat {} ; 查詢200分鐘以內更改的檔案並且檢視其內容 1540269715 12efrg 12efr eretg qadsd [[email protected] ~]# cat /root/.cache/abrt/lastnotification 1540269715 [[email protected] ~]# cat /root/12345.txt 12efrg 12efr eretg qadsd

[[email protected] ~]# find /root/ -type f -size -10k 指定查詢檔案大小小於為10kb的檔案 /root/.bash_logout /root/.bash_profile /root/.bashrc /root/.cshrc

[[email protected] ~]# find /root/ -type f -size -10k -exec ls -l {} ; -rw-r–r--. 1 root root 18 Dec 29 2013 /root/.bash_logout -rw-r–r--. 1 root root 176 Dec 29 2013 /root/.bash_profile -rw-r–r--. 1 root root 176 Dec 29 2013 /root/.bashrc -rw-r–r--. 1 root root 100 Dec 29 2013 /root/.cshrc

[[email protected] ~]# find /etc/ -type f -size +1M -exec ls -l {} ; 查詢檔案大小大於1M的檔案 -r–r--r–. 1 root root 7503912 Oct 18 05:39 /etc/udev/hwdb.bin -rw-r–r--. 1 root root 3752457 Aug 6 2017 /etc/selinux/targeted/active/policy.kern -rw-r–r--. 1 root root 1402267 Aug 6 2017 /etc/selinux/targeted/contexts/files/file_contexts.bin

檔名字尾

[[email protected] ~]# LANG=en 修改預設語言為英語 [[email protected] ~]# LANG=zh_CN.UTF-8 修改預設語言為漢語 修改語言的前提是需要有語言的支援,在系統安裝時需要選擇相關語言