Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

132
Visualizações
Count the number of subdirectories without the execute bit

How can I count the number of subdirectories that don't have the execute bit set?

This is my attempt but is there a better or more elegant way?

count=0; for d in */; do [[ -d $d && ! -x $d ]] && (( ++count )); done
printf %s\\n "$count"

My main interest is in checking if the execute bit is not set for all. That is not just for the current user.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

The following counts directories without executable bit for current user:

find . -mindepth 1 -maxdepth 1 -type d '!' -executable -printf . | wc -c

The following counts directories that have 0 executable bits:

find . -mindepth 1 -maxdepth 1 -type d '!' -perm /111 -printf . | wc -c

The following counts directories that have 2 or less executable bits set:

find . -mindepth 1 -maxdepth 1 -type d '!' -perm -111 -printf . | wc -c

Parts from 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.
over 4 years ago · Santiago Trujillo Relatório

0

This oneliner should do. Add a | wc -l at the end if you want to just count the number:

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

And the result:

/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
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda