Wrong characters from "tree" command

Using the standard "tree" command (as supplied by MacPorts), if at the Terminal prompt I cd to a folder and then execute "tree"there, I get output like this:


.
├── Activity\ Monitor.app
├── ApplicationsFolderIcon.icns
├── BBEdit.app
├── Backup
│   ├── Backup\ and\ Sync\ from\ Google.app
│   ├── Carbon\ Copy\ Cloner.app
│   ├── Dropbox.app\ 
│   ├── ForeverSave\ 2.app
│   ├── Get\ Backup\ Pro\ 3.app


However, if I redirect the output to a text file, as in


tree > myapps.txt


then I get wrong characters when I view the file in TextEdit:

.
├── Activity\ Monitor.app
├── ApplicationsFolderIcon.icns
├── BBEdit.app
├── Backup
│   ├── Backup\ and\ Sync\ from\ Google.app
│   ├── Carbon\ Copy\ Cloner.app
│   ├── Dropbox.app\ 
│   ├── ForeverSave\ 2.app
│   ├── Get\ Backup\ Pro\ 3.app


What's wrong?

iMac 27", macOS 10.15

Posted on Dec 10, 2019 9:33 AM

Reply
Question marked as Top-ranking reply

Posted on Dec 10, 2019 9:53 AM

In textedit you may have to change the encoding under Options from "automatic" to utf-8 (or something else, I'm not sure what terminal does)


Textedit preferences let you set the default encoding for opening files if that helps.

Similar questions

17 replies

Dec 10, 2019 8:42 PM in response to murrayE

murrayE wrote:

Yes,

tree -n --charset=unicode > ~/Desktop/myapps.txt

does work, too!

Thanks!


From the man page for tree, it appears that the "ascii" charset is probably CP437, an ancient 8 bit encoding which does have those drawing characters. I'm not sure how TextEdit would automatically recognize that. "Unicode" is probably utf-16, which TextEdit should be able to recognize without any help.

Dec 10, 2019 1:15 PM in response to murrayE

murrayE wrote:

I'm still getting those weird characters such as │   ├──

Here's an analysis of what is happening: ├── is the utf-8 encoding for the drawing characters 251c 2500 2500 (e2 94 9c e2 94 80 e2 94 80) being read as if were in MacRoman encoding (which is presumably TextEdit's default).


I'm mystified by the error message you are getting.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Wrong characters from "tree" command

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.