ls-tree 0.1.0

A lightweight, dependency-free clone of the Unix `tree` command, written in Rust.
Documentation
  • Coverage
  • 75%
    6 out of 8 items documented0 out of 3 items with examples
  • Size
  • Source code size: 145.9 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 401.4 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 6s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • NefaroXX/ls-tree
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • NefaroXX

ls-tree

CI License: MIT Rust: stable

A lightweight, dependency-free clone of the Unix tree command, written in Rust. Point it at a directory and it recursively prints the folders and files as a visual hierarchy — using only the Rust standard library.

$ ls-tree ./src
src
├── lib.rs
└── main.rs

2 directories, 2 files

Features

  • 🌳 Classic tree output using ├──, └──, and │ connectors.
  • 📦 Zero dependencies — pure std (std::fs, std::path, std::env).
  • 🛡️ Robust error handling — unreadable directories print [Access Denied] and the traversal continues instead of crashing.
  • 🔗 Symlink-safe — symlinks are shown (with their target) but never descended into, so symlink cycles cannot hang the program.
  • 🙈 Hidden-file aware — dotfiles are hidden by default (like tree), with a flag to reveal them.
  • 🎚️ --max-depth to limit how far down the tree is printed.

Installation

From source (recommended)

git clone https://github.com/NefaroXX/ls-tree.git
cd ls-tree
cargo install --path .

From crates.io

cargo install ls-tree

Build locally

cargo build --release
./target/release/ls-tree

Usage

ls-tree [OPTIONS] [PATH]

If PATH is omitted, ls-tree prints the current directory (.).

Options

Flag Description
-a, --all Show hidden entries (names starting with .).
-L, --max-depth N Descend at most N directory levels.
-h, --help Print the help message and exit.
-V, --version Print version information and exit.

Examples

# Current directory
ls-tree

# Specific path
ls-tree ./src

# Include hidden files, two levels deep
ls-tree -a -L 2 /etc

Exit codes

Code Meaning
0 Success (including when some subdirectories were unreadable).
1 The path does not exist, is not a directory, or could not be accessed.

How it works

ls-tree reads the provided path, then recursively walks the directory tree with std::fs::read_dir and std::path::PathBuf, emitting an indented hierarchy. Strings and paths are passed through the recursive walk as borrowed &Path values with owned PathBufs only where ownership is genuinely needed, keeping the borrow checker happy.

Edge cases handled explicitly:

  • Hidden files / folders — skipped by default, shown with -a.
  • Restricted permissions — an unreadable directory prints [Access Denied] inline and traversal continues.
  • Symlink cycles — symlinks are displayed but never descended into.

Development

cargo build
cargo test
cargo fmt --all -- --check
cargo clippy --all-targets -- -D warnings

Contributions are welcome — see CONTRIBUTING.md and please follow the Code of Conduct.

License

Licensed under the MIT License.