Putty and tree - how to avoid weird characters (squares)

Character encoding is always a problem when communicating between Windows and Linux. And using the "tree" command is affected by this problem if you are connected to a Linux box using Putty on a Windows box. You will certainly get weird characters, probably squares.

For those who are not sure about what tree is. It is a command-line tool to list contents of directories in a tree-like format.

A solution to this problem is to force using plain ASCII characters:

tree --charset=ASCII

You can also have an alias for this command, so that every time you type "tree", it will force tree to use the ASCII charset automatically.

alias tree='tree --charset=ASCII'

And this is an example of what you will get as an output:

/tmp
|-- claws-mail-1000
|-- keyring-x803mg
|   |-- control
|   |-- pkcs11
|   `-- ssh
|-- orbit-gdm [error opening dir]
`-- virtual-user

4 Comments so far »

  1. Matt Stevens said

    July 7 2011 @ 11:15 AM

    Nice tip, thanks for putting this up! :)
    'ls -R' doesn't cut it.

  2. Jody said

    July 13 2012 @ 10:20 AM

    You can also change the character encoding in Putty. Settings -> Window -> Translation -> Remote Character Set. I used UTF-8

  3. Harry said

    September 2 2012 @ 5:27 PM

    @Jody: Thx for that tip, this looks even better in Putty ;-)

  4. Wolfgang Kucher said

    April 26 2013 @ 4:57 AM

    Thank You for the tip.
    Saved me a lot of time.

    Regards

    Wolfgang

Comment RSS · TrackBack URI

Leave a comment

Name: (Required)

eMail: (Required)

Website:

Comment: