¿Cómo puedo contar la cantidad de subdirectorios que no tienen el bit de ejecución establecido?
Este es mi intento, pero ¿hay una manera mejor o más elegante?
count=0; for d in */; do [[ -d $d && ! -x $d ]] && (( ++count )); done printf %s\\n "$count" Mi principal interés es verificar si el bit de ejecución no está configurado para all . Eso no es solo para el usuario actual.
Lo siguiente cuenta directorios sin bit ejecutable para el usuario actual:
find . -mindepth 1 -maxdepth 1 -type d '!' -executable -printf . | wc -cLo siguiente cuenta directorios que tienen 0 bits ejecutables:
find . -mindepth 1 -maxdepth 1 -type d '!' -perm /111 -printf . | wc -cLo siguiente cuenta directorios que tienen 2 o menos bits ejecutables configurados:
find . -mindepth 1 -maxdepth 1 -type d '!' -perm -111 -printf . | wc -c Partes del 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.
Este oneliner debería servir. Agregar un | wc -l al final si solo quieres contar el número:
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'; doneY el resultado:
/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