avd
avd

Reputation: 14441

UNIX: Strange output if piped to less

If I execute ls command with pipe to less, I get strange output

ESC[00mESC[00mfile1.ccESC[00m
ESC[00file2.ccESC[00m
ESC[00file3.ccESC[00m

(means ESC string in between).

Without ls, the output is:

file1.cc    file2.cc    file3.cc

How to correct this?

Upvotes: 5

Views: 1068

Answers (4)

msw
msw

Reputation: 43487

I'm guessing that you have the --color=always option to ls set, either through an alias, functions or the LS_COLORS environment variable and ls is sending color directives to a non-terminal (that is, your pipe to less).

Upvotes: 4

Michał Trybus
Michał Trybus

Reputation: 11784

You need to make less output raw control characters using less -r.

Upvotes: 1

Jouni K. Seppänen
Jouni K. Seppänen

Reputation: 44118

Use less -R or set the LESS environment variable to -R.

Upvotes: 3

ninjalj
ninjalj

Reputation: 43688

What you're seeing are ANSI escape sequences for setting colors. Run ls --color=no.

Upvotes: 1

Related Questions