How To List Directories in a Directory in Unix

Another quick answer to the question I see a lot in search queries on this blog: listing directories in a directory. I take it that this question means showing a list of only the directories and not other files under a certain location of your Unix filesystem.

Using find to show only directories

find command helps you show only the directories by using a -type d parameter.

Compare the default find output of finding files and directories under /etc/mysql:

ubuntu# find /etc/mysql 

To the one which only shows you the directories:

ubuntu# find /etc/mysql -type d

And if you’re in doubt, you can always use ls -ld command to confirm that returned entries are really standard Unix directories:

ubuntu# ls -ld /etc/mysql /etc/mysql/conf.d
drwxr-xr-x 3 root root 4096 2008-03-28 07:56 /etc/mysql
drwxr-xr-x 2 root root 4096 2008-03-25 21:06 /etc/mysql/conf.d

That’s it! Have fun with Unix!

See also

  • How to Find a Location of a Directory in Unix
  • Unix Commands: find
  • How To Find the Largest Files in Your Unix
  • find command

Keep Learning with Me

Follow me on Facebook and Twitter or jump into Telegram chat!:
I'm using Brave browser
Give it a try, it's awesome: Brave Browser
IT Consultancy
I'm a principal consultant with Tech Stack Solutions. I help with cloud architectrure, AWS deployments and automated management of Unix/Linux infrastructure. Get in touch!

Recent Tweets