1

The following resources show tree should output hierarchical directory structure view directory structure

enter image description here

So I did brew install tree. But the tree command does not print hierarchical output:

(py367) 11:31:12/hercules-api $tree -d src
[        160 Jan 20 17:28]  src
[        224 Feb 13 13:52]  src/alembic_migrations
[        160 Feb 13 23:21]  src/alembic_migrations/__pycache__
[        256 Feb 13 13:52]  src/alembic_migrations/versions
[        544 Feb 13 23:35]  src/alembic_migrations/versions/__pycache__

Is there a switch on tree to get the expected or a different code base/compile/install which has this feature on macOS?

3
  • 1
    Check if you have more than one tree command installed and the non-brew one is getting called. which -a tree should list them all (if there is more than one).
    – DC Slagel
    Commented Feb 16, 2022 at 21:37
  • @DCSlagel Before installing tree from brew there was none available. in any case $which tree /opt/brew/bin/tree Commented Feb 16, 2022 at 22:41
  • Okay it sounds like there is only one 'tree' there. Side-note... The '-a' tells 'which' to list all the executables for 'tree'. So if there was more than one, '-a' would display all of them.
    – DC Slagel
    Commented Feb 16, 2022 at 23:11

2 Answers 2

1

I don't use tree. But I have found:

brew info tree which tells me the tree website is:

The Tree Command for Linux Home Page, which links to:

Man page for Tree, which tells me:

The -d is used to list directories only, which is what you have done. Without the -d all files are shown.

To confirm this I have installed tree and the -d works for me, for example:

gilby@Beth/Users/gilby/Projects% tree -d cacti
cacti
├── 947301-387ecde4b13cf7e8daf05ab154461505b5cd027d
├── RRD-to-CSV-master
├── TechnicolorStatScraper-master
│   ├── Cacti
│   │   └── __pycache__
│   └── __pycache__
├── cacti-0.8.8b
│   ├── cli
│   ├── docs
│   │   ├── html
│   │   │   └── images
│   │   ├── pdf
│   │   └── txt
│
4
  • I do want only directories and as you see it is not hierarchical. Removing -d adds a bunch of files into the still non-hierarchical output Commented Feb 16, 2022 at 21:09
  • @WestCoastProjects Sorry, did not appreciate you only wanted dirs. Was making it like the sample in your question.
    – Gilby
    Commented Feb 16, 2022 at 21:15
  • 1
    @WestCoastProjects I have installed tree (via home-brew) and tree -d does give me the hierarchical output with just directories (and packages).
    – Gilby
    Commented Feb 16, 2022 at 21:16
  • huh, then i wonder why there is the difference between the behaviors Commented Feb 16, 2022 at 21:24
1

If all you want is tree, try:

$ alias tree=$'find . -print | sed -e \'s;[^/]*/;|____;g;s;____|; |;g\''

And then just run tree.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .