Skip to content
Advertisement

‘tree’ and ‘ls’ change text color on Linux command line

I’ve been having a peculiar issue caused by the tree command on Linux. When I call tree, the the color of the command prompt changes, and is only returned to normal by the ls command. I’m curious if others have encountered the same issue, and if they have fixes or workarounds. I’m using the solarized color scheme (though I’m not sure it’s displaying entirely as intended) and I’ve confirmed that the issue arises on both xterm and gnome-terminal.

Thanks!

(Edit: I deleted the screenshot because it had some personal information)

Advertisement

Answer

The screenshot shows that the tree command is setting the foreground color, without resetting it.

The ls command does reset colors, sending

e[0m

(where e is the escape character). Call it a bug in tree. There is no general/portable method for restoring the original colors before a program is run. It is each program’s responsibility to reset colors.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement