tree: hide control characters and display Japanese properly #

After installing tree in macOS (brew install tree), running it did not produce the expected results:

$ tree
.
└── 宮?\216駿
    ├── 1\ 風?\201?谷?\201??\203\212?\202??\202??\202?.iso
    ├── 2\ 天空?\201??\237\216?\203??\203\222?\202\232?\203??\202?.iso
...

Specifying the character set sadly did not avail, and saving results to a file seemingly exacerbated the problem:

$ tree --charset utf-8 -o list.txt

Partial view of file as it appeared it Sublime Text:

<0x1b>[01;34m.<0x1b>[00m
├── list.txt
└── <0x1b>[01;34må®®å´\216駿<0x1b>[00m
...

The solution was to use the -N ("Print non-printable characters as is") and -n ("Turn colorization off always", which hides the color control characters / ANSI escape codes) options:

$ tree -Nn
.
└── 宮崎駿
    ├── 1 風の谷のナウシカ.iso
    ├── 2 天空の城ラピュタ.iso
    ├── 3 となりのトトロ.iso
    ├── 4 魔女の宅急便.iso
    ├── 5 もののけ姫.iso
    └── 6 千と千尋の神隠し.iso

1 directory, 6 files

/mac | Jan 15, 2019


Subscribe or visit the archives.