LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using dd command to write bytes (https://www.linuxquestions.org/questions/linux-newbie-8/using-dd-command-to-write-bytes-851221/)

dgs012 12-19-2010 12:29 PM

Using dd command to write bytes
 
I'm using
Code:

dd if=/dev/zero bs=5 count=1 of=binfile
Then I run

Code:

hexdump -b binfile
0000000 000 000 000 000 000

How can I use dd to write bytes of 1 or 5 for example?
hexdump -b will return
0000000 001 001 001 001 001
or
0000000 005 005 005 005 005

colucix 12-19-2010 02:08 PM

Maybe with something like this:
Code:

$ for i in {1..5}; do echo -n $'\x01'; done | dd of=binfile
0+1 records in
0+1 records out
5 bytes (5 B) copied, 7.0541e-05 s, 70.9 kB/s

$ hexdump -b binfile
0000000 001 001 001 001 001                                           
0000005

Another option is to use /dev/zero and change zeros on the fly using sed, e.g.
Code:

$ dd if=/dev/zero bs=5 count=1 | sed 's/\x00/\x01/g' > binfile
1+0 records in
1+0 records out
5 bytes (5 B) copied, 2.4654e-05 s, 203 kB/s

$ hexdump -b binfile
0000000 001 001 001 001 001                                           
0000005

The tr command may serve the same purpose.

dgs012 12-19-2010 03:52 PM

Thank you very much.

I used the second option because I needed to add the bytes at the end of the file.

Worked great!


All times are GMT -5. The time now is 04:29 PM.