How can I find all immediate sub-directories of the current directory on Linux?
Typing just "ls" will give you a list of all the files and subdirectories in the current directory.
Substitute dir /A:D. /B /S > FolderList. txt to produce a list of all folders and all subfolders of the directory. WARNING: This can take a while if you have a large directory.
The dir command displays a list of files and subdirectories in a directory. With the /S option, it recurses subdirectories and lists their contents as well.
The simplest way is to exploit the shell globbing capabilities by writing echo */.
If you like to use ls, e.g. to apply formatting/sorting options, make it ls -d */.
Explanation:
-d: list directories themselves, not their contentsIf you just need to get a list of sub directories (without caring about the language/tool to use) find is the command that you need.
It's able to find anything in a directory tree.
If by immediate you mean that you need only the child directories, but not the grandchild -maxdepth option will do the trick. Then -type will let you specify that you are only looking for directories:
find YOUR_DIRECTORY -type d -maxdepth 1 -mindepth 1
You can also use the below -
$ ls -l | grep '^d'
Brief explanation: As in long listing, the directories start with 'd', so the above command (grep) filters out those result, that start with 'd', which are nothing but directories.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With