為什麼我不能像之前那樣 chmod 這些檔案?

為什麼我不能像之前那樣 chmod 這些檔案?

我試圖為資料夾中的 sh 檔案添加執行權限。為此,我錯誤地使用了:

find . -print0 -iname '*.sh' | xargs -0 chmod -v 744

輸出是:

mode of `.' changed from 0755 (rwxr-xr-x) to 0744 (rwxr--r--)
mode of `./codis.sh' changed from 0644 (rw-r--r--) to 0744 (rwxr--r--)
mode of `./ne fil.sw' changed from 0644 (rw-r--r--) to 0744 (rwxr--r--)
mode of `./.whois1.sh.swo' changed from 0644 (rw-r--r--) to 0744 (rwxr--r--)
mode of `./new file' changed from 0644 (rw-r--r--) to 0744 (rwxr--r--)
mode of `./ezik.sh' changed from 0644 (rw-r--r--) to 0744 (rwxr--r--)
mode of `./.whois1.sh.swp' changed from 0600 (rw-------) to 0744 (rwxr--r--)
mode of `./whois1.sh' retained as 0744 (rwxr--r--)

我現在知道 find 部分的正確用法是

find . -iname '*.sh' -print0

所以我創建了另一個像這樣的發現:

find . \! -iname '*.sh' -print0 | xargs -0 chmod 600

這樣我就可以設定非 sh 檔案的權限(是的,我看到有些檔案有 644 權限,而不是 600,但現在沒關係)。該命令的輸出是:

chmod: cannot access `./ne fil.sw': Permission denied
chmod: cannot access `./.whois1.sh.swo': Permission denied
chmod: cannot access `./new file': Permission denied
chmod: cannot access `./.whois1.sh.swp': Permission denied

我也用過sudo,但是還是沒啥效果…

我發現我沒有正確理解權限...如果我理解正確,我也需要x目錄的權限direc才能在所述目錄中執行命令。

答案1

您的findcmd 也會找到目前目錄“ .”。然後,該目錄的權限將被設定為600,因此您將失去存取該目錄中檔案的權限。

所以cd ..chmod 700說目錄,然後運行你的恢復find,它現在排除當前目錄,如下所示:

find . \! -path . \! -iname '*.sh' -print0 | xargs -0 chmod 600

相關內容