Listing Directories in Linux and Limiting Depth⚓︎
Why ls doesn’t work⚓︎
ls doesn’t natively support recursion depth limiting.
While you can use shell wildcards as in ls */*/, you must know how many depths exist. If you use two wildcards, and only have one subdirectory, you will receive an error.
| Bash | |
|---|---|
1 2 | |
There are better ways than using shell wildcards in this instance.
Alternatives⚓︎
tree⚓︎
tree allows for limiting depth, and many other options. Human readable units, permissions, size, etc. This is an additional package and may not be installed, but it allows for the greatest flexibility.
| Bash | |
|---|---|
1 2 3 | |
| Text Only | |
|---|---|
1 2 3 4 5 6 7 8 | |
find⚓︎
find can limit to a maxdepth, however, it will be the output of ls -dils and may be more text than you need.
| Bash | |
|---|---|
1 | |
| Text Only | |
|---|---|
1 2 3 4 | |

