-1

I need help. How to write script displaying all subdirectories in the location. I've got something like that:

ls -al | grep ^d

but it only works in the home directory

jww
  • 97,681
  • 90
  • 411
  • 885
Roundstic
  • 21
  • 3
  • 1
    Duplicate of [List sub-directories with ls](https://stackoverflow.com/q/5168071/608639), [Listing only directories using ls in Bash](https://stackoverflow.com/q/14352290/608639), etc. – jww Dec 25 '19 at 22:23

1 Answers1

0

find(1) may be a better choice here:

find . -type d

which would list all directories from the current directory and all subdirectories.

P.P
  • 117,907
  • 20
  • 175
  • 238
  • It does not appear the OP wants to descend into all subdirectories. – jww Dec 25 '19 at 22:24
  • Apparently, I can't mind read as well as you do. – P.P Dec 25 '19 at 22:27
  • No oculus is necessary. OP said *"all subdirectories in the location"*. You don't go below the current location. That equates to a `maxdepth=1` in your `find` command. I'm not clear on which location, but that's a different matter. In the end, the question is yet another off-topic, no effort dump that should be closed. – jww Dec 25 '19 at 22:32
  • 1
    I don't read such conclusivity in the question. But you're entitled to your opinion and there's a *possibility* that what you are saying is what OP really meant/wanted. – P.P Dec 25 '19 at 22:48
  • again, the script only works in the location where I created it – Roundstic Dec 25 '19 at 23:09
  • @Roundstic That dot (`.`) says the "current directory". You can instead specify any other directory. – P.P Dec 30 '19 at 09:45