0

I want to issue a simple ls command and store the results in a file:

ls -ltr equ* > ffile

The file names show up with extra escape characters attached. These show up plainly under some utilities (like vi), and not at all under others (like more). Example:

-rw------- 1 me 9607LPET  72680 Apr 10 12:00 ^[[0m^[[00mequ_00020.dat^[[0m
-rw------- 1 me 9607LPET  72680 Apr 10 12:00 ^[[00mequ_00021.dat^[[0m
-rw------- 1 me 9607LPET 356110 Apr 10 12:00 ^[[00mequ_00065.dat^[[0m
-rw------- 1 me 9607LPET  60253 Apr 10 12:00 ^[[00mequ_00067.dat^[[0m
-rw------- 1 me 9607LPET  83656 Apr 10 12:00 ^[[00mequ_00068.dat^[[0m

Anyway, these characters are detected by almost any tool I might use to process this file list. They are making it very difficult to process the file names. How do I get rid of them? What are they there for in the first place?

EDIT: This question has been flagged as a duplicate of another question that also involved getting rid of colors in the ls output. However, I maintain that getting rid of the colors is a single solution to two distinct problems. The other question is specifically about colors in the first place. This one is not. A user can have the exact problem I just had and still have no idea whatsoever that he should be looking at other questions involving color in ls output. I, of course, was one of these users. I therefore maintain that this is not a proper duplicate of the other question, and this question should be kept as a unique question about a unique problem since that in fact is what it is.

bob.sacamento
  • 6,283
  • 10
  • 56
  • 115
  • 2
    Possible duplicate of [Removing colors from output](https://stackoverflow.com/questions/17998978/removing-colors-from-output), [How do I turn OFF colors for ls output in Terminal on OSX](https://stackoverflow.com/q/33160450/608639), [How to remove dir background in `ls -color` output](https://stackoverflow.com/q/40574819/608639), [How to turn off color with `ls`?](https://unix.stackexchange.com/q/107371/56041) and friends. – jww Apr 11 '19 at 14:20
  • @jww I would say though this post and the possible duplicate have the same solution, it is the same solution to *two different problems*. Some user looking through stack overflow could have the same problem I have and still have no idea that he should be looking at a question about colors in `ls`. – bob.sacamento Apr 11 '19 at 14:24

1 Answers1

4

These are the ANSI escape sequences that turn colours on and off. Try adding

--color=never

to ls to turn colouring off.

Usually, you should use --color=auto which should turn the colours off when the output is not a terminal.

choroba
  • 231,213
  • 25
  • 204
  • 289