9

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.

jww
  • 97,681
  • 90
  • 411
  • 885
Mike Egren
  • 205
  • 1
  • 3
  • 7

3 Answers3

15

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
jaypal singh
  • 74,723
  • 23
  • 102
  • 147
mokalan
  • 178
  • 5
1

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

xmoex
  • 2,602
  • 22
  • 36
0

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

A: "dd" is certainly on option. One of many :)

How can I generate those 10 bytes of 7?

A: However you want. For example, you can write a C program:

#include<stdio.h>

#define MY_FILE "7";

char my_data[] = {
  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa
};

int
main (int argc, char *argv[])
{  
  FILE *fp = open (MY_FILE, "wb");
  if (!fp) {
    perror ("File open error!");
    return 1;
  }
  fwrite (my_data, sizeof (my_data), fp);
  fclose (fp);
  return 0;
}
paulsm4
  • 114,292
  • 17
  • 138
  • 190