How can I find all direct subdirectories of the current directory in Linux?

How can I find all direct subdirectories of the current directory in Linux?

+7
source share
4 answers

Use ls -d */ .

Explanation:

  • -d will make ls print directory names instead of their contents.
  • A slash ensures that only directories are considered, not files.
+11
source

If you just need to get a list of helper directories (without worrying about the language / tool to use) find is the command you need.

It can find anything in the directory tree.

If by immediate you mean that you only need child directories, but not the grandchild -maxdepth option will do the trick. Then -type will let you indicate that you are only looking for directories:

 find YOUR_DIRECTORY -type d -maxdepth 1 -mindepth 1 
+5
source

You can also use below -

 $ ls -l | grep '^d' 

Short explanation: as in a long listing, directories start with 'd', so the above command ( grep ) filters out results that start with 'd', which are nothing more than directories.

+1
source

Use this

ls | grep / $

grep will find anything ending in / which directories do.

-one
source

All Articles