Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to create a file that just contains a binary number. I think that touch can be used to create an empty file, but is there any way I can fill it with a binary number e.g. 10 (ten)? And how can I validate that the file contains the binary value of ten?

See also How can I check the Base64 value for an integer?

share|improve this question
up vote 5 down vote accepted

Convert the number to hex (in this case A) and then do:

echo -en '\xA' > file
share|improve this answer
Thanks, however, now I don't know how I can validate this anser. E.g could I write the number 65 and in some way print that with a command? – Jonas Oct 24 '10 at 15:41
@Jonas: hexdump file will display the bytes in a file as hex. – sepp2k Oct 24 '10 at 15:42
Thanks for hexdump. I added that to my question. However I don't think echoing the hexnumber is working. When I look at the file with hexdump file I get 0000000 785c 0041 0000003 and I get a different value for echo -n '\xa > file` – Jonas Oct 24 '10 at 15:55
The file seems to contain something more than a number, and with hexdump should the hexvalue \xA be shown as A or a? But it doesn't in this case. – Jonas Oct 24 '10 at 15:58
@Jonas: Ok, my bad. I tested this in zsh and apparently zsh's echo behaves differently than bash's. In bash you need the -e option to echo for \x to work. – sepp2k Oct 24 '10 at 16:01

Your Answer


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

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