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 11:42 AM in response to murrayE

tree -n --charset utf-8 > myapps.txt


Strip the color information [-n] from the UTF-8 output. This removes all of those prefaced color codes in TextEdit. Also, since TextEdit is not a proper programmer's editor, it will not align the output as it would if piped into BBEdit or more -r .


Here is the result from the preceding command when opened in BBEdit 13:


and in TextEdit:

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.