Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a file with .dat extension how can i view the contents of the file in hexa ? mean if i open the file i should be able to see the contents in hex format, can this be done using vim editor. I have installed tnef but when i try opening this dat file it says "Seems not to be a TNEF file"

share|improve this question

migrated from stackoverflow.com Jul 4 '12 at 7:48

This question came from our site for professional and enthusiast programmers.

    
That depends on what the file is. .dat is such a generic extension that it could be anything. Where did you get the file from? What type of data do you expect to be contained in the file? –  Piskvor Jul 4 '12 at 9:36

5 Answers 5

can this be done using vim editor[?].

Here's one way, from some blog Google found

So, open a file in vi as usual, hit escape and type: :%!xxd to switch into hex mode

And when your [sic] done hit escape again and type: :%!xxd -r to exit from hex mode.

Okay, so this isn’t actaully switching to vi’s ‘hex mode’; vi doesn’t have one. What the above actually does is to stream vi’s buffer through the external program ‘xxd’.

A commenter added

Try adding the following to /etc/vim/vimrc.local, and you’ll get keyboard shortcuts for switching back and forth (F8 and F7).

" Switch to hex-editor`
noremap <F8> :%!xxd<CR> 
" Switch back 
noremap <F7> :%!xxd -r<CR>

There is also a Vim tip on this subject.

share|improve this answer

Firstly, the dat file can be anything.

Use file <yourfile>.dat to find what it is. Then depending out its type, use specific application to open it.

mplayer <yourfile>.dat
gedit <yourfile>.dat
share|improve this answer

file is a good command to try first.

After that, I use cat -v | less or od -a | less for a "readable" view. Check the man pages for od and file.

xxd is more modern than od, and often generates a prettier view, but sometimes only od is available.

share|improve this answer

Of course mc (in many serious distros available from basic install CD) has HEX viewer. It can be accessed id view mode by F4

share|improve this answer

Some common Linux utilities for viewing hex dumps are:

  • xxd
  • hexdump
share|improve this answer
    
+on kde: okteta –  Tobas Jul 4 '12 at 7:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.