例如,我们如何将 10 个字节的“7”复制到文件中?
如何生成这 10 个字节的 7?
例如,对于 n 个零字节,我正在做dd if=/dev/zero of=myFile bs=1 count=10
.
您可以将零发送到标准输出并将它们转换为 7,或者您喜欢的任何内容。
dd if=/dev/zero bs=1 count=10 | tr "\0" "\7" > file.bin
echo
将输出重定向到dd
echo 7777777777 | dd of=myFile bs=1 count=10
或者
echo -e '\x7\x7\x7\x7\x7\x7\x7\x7\x7\x7' | dd of=myFile bs=1 count=10
如果你需要 7 的二进制表示
问:我们如何将例如 10 个字节的“7”复制到文件中?
A:“dd”当然是可选的。其中之一 :)
如何生成这 10 个字节的 7?
A:随便你。例如,您可以编写一个 C 程序:
#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;
}