Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UNIX: Strange output if piped to less

Tags:

command

unix

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?

like image 763
avd Avatar asked Jan 22 '23 07:01

avd


1 Answers

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

like image 141
msw Avatar answered Jan 29 '23 07:01

msw