如何建立具有給定結構的文件?

如何建立具有給定結構的文件?

如何建立一個文件,其中包含X 位元組的0、Y 位元組的數字7(即十六進位的0x07、二進位的00000111)、Z 隨機位元組和數字25 的T 位元組(十六進位的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

相關內容