如何計算沒有設定執行位的子目錄的數量?
這是我的嘗試,但有更好或更優雅的方法嗎?
count=0; for d in */; do [[ -d $d && ! -x $d ]] && (( count )); done
printf %s\\n "$count"
我的主要興趣是檢查是否未為all. 這不僅適用于當前用戶。
uj5u.com熱心網友回復:
以下為當前用戶計算沒有可執行位的目錄:
find . -mindepth 1 -maxdepth 1 -type d '!' -executable -printf . | wc -c
以下計算具有 0 個可執行位的目錄:
find . -mindepth 1 -maxdepth 1 -type d '!' -perm /111 -printf . | wc -c
以下對設定了 2 個或更少可執行位的目錄進行計數:
find . -mindepth 1 -maxdepth 1 -type d '!' -perm -111 -printf . | wc -c
零件來自man find:
-perm /mode Any of the permission bits mode are set for the file. -perm -mode All of the permission bits mode are set for the file. -executable Matches files which are executable and directories which are searchable (in a file name resolution sense) by the current user.
uj5u.com熱心網友回復:
這個oneliner應該可以。| wc -l如果您只想計算數字,請在末尾添加一個:
ls | while read dir; do stat --printf="%A %n\n" "$dir" | grep '^d' | grep -v '^d..x......' | grep -v '^d.....x...' | grep -v '^d........x'; done
結果:
/tmp % mkdir b
/tmp % mkdir c
/tmp % chmod 600 a
/tmp % chmod 060 a
/tmp % chmod 600 a
/tmp % chmod 060 b
/tmp % chmod 006 c
/tmp % ls | while read dir; do stat --printf="%A %n\n" "$dir" | grep '^d' | grep -v '^d..x......' | grep -v '^d.....x...' | grep -v '^d........x'; done
drw------- a
d---rw---- b
d------rw- c
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/373330.html
