How to List Only Directories in Ubuntu Terminal
This article provides a quick guide on filtering directory listings in the Ubuntu operating system. You will learn specific terminal commands that exclude regular files and display only subfolders within your current working directory. These methods are essential for scripting automation and efficient navigation.
Use ls with Wildcards
The fastest way to list directories is using the ls
command with a wildcard pattern. This method tells the shell to expand
only items that end with a slash, which indicates a directory.
ls -d */Use ls with Grep
You can combine the long listing format with grep to
filter lines that start with the directory permission character. This
displays detailed information about each folder.
ls -l | grep "^d"Use the Find Command
For robust scripting, the find utility offers precise
control. This command searches the current path limited to one depth
level and selects only items of type directory.
find . -maxdepth 1 -type dNote that find includes the current directory
. in the output. To exclude it, you can add
! -name . to the command.