I would say your ls shouldn’t be working that way: when it detects that it’s standard output isn’t a terminal, it shouldn’t be outputting the control codes. Which makes me wonder what version of ls you are running.
edit: what is the output from alias ls and what happens if you run \ls --help | less?


That’s surprising. I have an older version of coreutils (9.7 from Debian 13) that doesn’t produce the links and formatting. I’m running bash and the behaviour you’re experiencing isn’t reproduced.
Aliases aside, I wouldn’t expect the shell to be the cause. None the less, I installed version 4.0.2 of the fish shell and ran the same command in it and didn’t see any control characters. But that’s not really surprising - my old version of ls doesn’t produce them. So I ran
ls | lessbecause even with my versionlscolour highlights files by type, but in the pipeline to less, there were no codes.If I run
ls --color=always | lessthen I do see codes in the less output.You might check your environment variables to see if CLICOLOR_FORCE is set.
Otherwise, I am out of ideas.