tree
Files and directories
Usage
tree -L 2 [path]Draws the directory structure as an indented picture; it is not installed by default on macOS or slim Linux images.
Common flags
| Flag | Meaning |
|---|---|
| -L | Limit the depth to N levels |
| -a | Include hidden files |
| -d | Directories only |
| -I | Skip names matching a pattern |
| -f | Print the full path of each entry |
| -h | Show readable sizes |
Examples
tree -L 2Two levels deep, so the output stays readable.
tree -I 'node_modules|.git'Skips the noisy directories.
tree -d -L 1Just the top-level folders.
Moving, deleting and finding. Some of these do not ask twice, which is why -i becomes a habit.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does tree do?
Draws the directory structure as an indented picture; it is not installed by default on macOS or slim Linux images.
Q. How do I type it?
tree -L 2 [path] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
6 are listed here; the full set is in man tree. This command sits under Files and directories.
Related commands
man page: man tree