Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy n bytes of data x to file

Tags:

linux

dd

How we can copy for example 10 bytes of '7' to a file?

How can I generate those 10 bytes of 7?

For example for n bytes of zero I'm doing dd if=/dev/zero of=myFile bs=1 count=10.

like image 514
Mike Egren Avatar asked Nov 24 '11 21:11

Mike Egren


2 Answers

You can send the zeros to stdout and translate them to 7, or what ever you like.

dd if=/dev/zero bs=1 count=10 | tr "\0" "\7" > file.bin
like image 98
mokalan Avatar answered Sep 23 '22 13:09

mokalan


redirect an echo output to dd

echo 7777777777 | dd of=myFile bs=1 count=10

or

echo -e '\x7\x7\x7\x7\x7\x7\x7\x7\x7\x7' | dd of=myFile bs=1 count=10

if you need the binary representation of 7

like image 21
xmoex Avatar answered Sep 21 '22 13:09

xmoex