DTREE(1) General Commands Manual DTREE(1)

dtreeCommand line program to draw trees

dtree [-hVv]


dtree [-s set] [file]

dtree is a simple command line program which reads a number of lines and formats them as a tree using line drawing characters in several sets. Each input line represents one node in a tree. The number of tabs at the start of each input line determines the nesting level of that node. It is intended for the root node to have no tabs at the start.

If the file is omitted, dtree will read from stdin. Any additional arguments after file will be ignored.

Prints usage information.
set
Selects the symbol set set. Allowed values for set are: a (ASCII set), d (double-stroke set), and s (single-stroke set, default).
Prints full version information: like -v, followed by copyright notice.
Prints version and commit date.

The dtree utility exits 0 on success, and >0 if an error occurs.

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):

LC_ALL=C sort -k2 /proc/mounts |
awk '{				# pp = previous pointer
	sl = $2;
	gsub("[^/]", "", sl);
	slashc = length(sl);	# slash count
	if ($2 != "/" &&
		slashc > prevsc[pp] &&
		substr($2,0,length(prev[pp])) == prev[pp])
	{
		for (i = 0; i < pp+1; i++)
			printf "\t";
		pp++;
	}
	else if ($2 != "/")
	{
		if (slashc < prevsc[pp] &&
			substr($2,0,length(prev[pp-1])) != prev[pp-1])
			pp--;
		for (i = 0; i < pp; i++)
			printf "\t";
	}
	print $2;
	prev[pp] = $2;		# previous mountpoint
	prevsc[pp] = slashc;	# previous slash count
}' |
dtree

tree(1)

Strahinya Radich ⟨sr@strahinja.org⟩, 2023-2024

July 15, 2024 OpenBSD 7.5