Does there exist a program for Linux that can display raw binary data?

Each byte in my binary files represent a pixel, so it would be very useful if something like this exists where I could say

program_name --input=dat001.bin --width=200 --height=100

and it would display the pixels.

I wonder if gnuplot, can be used for this...?

  • 2
    Question does not make sense. To display raw binary data, it must be converted to a human readable form. Usually this form is hexadecimal, which you can use hd to format. Then you ask to see an image. If it is an image, then it is going to be in an image format ( like bmp ) that will at the very least, have a header that identifies the format, the width, height, color depth, and maybe also have a color palette attached.
    – psusi
    Jun 8, 2011 at 1:12
  • @psusi While the title would be better How to display raw pixel data, the intent of this question is clear, and totally makes sense to me. ("I want a program to let me specify the image meta data") Does it make more sense in hindsight (or perhaps after editing) to you also? Sep 1, 2015 at 12:54
  • @NathanKidd, ahh, yes.. if you know it is an image using a specific format but has no header, rather than being just arbitrary binary data... got ya.
    – psusi
    Sep 4, 2015 at 17:56
  • 1
    ffmpeg can to it: stackoverflow.com/a/15037011/5447906
    – anton_rh
    Feb 9, 2017 at 4:31

4 Answers 4


To see the "raw binary data", I would use the hex dump command hd or hexdump

$ hd -C a.txt
00000000  61 0a 61 61 0a 61 61 61  0a 61 61 61 61 0a 61 61  |a.aa.aaa.aaaa.aa|
00000010  61 61 61 0a 62 62 62 0a  62 62 62 62 0a 62 62 62  |aaa.bbb.bbbb.bbb|
00000020  62 62 0a 3c 62 65 67 69  6e 3e 0a 61 61 61 61 61  |bb.<begin>.aaaaa|
00000030  61 0a 61 61 61 61 61 61  61 0a 61 61 61 61 61 61  |a.aaaaaaa.aaaaaa|
00000040  61 61 0a                                          |aa.|

I don't know of any image format that consists of unstructured bytes - is the data 8-bit RGB values? If the file contains 30000 bytes is that RGB for 100x100 pixels or RGB for 50x200 pixels or RGB for 200x50 pixels or something else? Is there a palette? You have to know something about the organisation of the data!

To view it as an image I would use the NetPBM utilities or maybe ImageMagick to convert it to a form understood by an image viewer

If the above can't do the job I'd investigate writing a small Perl script

  • Where can I get this? I just did yum search hd on my Fedora desktop, and it didn't have it.
    – Sandra
    Jun 7, 2011 at 23:36
  • OKay. I need to see the pxiels as graphic...
    – Sandra
    Jun 7, 2011 at 23:37
  • 2
    The binary might be called hexdump. On SuSE it is in the util-linux package.
    – Turbo J
    Jun 8, 2011 at 0:30
  • FWIW it's also hexdump in Arch.
    – Sparhawk
    Oct 11, 2014 at 12:20

Okay, gnuplot can do it.



convert from ImageMagick

E.g., an 8-bit 2x3 grayscale:

printf '\x00\xFF\x88\xFF\x00\xFF' > in.bin


convert -depth 8 -size 3x2+0 gray:in.bin out.png

Command explanation:

  • -depth 8: each color has 8 bits
  • -size 2x3+0: 2x3 image. +0 means starting at offset 0 in the file. If there are metadata headers, you can skip them with the offset.
  • gray:in.bin: the input file is in.bin, and the format is gray, as defined at http://www.imagemagick.org/script/formats.php This weird notation is used because ImageMagick usually determines the format from the extension, but here there is no extension.

How to view such tiny outputs like this example

The problem now is how to view the such a tiny 3x2 output accurately. A direct eog:

eog out.png

is not very good because the image is too small, and if you zoom in a lot eog uses a display algorithm that mixes up pixels continuously, which is better for most pictures, but not for such a tiny image.

One good possibility is to run:

convert out.png -scale 300x out2.png

or directly in one go with:

convert -depth 8 -size 3x2+0 gray:in.bin -scale 300x out.png

-scale is needed instead of -resize, since -resize mixes pixel colors continuously up much like eog by default.


enter image description here

Anther option is to view it in Gimp:

gimp out.png

Image editors such as Gimp must show every single pixel separately if you zoom in enough.

RGB example

printf '\xFF\x00\x00\x00\xFF\x00\x00\x00\xFF' > in.bin
convert -depth 8 -size 3x1+0 rgb:in.bin out.png

or with the -scale to make it more viewable:

convert -depth 8 -size 3x1+0 rgb:in.bin -scale 300x out.png

enter image description here


Tested on Ubuntu 16.04, ImageMagick 6.8.9.

  • 1
    Another example: if you have a file in RGBA format (say /tmp/tex1.dat), you can view the converted image directly with Imagemagick's display as 128x256 pixel image with display -depth 8 -size 128x256+0 RGBA:/tmp/tex1.dat
    – sdaau
    Jan 15, 2016 at 13:48
  • What if the pixels have 10 ot 12 bits ? I have tried the -endian option but it seems that it works as the -depth 16, the image is very dark
    – sop
    Feb 15, 2017 at 14:28
  • @sop not sure about 10 12. 12 might work with depth 12? 10 I expect you to need to specify further how many bits per channel, since 10 is not divisible by 4 (RGBA) nor 3 (RGB). Not sure how to do this. Feb 16, 2017 at 14:09

If not wanting to view it directly but rather convert it the convert utility can do this:

To read from stdin, assuming 320 x 200 pixels, 8 bit gray, header of 0, saving to pic.png in PNG format.

convert -depth 8 -size 320x200+0 gray:- pic.png

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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