您可以通過點點滴滴對它們進行比較:
#!/bin/bash
function has_good_perm {
local FILE STAT X
for FILE; do
STAT=$(exec stat -c '%a' "$FILE")
X=${STAT:0:1}
((X & 1)) && return 1 ## False if first number has executable bit e.g. 7, 5, 1
X=${STAT:1:1}
(((X & 1) || (X & 2))) && return 1 ## False if second number has executable bit or writable bit e.g. 7, 6, 5, 3, 1
X=${STAT:2:1}
(((X & 1) || (X & 2))) && return 1
done
return 0
}
if has_good_perm /etc/file1 /etc/file2; then
echo "All files are good!"
else
echo "Something's bad."
fi
或者
function has_good_perm {
local STAT X
STAT=$(exec stat -c '%a' "$1")
X=${STAT:0:1}
((X & 1)) && return 1
X=${STAT:1:1}
(((X & 1) || (X & 2))) && return 1
X=${STAT:2:1}
(((X & 1) || (X & 2))) && return 1
return 0
}
for FILE in /etc/file1 /etc/file2; do
if has_good_perm "$FILE"; then
echo "Good file: $FILE"
else
echo "Bad file: $FILE"
fi
done
「更多permi可能比666「只是意味着」有一個執行位集「不是嗎? –
我想是的。但我需要的實際數字是644。我會改變它來反映這一點。 – michaelAdam