如何创建具有给定结构的文件?

如何创建具有给定结构的文件?

如何创建一个文件,其中包含 X 个字节的 0、Y 个字节的数字 7(即十六进制中的 0x07,二进制中的 00000111)、Z 个随机字节和 T 个字节的数字 25(十六进制中的 0x19,二进制中的 00011001)。最后,该文件的大小应为 X+Y+Z+T 字节。

答案1

从软件中心安装“ghex”。

进入终端并运行touch hexfile

打开 ghex,然后打开“hexfile”。

按插入,然后输入您想要的字节。

节省。


您可能能够在文件中保存类似的内容,更改变量(按照指示),并使其可执行(chmod +x filename),然后运行它./filename

#!/bin/bash
#(C) 2011 Erik B. Andersen This script is licensed under the latest non-draft
#version of the AGPL as published by the Free Software Foundation (currently 
#at http://www.gnu.org/licenses/) .
# Set the following four variables.
X=
Y=
Z=
T=
#######Don't need to change anything past here.
y=0
t=0
head -c $X /dev/zero >> structurefile
while [ $y -lt $Y ]; do echo -n -e "\x07"; y=$(($y+1)); done >> structurefile
head -c $Z /dev/urandom >> structurefile
while [ $t -lt $T ]; do echo -n -e "\x19"; t=$(($t+1)); done >> structurefile

相关内容