How to make “tree” output consistent on Linux

Posted on In QA

I tried tree on different Linux boxes to verify the files by diff. However, I found the format can be a little bit different on different nodes.

For examples, the tree result could be

.
|-- test2
|   |-- test4
|   `-- test5
`-- test3

1 directory, 3 files

or

.
├── test2
│   ├── test4
│   └── test5
└── test3

1 directory, 3 files

How to make them consistent. Either one actually works for me.

You can set the charset that will be used by tree:

tree --charset=ascii

or

tree --charset=utf-8

Tests on one Linux box:

$ tree 
.
├── test2
│   ├── test4
│   └── test5
└── test3

1 directory, 3 files
$ tree --charset=ascii
.
|-- test2
|   |-- test4
|   `-- test5
`-- test3

1 directory, 3 files

The tree --charset=ascii method should be more portable to be shown correctly on a wider range of devices.

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *