Syntax
Description
Thetree command displays the directory structure in a visual tree format, making it easy to understand the hierarchy of files and directories. It recursively traverses directories and presents them with ASCII art connectors showing the relationships between files and folders.
Tree operates entirely within Nash’s Virtual Filesystem (VFS). When viewing mounted host directories, it displays the host content through the VFS mount point.
Options
Show hidden files and directories (those starting with
.). By default, hidden entries are filtered out.Limit the depth of directory traversal. For example,
-L 2 shows only two levels deep. Without this option, tree recurses through all subdirectories.Syntax: -L N where N is the maximum depth level.Arguments
The starting directory to display. Can be an absolute path or relative to the current working directory. If omitted, defaults to the current directory.
Behavior
- Displays the root directory path on the first line
- Recursively traverses all subdirectories (unless limited by
-L) - Uses box-drawing characters (
├──,└──,│) to show hierarchy - Appends
/to directory names for visual distinction - Filters hidden files/directories by default (unless
-ais specified) - Outputs summary line showing total directories and files counted
Examples
Basic tree from current directory
Tree of specific directory
Limit depth with -L
Show hidden files with -a
Combine -a and -L flags
Tree with files in subdirectories
Tree from absolute path
Output Format
Tree uses the following ASCII characters to draw the structure:├──- Branch connector (not the last item)└──- Final branch connector (last item)│- Vertical line (continues branch)/- Suffix for directories
Use Cases
Verify project structure
Quick overview of nested content
Documentation and README examples
Compare before and after operations
VFS Integration
Viewing mounted directories
Tree displays the content of mounted host directories:Multiple mount points
Read-only mounts
Tree works identically on read-only mounts:Error Handling
Non-existent directory
If the specified directory doesn’t exist, tree shows an empty result:Tree doesn’t produce an error for non-existent paths; it simply shows zero entries.
Permission issues in mounted directories
If a mounted directory has host-level permission issues, those entries may be skipped silently.Combining with Other Commands
Save tree output to file
Compare with find
Verify mkdir -p results
Use with grep to filter
Exit Codes
- 0 - Success: tree displayed successfully
Related Commands
ls- List directory contents in flat formatfind- Search for files recursivelycd- Change to a directory before running treepwd- Show current directory (tree’s default starting point)mkdir- Create directory structures to visualize
Implementation Details
Thetree command is implemented in /home/daytona/workspace/source/src/builtins/tree.rs:9-110. Key implementation notes:
- Recursively traverses directories using
vfs.list_dir() - Uses a depth counter to implement
-Lmax depth limiting - Filters entries starting with
.unless-aflag is provided - Tracks directory and file counts separately for summary
- Uses
tree_recursive()helper function for depth-first traversal - Builds ASCII tree structure with appropriate connectors
- Handles the “last item” case differently (uses
└──instead of├──) - Appends
/suffix to directory names for visual clarity
Performance Considerations
Best practices for large trees
Comparison to Traditional Unix tree
Nash’stree implements core functionality:
| Feature | Nash tree | Unix tree |
|---|---|---|
-a all files | ✓ Supported | ✓ Supported |
-L max depth | ✓ Supported | ✓ Supported |
-d dirs only | ✗ Not supported | ✓ Supported |
-f full path | ✗ Not supported | ✓ Supported |
-P pattern | ✗ Not supported | ✓ Supported |
--du disk usage | ✗ Not supported | ✓ Supported |
| Colored output | ✗ Not supported | ✓ Supported |
| File permissions | ✗ Not supported | ✓ Supported |
Nash focuses on the essential tree visualization features. Advanced filtering and statistics are available through other commands like
find and stat.