how count number of folders in specific directory. using following command, provides one.
find /directory/ -maxdepth 1 -type d -print| wc -l
for example, if have 3 folders, command provides 4. if contains 5 folders, command provides 6. why that?
find
printing directory itself:
$ find .vim/ -maxdepth 1 -type d .vim/ .vim/indent .vim/colors .vim/doc .vim/after .vim/autoload .vim/compiler .vim/plugin .vim/syntax .vim/ftplugin .vim/bundle .vim/ftdetect
you can instead test directory's children , not descend them @ all:
$ find .vim/* -maxdepth 0 -type d .vim/after .vim/autoload .vim/bundle .vim/colors .vim/compiler .vim/doc .vim/ftdetect .vim/ftplugin .vim/indent .vim/plugin .vim/syntax $ find .vim/* -maxdepth 0 -type d | wc -l 11 $ find .vim/ -maxdepth 1 -type d | wc -l 12
you can use ls
:
$ ls -l .vim | grep -c ^d 11 $ ls -l .vim total 52 drwxrwxr-x 3 anossovp anossovp 4096 aug 29 2012 after drwxrwxr-x 2 anossovp anossovp 4096 aug 29 2012 autoload drwxrwxr-x 13 anossovp anossovp 4096 aug 29 2012 bundle drwxrwxr-x 2 anossovp anossovp 4096 aug 29 2012 colors drwxrwxr-x 2 anossovp anossovp 4096 aug 29 2012 compiler drwxrwxr-x 2 anossovp anossovp 4096 aug 29 2012 doc -rw-rw-r-- 1 anossovp anossovp 48 aug 29 2012 filetype.vim drwxrwxr-x 2 anossovp anossovp 4096 aug 29 2012 ftdetect drwxrwxr-x 2 anossovp anossovp 4096 aug 29 2012 ftplugin drwxrwxr-x 2 anossovp anossovp 4096 aug 29 2012 indent drwxrwxr-x 2 anossovp anossovp 4096 aug 29 2012 plugin -rw-rw-r-- 1 anossovp anossovp 2505 aug 29 2012 readme.rst drwxrwxr-x 2 anossovp anossovp 4096 aug 29 2012 syntax $ ls -l .vim | grep ^d drwxrwxr-x 3 anossovp anossovp 4096 aug 29 2012 after drwxrwxr-x 2 anossovp anossovp 4096 aug 29 2012 autoload drwxrwxr-x 13 anossovp anossovp 4096 aug 29 2012 bundle drwxrwxr-x 2 anossovp anossovp 4096 aug 29 2012 colors drwxrwxr-x 2 anossovp anossovp 4096 aug 29 2012 compiler drwxrwxr-x 2 anossovp anossovp 4096 aug 29 2012 doc drwxrwxr-x 2 anossovp anossovp 4096 aug 29 2012 ftdetect drwxrwxr-x 2 anossovp anossovp 4096 aug 29 2012 ftplugin drwxrwxr-x 2 anossovp anossovp 4096 aug 29 2012 indent drwxrwxr-x 2 anossovp anossovp 4096 aug 29 2012 plugin drwxrwxr-x 2 anossovp anossovp 4096 aug 29 2012 syntax
Comments
Post a Comment