tree
is an open-source tree
command-line application that recursively displays the directory structure of a given path in a tree-like format, inspired by the Unix tree
command. It is implemented in Rust and aims to provide a fast and efficient alternative with additional features, especially useful on platforms with no or limited tree
cli features. Available for most platforms.
Website: https://peteretelej.github.io/tree/
-L
or --level
)-f
or --full-path
)-i
or --no-indent
)-a
or --all
)-P
or --pattern
)-s
or --size
)-H
or --human-readable
)-C
or --color
)-n
or --no-color
)-A
or --ascii
)-d
or --directories
)-I
or --exclude
)-o
flag--filelimit
flagdirsfirst
flag-t
)-r
)-D
)/
, *
, etc.) (-F
)--noreport
)-p
)--fromfile
)Please feel to open PR requests in case interested in implementing some of the pending features.
You can easily download binaries for different platforms from the Releases Page (Windows, MacOS, Linux).
tree
binariesIf you have Rust and Cargo installed, you can build the project by running:
git clone https://github.com/peteretelej/tree.git
cd tree
cargo build --release
./target/release/tree -L 2 . # or use --level=2
# copy tree binary to a PATH directory
The resulting binary will be located at ./target/release/tree.
For Windows 7 compatibility, use Rust 1.75 with the provided lockfile:
rustup install 1.75.0
cp Cargo-win7.lock Cargo.lock
rustup run 1.75.0 cargo build --release
# restore default rust toolchain version
rustup default stable
./tree [FLAGS] [OPTIONS] [PATH]
For example:
# Using short flags
./tree -L 2 .
./tree -a -f -s .
./tree -P "*.txt" -I "*.log" .
# Using long flags
./tree --level=2 .
./tree --all --full-path --size .
./tree --pattern="*.txt" --exclude="*.log" .
use rust_tree::tree::{list_directory, options::TreeOptions};
fn main() {
let path = ".";
let options = TreeOptions {
full_path: true,
no_indent: true,
..Default::default()
};
list_directory(path, &options).unwrap();
}
The library now also provides list_directory_as_string
function that returns the tree output as a String
instead of writing to stdout, useful when you need to capture the output for further processing.
Using the bytes_to_human_readable
function to print human readable file sizes
use rust_tree::utils::bytes_to_human_readable;
use std::fs;
fn main() {
let metadata = fs::metadata("my_file.txt").unwrap();
let size = metadata.len();
let size_str = bytes_to_human_readable(size);
println!("File size: {}", size_str);
}
Contributions are welcome! If you have any suggestions, feature requests, or bug reports, please feel free to open an issue or submit a pull request on the GitHub repository.
This project uses standard Rust formatting. Before submitting a PR:
# Format your code
cargo fmt
# Verify formatting
cargo fmt --check
# run the pre-push script to ensure code quality
./scripts/pre-push
Consider copying the pre-push
script to your git hooks directory:
cp scripts/pre-push .git/hooks/pre-push
The project includes a comprehensive Rust-based QA testing tool in tools/qa
that validates all tree CLI features across multiple platforms using Docker containers.
# Build the QA tool
cd tools/qa && cargo build --release
# Run tests on Linux platform
./target/release/qa test --platforms linux
# Run tests on multiple platforms
./target/release/qa test --platforms linux,alpine
# Run with verbose output for debugging
./target/release/qa test --platforms linux --verbose
# Clean up Docker resources
./target/release/qa clean
The QA tool executes 34 comprehensive tests across 9 categories (basic functionality, file filtering, display options, sorting, etc.) in isolated Docker containers. Tests validate features as advertised in this README using only the generated binaries. See tools/qa/README.md
for full documentation.
For VS Code users, add this to your settings.json:
{
"[rust]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "rust-lang.rust-analyzer"
}
}
MIT