Tree command does not print properly

Hi,

when I run tree command in linux box getting below image, not the line

 
test
��� lost+found
��� test1
�� �  ��� aaa.txt
�� �  ��� bbb.txt
��� test2
3 directories, 2 files

installed tree-1.5.3-2.el6.x86_64 package

Try:

LC_ALL=C tree

Thanks, it worked.

I know this very old, but I have a question. still when I run tree command I am getting same junk what I posted in my first post.

But when I run below command, tree structure getting

 
LC_ALL=C tree

what is permanent solution to print tree structure with "tree" command.

Maybe your character set is set to UTF-8 when you don't actually have a UTF-8 terminal. LC_ALL=C prevents it from trying to use fancy unicode line-printing characters.

What is the output of your locale command?

The set of language-specific characters in your environment is (maybe erronously) set so that the line-drawing characters are replaced by some other characters (which you called "junk"). Which set of characters is taking these places (german umlauts, french accents, ....) is controlled by the "LC_ALL" variable. To set this variable to "C" means to use a set of characters without any diacriticals at all, which is enough for english language but probably no other.

When you enter a certain setting for a variable and then a command it means that the value for this variable is in effect only for this one command. This means:

# LC_ALL=C tree
# tree

The first of the two commands will have set LC_ALL to "C" and therefore work, the second one will produce junk again because "LC_ALL" is set to something else.

Solution: set the variable somewhere where it has a lasting effect. The best place is your shells startup file: "~/.kshrc" if you use ksh (Korn shell), "~/.bashrc" if you use bash (Bourne Again Shell).

Put in the respective file the following line:

LC_ALL=C ; export LC_ALL

and start a new shell.

I hope this helps.

bakunin

I appended

LC_ALL=C ; export LC_ALL

in .bash_profile, but the entire locale variable has changed.

 
LC_CTYPE=C
LC_NUMERIC=C
LC_TIME=C
LC_COLLATE=C
LC_MONETARY=C
LC_MESSAGES=C
LC_PAPER=C
LC_NAME=C
LC_ADDRESS=C
LC_TELEPHONE=C
LC_MEASUREMENT=C
LC_IDENTIFICATION=C
LC_ALL=C

It does that. It's a special variable.

$ man bash
...
       LC_ALL This variable overrides the value of  LANG  and  any  other  LC_
              variable specifying a locale category.
...

The alternative to altering the locale would be to fix your terminal. What are you using?