I highly suspect the "contents of the list.txt
file" you posted is an interpretation (representation) of the actual content, not the literal content. Then it makes sense.
<0x1b>
is what the program you used to view the file prints to represent the (unprintable) ASCII escape character (in various circumstances the character may be referred to as ESC
, \x1b
, \033
, \e
, ^[
).
Then <0x1b>[01;34m
and similar sequences are CSI sequences. Your file contains SCI sequences that change color of the following text. Run cat list.txt
to pass the file to the terminal as-is. If your terminal supports CSI sequences (it probably does) then you will see colorized text.
The sequences are there in the file because your tree
put them there. In my Kubuntu man 1 tree
states few options to colorize (or not) the output: -C
, -n
. Without any of these options the behavior depends on LS_COLORS
and TREE_COLORS
environment variables and on stdout being a terminal or not.
By default, if LS_COLORS
(or TREE_COLORS
) is set, tree
will colorize its output to a terminal, but not if piped to a non-terminal (e.g. to a file or the next command in a pipeline). The quirk is if you tell it to write to a file with -o
then its behavior still depends on whether stdout is a terminal or not. If you redirected stdout to a non-terminal
tree -fFN --charset=utf8 -o list.txt test/ >/dev/null
# or simply
tree -fFN --charset=utf8 test/ >list.txt
then the output would not contain color codes.
Until a few days ago the output was correct without these additional characters.
Maybe there was no LS_COLORS
in your environment until few days ago; and the files created earlier don't contain color codes. Did you add LS_COLORS
to the environment recently? Or maybe the earlier files contain(ed) color codes but you used to examine them in a way that actually uses CSI sequences to display colors? or ignores them?
It's not clear if you want the color codes to be in the file in the first place.
Anyway check the manual of your tree
. Use a proper option to force coloring or not-coloring, or manipulate the environment and/or redirections to make tree
behave as you expect.
If you need to remove color codes from already existing files then pass each file through one of the filters from this post: Removing ANSI color codes from text stream.