2

I'd like to know the command to get a list of the current directories in a directory which satisfies the following conditions:

  • It excludes hidden directories
  • Directories with spaces are not broken up into multiple entries
  • Files (and hidden files) are not included in the list

(I intend to iterate over this list in a bash script)

ndrizza
  • 2,865
  • 6
  • 24
  • 40

2 Answers2

3

You can use this for listing:

shopt -u dotglob
printf "%s\n" */

shopt -u dotglob makes sure to not to match hidden directories.

To iterate you can do:

for d in */; do
    echo "${d%/}"
done
anubhava
  • 664,788
  • 59
  • 469
  • 547
-1
find . -maxdepth 1 ! -name '.*' -type d

Matches all your needs

Bity
  • 43
  • 1
  • 6