# Help with unix

**URL:** <https://boards.straightdope.com/t/help-with-unix/832139>\
**Category:** Factual Questions\
**Created:** [April 6, 2019, 6:30pm UTC](https://boards.straightdope.com/t/help-with-unix/832139 "2019-04-06T18:30:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hari\_Seldon](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/hari_seldon/32/5173_2.png) [@Hari\_Seldon](https://boards.straightdope.com/u/Hari_Seldon)\
**Post date:** [April 6, 2019, 6:30pm UTC](https://boards.straightdope.com/t/help-with-unix/832139/1 "2019-04-06T18:30:41Z")

</div>

There must be a simple command that asks for a list of all the subdirectories of whatever directory you are in, but I don’t know it or how to find it. I can get a listing of all the files but I cannot tell which of them (if any) is a subdirectory.

---

<div class="post-metadata">

**Author:** ![leahcim](https://avatars.discourse-cdn.com/v4/letter/l/b4bc9f/32.png) [@leahcim](https://boards.straightdope.com/u/leahcim)\
**Post date:** [April 6, 2019, 6:36pm UTC](https://boards.straightdope.com/t/help-with-unix/832139/2 "2019-04-06T18:36:37Z")

</div>

Would “ls -l . | grep ^d” work for what you need?

---

<div class="post-metadata">

**Author:** ![leahcim](https://avatars.discourse-cdn.com/v4/letter/l/b4bc9f/32.png) [@leahcim](https://boards.straightdope.com/u/leahcim)\
**Post date:** [April 6, 2019, 6:43pm UTC](https://boards.straightdope.com/t/help-with-unix/832139/3 "2019-04-06T18:43:38Z")

</div>

Missed edit window, but if you want just the names and not the rest of the ls -l output, you can append “| awk ‘{print $NF}’” to that.

---

<div class="post-metadata">

**Author:** ![beowulff](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/beowulff/32/542_2.png) [@beowulff](https://boards.straightdope.com/u/beowulff)\
**Post date:** [April 6, 2019, 6:44pm UTC](https://boards.straightdope.com/t/help-with-unix/832139/4 "2019-04-06T18:44:56Z")

</div>

ls -d \*/

---

<div class="post-metadata">

**Author:** ![leahcim](https://avatars.discourse-cdn.com/v4/letter/l/b4bc9f/32.png) [@leahcim](https://boards.straightdope.com/u/leahcim)\
**Post date:** [April 6, 2019, 6:54pm UTC](https://boards.straightdope.com/t/help-with-unix/832139/5 "2019-04-06T18:54:32Z")

</div>

> [@beowulff](#):
>
> ls -d \*/

Only if you want to do it the easy way. :smack:

---

<div class="post-metadata">

**Author:** ![echoreply](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/echoreply/32/3641_2.png) [@echoreply](https://boards.straightdope.com/u/echoreply)\
**Post date:** [April 6, 2019, 9:32pm UTC](https://boards.straightdope.com/t/help-with-unix/832139/6 "2019-04-06T21:32:07Z")

</div>

> [@beowulff](#):
>
> ls -d \*/

That is a good one. It will find all of the non-hidden directories (ones that don’t start with a “.”). A more general solution might be

```auto

find ./ -type d

```

which will show all of the subdirectories and subdirectories of subdirectories. Verbosly: find all files of the type directory (in Unix, everything is a file) starting at the current directory “./”. You can leave out the “./”, as starting at the current directory is default, but my fingers automatically type it, because they learned the command on a system where it was required.

To only show the first level of subdirectories, you can use

```auto

find ./ -maxdepth 1 -type d

```

“find” is incredibly useful and powerful, but with great power comes great complexity.  
If you only want to be able to distinguish between regular files and directories, then here are a couple good options:

```auto

 ls -CF

```

```auto

  ls -l
 

```

The first will just list names, but it will show directory names with a “/” after them. The second will list more details, such as permissions and owners. Directories will have a “d” as the first letter in the first column.

---

<div class="post-metadata">

**Author:** ![Voyager](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/voyager/32/133_2.png) [@Voyager](https://boards.straightdope.com/u/Voyager)\
**Post date:** [April 6, 2019, 11:13pm UTC](https://boards.straightdope.com/t/help-with-unix/832139/7 "2019-04-06T23:13:03Z")

</div>

In general, if you know the generic command, _ls_ in this case, man’ing that command will often give you the way to do what you want. You’re hardly the first person to want to see directories only. The same goes for nearly anything you’d want to do as a novice.  
If not, you can strong a couple of commands together to do it.

---

<div class="post-metadata">

**Author:** ![DPRK](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@DPRK](https://boards.straightdope.com/u/DPRK)\
**Post date:** [April 6, 2019, 11:31pm UTC](https://boards.straightdope.com/t/help-with-unix/832139/8 "2019-04-06T23:31:58Z")

</div>

Color-coded ls is nice if your operating system and terminal support it. For example, under Linux “ls --color” (or ls -Fa --color", etc) will list all files color-coded by type.

---

<div class="post-metadata">

**Author:** ![Hari\_Seldon](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/hari_seldon/32/5173_2.png) [@Hari\_Seldon](https://boards.straightdope.com/u/Hari_Seldon)\
**Post date:** [April 7, 2019, 3:07am UTC](https://boards.straightdope.com/t/help-with-unix/832139/9 "2019-04-07T03:07:14Z")

</div>

> [@beowulff](#):
>
> ls -d \*/

Thanks. Worked fine. No need for more complicated solutions.

TSD scores again!
