How to resolve the ls > file.txt dumps garbage characters in Linux?
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 yourls
output. - Specify that you don’t want color as
ls --color=no
in your command.