others-How to solve garbled characters when using tree command in terminal?

1. Purpose

In this post, I would demo how to solve garbled characters problem when using tree to print the directory structure:

[[email protected] ~]# tree .

you get this result:

├── �\210\221们
└── �\213�\225

2 directories, 0 files

2. Environment

  • macos 10.15 catalina

3. The solution

We can use this command to solve this problem:

[[email protected] ~]# tree -N .

We get this:

├── 我们
└── 测试

2 directories, 0 files

4. Why did this work?

We can check why the command tree -N works:

  -N            Print non-printable characters as is.

It just print the results of tree command as is.

5. Summary

In this post, I demonstrated how to solve the garbled characters problem when using tree command. Hope it helps for you.