溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

chmod+find如何批量授權(quán)

發(fā)布時間:2022-01-14 09:21:58 來源:億速云 閱讀:147 作者:小新 欄目:大數(shù)據(jù)

這篇文章將為大家詳細(xì)講解有關(guān)chmod+find如何批量授權(quán),小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

這兩張圖是test 這個文件夾下的目錄結(jié)構(gòu)圖以及權(quán)限圖。那么接下來我要將test這個目錄以及子目錄的所有.sh 的文件設(shè)置為只有可執(zhí)行權(quán)限要怎么設(shè)置呢?執(zhí)行以下命令后會發(fā)現(xiàn) tesh.sh 和./test1/test1.sh 的權(quán)限已經(jīng)變成---x--x--x 而其它保持不變

find . -name "*.sh" -exec chmod 111 {} \;
total 0
drwxr-xr-x 2 root root 38 Sep 29 10:31 test1
drwxr-xr-x 2 root root  6 Sep 29 10:13 test2
-rw-r--r-- 1 root root  0 Sep 29 10:38 test.bash
---x--x--x 1 root root  0 Sep 29 10:22 test.sh
-rw-r--r-- 1 root root  0 Sep 29 10:38 test.tx

find .  -name "*.sh"  與 find . -name *.sh 的區(qū)別是少了個雙引號,結(jié)果就是一個遞歸,一個不遞歸。

有人會說了 chmod 有個 -R 參數(shù)就可以實現(xiàn)遞歸了。 但是chmod -R 實現(xiàn)的是無差別攻擊所以并不適用,以上授權(quán)命令還可以寫成這樣。效果上是一樣的。

把 文件里面.txt 改成執(zhí)行權(quán)限

[root@oracle1 test]# chmod 111 `find . -name "*.txt"`
[root@oracle1 test]# ll
total 0
d--x--x--x 2 root root 38 Sep 29 10:31 test1
d--x--x--x 2 root root  6 Sep 29 10:13 test2
-rw-r--r-- 1 root root  0 Sep 29 10:38 test.bash
---x--x--x 1 root root  0 Sep 29 10:22 test.sh
---x--x--x 1 root root  0 Sep 29 10:38 test.txt

那么問題又來了 我一個目錄下要是只有文件與文件夾的區(qū)別呢?  好的 ,這個時候你就可以用 find  命令的 -type 參數(shù)了 type 后面 d代表目錄,f 代表 文件

給文件設(shè)置為只有可執(zhí)行權(quán)限

[root@oracle1 test]# chmod 111 `find . -type f`
[root@oracle1 test]# ll
total 0
d--x--x--x 2 root root 38 Sep 29 10:31 test1
d--x--x--x 2 root root  6 Sep 29 10:13 test2
---x--x--x 1 root root  0 Sep 29 10:38 test.bash
---x--x--x 1 root root  0 Sep 29 10:22 test.sh
---x--x--x 1 root root  0 Sep 29 10:38 test.txt

給目錄設(shè)置為755權(quán)限

[root@oracle1 test]# chmod 755 `find . -type d`
[root@oracle1 test]# ll
total 0
drwxr-xr-x 2 root root 38 Sep 29 10:31 test1
drwxr-xr-x 2 root root  6 Sep 29 10:13 test2
---x--x--x 1 root root  0 Sep 29 10:38 test.bash
---x--x--x 1 root root  0 Sep 29 10:22 test.sh
---x--x--x 1 root root  0 Sep 29 10:38 test.txt

關(guān)于“chmod+find如何批量授權(quán)”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI