LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   ls > temp has extra characters (https://www.linuxquestions.org/questions/linux-newbie-8/ls-temp-has-extra-characters-631720/)

djeikyb 03-30-2008 12:36 PM

ls > temp has extra characters
 
I have a series of log files I'd like to scroll through all at once instead of catting or lessing each one. So I'm thinking:

ls -1tc |xargs -l1 cat |less

This gives a bunch of errors like foo.file not found. So I tried to simplify. (I know logging in as root is generally a Bad Thing.)
Code:

[root@localhost log]# ls -1tc |tee temp
temp
htm/
dptrace-1.txt
dptrace-2.1
dptrace-2.2
dptrace-2.txt
[root@localhost log]# cat temp
temp
htm/
dptrace-1.txt
dptrace-2.1
dptrace-2.2
dptrace-2.txt
[root@localhost log]# vi temp
^[[00m^[[00mtemp^[[00m
^[[00;34mhtm^[[00m/
^[[00mdptrace-1.txt^[[00m
^[[00mdptrace-2.1^[[00m
^[[00mdptrace-2.2^[[00m
^[[00mdptrace-2.txt^[[00m

[2]+  Stopped                vi temp
[root@localhost log]# ls -1tc |xargs -l1 cat
cat: temp: No such file or directory
cat: htm/: No such file or directory
cat: dptrace-1.txt: No such file or directory
cat: dptrace-2.1: No such file or directory
cat: dptrace-2.2: No such file or directory
cat: dptrace-2.txt: No such file or directory

So of course cat is failing; the temp file has all these wierd characters. But why does vi show them, and not cat? And why does ls > temp add all those extra characters?

I'm also confused about why the temp file that is just being created shows up during the ls command.

The linux box is RHEL 5.1, but I'm using Putty to ssh in. Putty with XMing is pretty dang useful!

osor 03-30-2008 01:14 PM

The extra characters are ANSI escape sequences for colors. Perhaps you have an alias for ls to “ls --color=always”. Try removing this (or setting it to “ls --color=auto”).

pwc101 03-30-2008 01:14 PM

I think they're colour codes; you might find that your ls command is actually aliased to ls --color (check with "alias" or "type ls"). To remedy it, try this:
Code:

\ls -1tc |tee temp
That should use the original ls command, not its alias. Otherwise, specify the path to ls
Code:

/usr/bin/ls -1tc |tee temp

djeikyb 03-30-2008 02:20 PM

Yep, ls was aliased to color=always. Now I know why auto is recommended! Thanks guys.


All times are GMT -5. The time now is 07:58 AM.