echo bytes to a file

You have to take your codes into quotes:

echo -n -e '\x66\x6f\x6f' > byteFileForNow

cause otherwise shell replaces \x to x before it goes to echo -e.

ps. double escape will also work:

echo -n -e \\x66\\x6f\\x6f > byteFileForNow

Shell

In shell you can use printf:

printf "%b" '\x66\x6f\x6f' > file.bin

Note: %b - Print the associated argument while interpreting backslash escapes.

Perl

With perl, it is even simpler:

perl -e 'print pack("ccc",(0x66,0x6f,0x6f))' > file.bin

Python

If you've Python installed, try the following one-liner:

python -c $'from struct import pack\nwith open("file.bin", "wb") as f: f.write(pack("<bbb", *bytearray([0x66, 0x6f, 0x6f])))'


Testing:

$ hexdump file.bin 
0000000 66 6f 6f 

This might not answering directly the question, but you can also use vi in hex mode:

Open your file and type: ESC :%!xxd to switch into hex mode.

You will be able to edit the hex part (the text part will not be updated as you change the hex part).

When your are done hit escape again and type: ESC :%!xxd -r to write back the changes you did in hex mode (don't forget to save afterward).