dtree
Command line program to draw trees
For installation instructions, see the file INSTALL.
Manual
See https://strahinja.srht.site/man/dtree/dtree.1.html.
Examples
Format a tree using double-stroke box drawing characters:
printf "A\n\tB\n\t\tC\n\tD\n" | dtree -sd
tree(1) replacement:
find . -print | sed -E "s,[^/]+/,$(printf '\t'),g" | dtree
same, using ASCII characters:
find . -print | sed -E "s,[^/]+/,$(printf '\t'),g" | dtree -sa
poor man's findmnt(1) (depends on having /proc/mounts active):
sort -k2 /proc/mounts |
awk 'BEGIN{ pp=0 } { # pp = previous pointer
sl = $2;
gsub("[^/]", "", sl);
slashc = length(sl); # slash count
if ($2 != "/" &&
substr($2,0,length(prev[pp])) == prev[pp])
{
if (prev[pp] == "/" || slashc > prevsc[pp])
pp++;
for (i = 0; i < pp; i++)
printf "\t";
prev[pp] = $2; # previous mountpoint
prevsc[pp] = slashc; # previous slash count
}
else if ($2 != "/")
{
if (slashc < prevsc[pp] &&
substr($2,0,length(prev[pp-1])) != prev[pp-1])
pp--;
prev[pp] = $2;
prevsc[pp] = slashc;
for (i = 0; i < pp; i++)
printf "\t";
}
else
{
prev[pp] = $2;
prevsc[pp] = slashc;
}
print $2;
}' |
dtree
On OpenBSD, replace the first command in the above pipeline with
mount |
Prerequisites
C compiler - defaults in config.mk (HaikuOS needs Clang/LLVM)
Install
$ git clone https://git.sr.ht/~strahinja/dtree $ cd dtree $ cp config.$(uname -s) config.mk $ su # make install
With got:
$ got clone https://git.sr.ht/~strahinja/dtree $ got checkout dtree.git $ cd dtree $ cp config.$(uname -s) config.mk $ su # make install
Persistent build configuration file
The file config.mk will be sourced when building targets which also accept
configuration through environment variables. For example, CPPFLAGS and
PREFIX are specified in config.mk.
Initially, there will be no config.mk, you will need to copy one of the customized config.* files or write your own:
$ cp config.$(uname -s) config.mk || echo Write config.mk from scratch
Install (Arch)
$ git clone https://aur.archlinux.org/dtree.git $ cd dtree $ makepkg -si
License
dtree - Command line program to draw trees
Copyright © 2023-2026 Страхиња Радић
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.