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.
There are better ways than using shell wildcards in this instance.
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.
1 2 3
1 2 3 4 5 6 7 8
find can limit to a maxdepth, however, it will be the output of
ls -dils and may be more text than you need.
1 2 3 4