5

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?

4 Answers 4

4

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).

Sign up to request clarification or add additional context in comments.

Comments

3

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

Comments

1

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

Comments

1

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

1 Comment

The upper-case option -R avoids some line-breaking problems.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.