How to resolve the ls > file.txt dumps garbage characters in Linux?

0

When i do ls in my terminal it works fine, but when I do ls > file.txt it dumps garbage values along the name.

Resolution

Your ls command is aliased to something like ls --color=auto (or ‘yes’) which produces the ANSI coloring codes you see.

There are a few possible solutions:

  • You could unalias it with unalias ls which would remove the colors from your ls output.
  • Specify that you don’t want color as ls --color=no in your command.

Source

About Author

Leave a Reply