
我怎麼才能找到目錄結構中不均勻的檔案/目錄權限?我已經嘗試使用類似於以下的 find 命令:
find /bin ! \( -perm 777 -o -perm 776 -o -perm 775 -o -perm 774 -o -perm 773 -o -perm 772 -o -perm 771 -o -perm 770 -o -perm 760 -o -perm 750 -o -perm 740 -o -perm 730 -o -perm 720 -o -perm 710 -o -perm 700 -o -perm 600 -o -perm 500 -o -perm 400
但在完成剩餘的排列加上一個之前我用完了命令列-exec ls -lL {} \;
我也一直在做類似的手動事情:
ls -lL /bin | grep -v ^-rwxr-xr-x | grep -v ^-rwx--x--x | grep -v ^-rwsr-xr-x | grep -v ^-r-xr-xr-x | grep -v ^-rwxr-xr-t
但同樣,在完成剩餘的排列之前,我用完了命令列。
這兩種方法看起來都異常尷尬。有沒有更好、更快、更簡單的方法?請注意,我在使用的 shell (sh) 和平台 (Irix 6.5.22) 中受到限制。
答案1
您在尋找可執行檔嗎?
find . -type f -perm /+x
無論如何, / 模式很可能是你的朋友......這是手冊頁:
-perm /mode
Any of the permission bits mode are set for the file. Symbolic modes are accepted in this form. You must specify `u', `g' or `o' if you use a symbolic mode. See the
EXAMPLES section for some illustrative examples. If no permission bits in mode are set, this test matches any file (the idea here is to be consistent with the behaviour
of -perm -000).
更新:對,我雖然你正在尋找奇數(可執行的)...
這應該可以工作(仍然使用 find 中的第三個 perm 參數
樣本資料:
$ ls
000 001 002 003 004 005 006 007 010 020 030 040 050 060 070 100 200 300 400 500 600 700
尋找命令:
$ find . -type f \( -perm /u-x,g+x -o -perm /u-w,g+w -o -perm /u-r,g+r -o -perm /g-x,o+x -o -perm /g-w,o+w -o -perm /g-r,o+r -o -perm /u-x,o+x -o -perm /u-w,o+w -o -perm /u-r,o+r \) | sort
./001
./002
./003
./004
./005
./006
./007
./010
./020
./030
./040
./050
./060
./070
基本上你是說,給我其中群組具有權限但所有者沒有的文件,或者世界具有權限但群組沒有的文件,或者世界具有權限但所有者沒有的文件。
注意:find 有 3 個 perm 參數;
- 燙髮模式
- 燙髮模式
- 燙髮/模式
ps我不太確定這個的價值.....