Test your skills on our all Hosting services and get 15% off!

Use code at checkout:

Skills
02.09.2025

How to list directories in linux ?

Working in Linux often feels like navigating a vast library. Instead of shelves, you have directories (folders), and instead of books, you have files. To be effective as a system administrator, developer, or even a curious beginner, you need to master the basics of finding your way around this structure. One of the most important skills is learning how to list directories. This article will walk you through different approaches, explain their pros and cons, and show you when each method makes sense.

Why listing directories is important

On a personal computer, you may only occasionally peek into your “Documents” or “Downloads” folder. On a server, however, directories are at the heart of daily tasks:

  • System administration: quickly check what lives in /etc/ or /var/log/.
  • Web hosting: find project folders in /var/www/.
  • Development: identify hidden directories such as .git/ or .venv/.
  • Security: confirm what’s installed and running on the system.

In short: if you don’t know how to list directories efficiently, you’ll always feel lost.

The simplest way: ls

The ls command is the default tool to display the contents of a folder. Run it with no arguments:

ls

This shows both files and directories. If you want to see only directories:

ls -d */

Here’s what’s happening:

  • -d tells ls not to dive into each directory.
  • */ is a shell pattern that matches all directories in the current folder.

But there’s a limitation: hidden directories (those starting with a dot, like .git) won’t show up.

If you also want details — permissions, ownership, timestamps — run:

ls -ld */

Use this when you just want a quick glance, but be aware it’s not the most reliable method for scripting.

A more reliable method: find

find is like a searchlight: it can scan your system for directories at any depth.

List all directories recursively from the current location:

find . -type d

Only top-level directories (portable across Linux, macOS, BSD):

find . -mindepth 1 -prune -type d

If you’re on GNU/Linux (most VPS distributions), you can use a simpler version:

find . -maxdepth 1 -type d

When to use find:

  • You want hidden directories included.
  • You need recursive results.
  • You’re writing a script and need consistency across systems.

Why not ls -l | grep “^d”?

You’ll sometimes see this suggested:

ls -l | grep "^d"

It filters ls -l output to only show directories (since they start with d).

But this approach is fragile:

  • Different locales or color settings may break parsing.
  • Symbolic links to directories won’t appear.
  • Not reliable for automation.

Better to use find instead.

Best practices

  • For scripting: use find — portable, consistent, and works with hidden directories.
  • For quick checks: ls -d */ is fine — just remember it ignores hidden folders.
  • For visual structure: use tree.
  • For security: always double-check hidden directories — they often store important configuration (.ssh, .git, .config).
  • Conclusion

Listing directories is a basic but essential Linux skill. Depending on the context, you have several tools:

  • ls -d */ for fast checks.
  • find . -mindepth 1 -prune -type d for reliable top-level results.
  • tree -d for a visual map of your system.

On an AlexHost VPS or Dedicated Server, these commands help you stay in full control of your environment, whether you’re deploying applications, monitoring logs, or just exploring the filesystem. Mastering them will save you time, prevent mistakes, and make you feel at home on any Linux machine.

Test your skills on our all Hosting services and get 15% off!

Use code at checkout:

Skills