Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
'less' on some files shows hex output
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
cgill27
n00b
n00b


Joined: 15 Mar 2008
Posts: 23

PostPosted: Wed Dec 17, 2008 12:58 am    Post subject: 'less' on some files shows hex output Reply with quote

After doing an emerge -e world I noticed that when I do 'less /var/log/messages' or other files, the less output is in hex, like below.
How can I change that so that less displays a file normally, not in hex?

I've tried looking through less's man page but don't see anything relevant.

00000000 44 65 63 20 31 35 20 31 35 3a 31 39 3a 31 33 20 |Dec 15 15:19:13 |
00000010 63 62 6f 78 20 73 79 73 6c 6f 67 2d 6e 67 5b 31 |cbox syslog-ng[1|
00000020 34 30 37 35 5d 3a 20 43 6f 6e 66 69 67 75 72 61 |4075]: Configura|
00000030 74 69 6f 6e 20 72 65 6c 6f 61 64 20 72 65 71 75 |tion reload requ|
00000040 65 73 74 20 72 65 63 65 69 76 65 64 2c 20 72 65 |est received, re|
00000050 6c 6f 61 64 69 6e 67 20 63 6f 6e 66 69 67 75 72 |loading configur|
00000060 61 74 69 6f 6e 3b 0a 44 65 63 20 31 35 20 31 35 |ation;.Dec 15 15|
00000070 3a 32 30 3a 30 31 20 63 62 6f 78 20 63 72 6f 6e |:20:01 cbox cron|
00000080 5b 31 35 30 34 36 5d 3a 20 28 72 6f 6f 74 29 20 |[15046]: (root) |
00000090 43 4d 44 20 28 74 65 73 74 20 2d 78 20 2f 75 73 |CMD (test -x /us|
000000a0 72 2f 73 62 69 6e 2f 72 75 6e 2d 63 72 6f 6e 73 |r/sbin/run-crons|
000000b0 20 26 26 20 2f 75 73 72 2f 73 62 69 6e 2f 72 75 | && /usr/sbin/ru|
000000c0 6e 2d 63 72 6f 6e 73 20 29 0a 44 65 63 20 31 35 |n-crons ).Dec 15|
000000d0 20 31 35 3a 32 35 3a 33 39 20 63 62 6f 78 20 73 | 15:25:39 cbox s|
000000e0 73 68 64 5b 31 35 30 35 39 5d 3a 20 41 63 63 65 |shd[15059]: Acce|
000000f0 70 74 65 64 20 6b 65 79 62 6f 61 72 64 2d 69 6e |pted keyboard-in|
00000100 74 65 72 61 63 74 69 76 65 2f 70 61 6d 20 66 6f |teractive/pam fo

Thanks,
Craig
Back to top
View user's profile Send private message
Dammital
Apprentice
Apprentice


Joined: 05 Nov 2004
Posts: 189

PostPosted: Wed Dec 17, 2008 3:11 am    Post subject: Reply with quote

less looks to see if the LESSOPEN environment variable is set, and if so calls an input preprocessor. You probably have it set to:
Code:
$ export | grep LESSOPEN
declare -x LESSOPEN="|lesspipe.sh %s"

... where lesspipe.sh is the input preprocessor. If you want to see what lesspipe.sh does, you can browse it:
Code:
less `which lesspipe.sh`

You can disable the LESSOPEN action temporarily with the less -L switch. To permanently disable it you can either unset LESSOPEN in your .bashrc or insert a command alias:
Code:
alias less='less -L'

(presuming you use bash)
Back to top
View user's profile Send private message
cgill27
n00b
n00b


Joined: 15 Mar 2008
Posts: 23

PostPosted: Wed Dec 17, 2008 4:55 am    Post subject: Reply with quote

Thanks that was it!

I found this in /usr/bin/lesspipe.sh on line 35:
*": data") hexdump -C -- "$1"; return 0;;

Doing 'file -L /var/log/messages' returns '/var/log/messages: data'

So thats why /var/log/messages shows hex when viewed with less, now the question is why this all of a sudden changed.

Thanks,
Craig
Back to top
View user's profile Send private message
cgill27
n00b
n00b


Joined: 15 Mar 2008
Posts: 23

PostPosted: Wed Dec 17, 2008 5:23 am    Post subject: Reply with quote

Digging alittle deeper the issue is something with file and how it recognizes the file:

# file /var/log/messages
messages: data
# file /var/log/emerge.log
emerge.log: ASCII text

Any idea why file would see those two files as different file types? (I know something in the file is triggering it to see it differently but no idea what)

Thanks,
Craig
Back to top
View user's profile Send private message
Yamakuzure
Advocate
Advocate


Joined: 21 Jun 2006
Posts: 2285
Location: Adendorf, Germany

PostPosted: Wed Dec 17, 2008 9:56 am    Post subject: Reply with quote

maybe localization helps? (/etc/locale.gen | /etc/env.d/02locale)
Code:
sed-notebook ~ # file /var/log/messages
/var/log/messages: UTF-8 Unicode English text, with escape sequences
sed-notebook ~ # file /var/log/emerge.log
/var/log/emerge.log: ASCII text
is what I get and less shows only real binary data as hexdumps. (And I am really happy that!)

On the other hand, which version of "file" do you have?
Code:
sed-notebook ~ # eix file -I -c -C sys-apps
[I] sys-apps/file (4.23@04.11.2008): identify a file's format by scanning binary data for patterns

_________________
Important German:
  1. "Aha" - German reaction to pretend that you are really interested while giving no f*ck.
  2. "Tja" - German reaction to the apocalypse, nuclear war, an alien invasion or no bread in the house.
Back to top
View user's profile Send private message
cgill27
n00b
n00b


Joined: 15 Mar 2008
Posts: 23

PostPosted: Wed Dec 17, 2008 5:03 pm    Post subject: Reply with quote

Code:

# locale-gen
 * Generating 2 locales (this might take a while) with 1 jobs
 *  (1/2) Generating en_US.ISO-8859-1 ...                                                              [ ok ]
 *  (2/2) Generating en_US.UTF-8 ...                                                                        [ ok ]
 * Generation complete


Code:

# eix file -I -c -C sys-apps
[I] sys-apps/file (4.23@12/16/08): identify a file's format by scanning binary data for patterns


Code:

# file /var/log/messages
/var/log/messages: data
# file /var/log/emerge.log
/var/log/emerge.log: ASCII text
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum