counting number of directories in a specific directory

后端 未结 15 2236
被撕碎了的回忆
被撕碎了的回忆 2020-12-22 21:06

How to count the number of folders in a specific directory. I am using the following command, but it always provides an extra one.

find /directory/ -maxdept         


        
15条回答
  •  一个人的身影
    2020-12-22 21:28

    Using zsh:

    a=(*(/N)); echo ${#a}
    

    The N is a nullglob, / makes it match directories, # counts. It will neatly cope with spaces in directory names as well as returning 0 if there are no directories.

提交回复
热议问题