Is there a bash equivalent of zsh file type?

In zsh, you can qualify globs with file type statements, for example. *(/) matches only directories, *(.) only normal files, is there a way to do the same in bash without resorting to searching?

+4
source share
2 answers

you can try

 ls -ltrd */ #match directories using -d and the slash "/" 

or

 echo */ 

or

 for dir in */ do ... done 

If you need to make it recursive and you have Bash 4+

 $ shopt -s globstar $ for dir in **/*/; do echo $dir; done 
+3
source

I don’t think there is a way to do this directly, but don’t forget that you can use the test -d and -f options to determine if the name refers to a directory or file.

 for a in *; do if [ -d "$a" ]; then echo Directory: $a elif [ -f "$a" ]; then echo File: $a fi done 
0
source

All Articles