in order to see the header of file (wmv,mp3, binary[pe/elf/machos], avi, etc....) which command line in unix could perform this ?

looking forward for some answers :D

  • 3
    Not programming. Did you even try the file command?
    – leppie
    Jan 25, 2011 at 5:12
  • 1
    do you want to see the first few bytes in hex? xxd is your friend.
    – akira
    Jan 25, 2011 at 9:44

6 Answers 6


I generally use od -bc {filename} | head to look at the header of a binary file. view works too, but I find that it is generally better to see the output directly on the terminal.


The question is a bit wide in scope, so the suggestion is to approach in steps.

  1. Use file command to get first level information: File (Unix).
  2. Then subsequently use FFMPG for audio video headers.
  3. And dump for object files.

See also: ffmpeg command line options


head will show the first few lines of code in a file.

A 'good' way of getting it into hex, pull the file into gvim and in the 'menu' (if you don't like typing abstract commands) there is an option to put the data through xxd getting it into hex. This is a good universal place to open a file like this as you'll be able to copy/paste plus have all of the wonderful tools of vim at your fingertips!


Just for completeness... Also you can do this directly in vim using xxd. I've used something similar to do binary patches to files.

vim <file> //opens the files
:%!xxd     //feeds the current buffer through xxd and shows the resulting hexdump
<edit your file in vim> //be sure to keep alignment of bytes in the "hex" portion (the text side doesn't matter)
:%!xxd -r //take the hexdump back to the binary file

Another program is bvi if you are familiar with vi.


Identify is also useful for images:

Identify describes the format and characteristics of one or more image files. It will also report if an image is incomplete or corrupt. The information displayed includes the scene number, the file name, the width and height of the image, whether the image is colormapped or not, the number of colors in the image, the number of bytes in the image, the format of the image (JPEG, PNM, etc.), and finally the number of seconds it took to read and process the image.


For ELF files, I guess that readelf is recommended.

For instance:

$ readelf -h ELF_FILE
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           ARM
  Version:                           0x1
  Entry point address:               0x15565
  Start of program headers:          52 (bytes into file)
  Start of section headers:          2919696 (bytes into file)
  Flags:                             0x5000402, Version5 EABI, hard-float ABI, <unknown>
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         8
  Size of section headers:           40 (bytes)
  Number of section headers:         39
  Section header string table index: 36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.