關於find的-perm


關於find的-perm

參考關於find命令-perm 的用法

總結

有三種用法

  • find -perm -mode
  • find -perm mode
  • find -perm /mode(find -perm +mode已經廢棄)

第一種

find -perm -mode

-mode表示完全滿足mode權限。

搜索的文件權限可以比mode高

比如mode位644,那么可以搜索到644的,744的,666的,777也行,比644高就行

比如,我要/etc目錄下權限至少是755的普通文件,

會發現,755的也滿足要求

[root@centos7 ~]# find /etc/ -perm -011  -type f -print0 | xargs -0 ls -ldh
-rwxr-xr-x. 1 root root 1.3K Oct 31  2018 /etc/auto.net
-rwxr-xr-x. 1 root root  687 Oct 31  2018 /etc/auto.smb
...

查找/etc⽬錄下⾄少有⼀類⽤戶沒有執⾏權限的⽂件

先查找所有用戶都有執行權限的,再取反

[root@centos7 tmp]# find /etc/ \( -not -perm -111 \)  -type f -print0 | xargs -0 ls -ldh | more
-rw-r--r--. 1 root root      850 Nov 14  2018 /etc/abrt/abrt-action-save-package-data.conf
-rw-r--r--. 1 root root     2.1K Nov 14  2018 /etc/abrt/abrt.conf

查找/tmp⽬錄下,所有⽤戶都有執⾏權限,且其它⽤戶有寫權限的⽂件

[root@centos7 tmp]# find /tmp   -perm -113  -type f -print0 | xargs -0 ls -ldh
-rwx--x-wx 1 root root 0 Aug  3 11:18 /tmp/111.txt

第二種

find -perm mode

這樣就表示完全匹配了

我要755的,就給我755,要644的就給我644

比如:我只要/etc/目錄下面權限為755的普通文件

會發現,所有搜到的文件權限都是755

[root@centos7 ~]# find /etc/ -perm 755  -type f -print0 | xargs -0 ls -ldh
-rwxr-xr-x. 1 root root 1.3K Oct 31  2018 /etc/auto.net
-rwxr-xr-x. 1 root root  687 Oct 31  2018 /etc/auto.smb
...

第三種

find -perm /mode

/mode表示部分滿足即可

我要755的,那么111的也行,100的也行,但022的不行,因為022(-----w--w-)兩個位置不符合要求,不是我要的

例如:查找/tmp目錄下面有執行權限的文件,不管什么用戶有都行

可以看到,不管是001的,755的,都找到了

[root@centos7 tmp]# find /tmp/ -perm /111  -type f -print0 | xargs -0 ls -ldh
-rwxr--r-- 1 root root   0 Aug  3 11:06 /tmp/10.txt
-rwxr-xr-x 1 root root   0 Aug  3 11:07 /tmp/6.txt
---------x 1 root root   0 Aug  3 11:07 /tmp/8.txt
...

例如:查找/etc目錄下面所有用戶都沒有寫權限的文件

取反即可

[root@centos7 tmp]# find /etc/ \( -not -perm /111 \)  -type f -print0 | xargs -0 ls -ldh | more
-rw-r--r--. 1 root root      850 Nov 14  2018 /etc/abrt/abrt-action-save-package-data.conf
-rw-r--r--. 1 root root     2.1K Nov 14  2018 /etc/abrt/abrt.conf
...

例如:查找/etc目錄下面s所有用戶都沒有寫權限的文件

[root@centos7 tmp]# find /etc/ \( -not -perm /222 \)  -type f -print0 | xargs -0 ls -ldh | more
-r--r--r--. 1 root root  460 Apr 11  2018 /etc/dbus-1/system.d/cups.conf
----------  1 root root  819 Aug  2 15:04 /etc/gshadow
----------. 1 root root  828 Aug  2 15:04 /etc/gshadow-
...


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM