¿Cómo creo un archivo con una estructura determinada?

¿Cómo creo un archivo con una estructura determinada?

¿Cómo creo un archivo que tiene X bytes de 0, Y bytes del número 7 (es decir, 0x07 en hexadecimal, 00000111 en binario), Z bytes aleatorios y T bytes del número 25 (0x19 en hexadecimal, 00011001 en binario)? Finalmente, este archivo debe tener un tamaño X+Y+Z+T bytes.

Respuesta1

Instale 'ghex' desde el centro de software.

Vaya a una terminal y ejecute touch hexfile.

Abra ghex, luego abra el 'archivo hexadecimal'.

Presione insertar, luego escriba los bytes que desee.

Ahorrar.


Es posible que pueda guardar algo como esto en un archivo, cambiar las variables (según las instrucciones) y hacerlo ejecutable ( chmod +x filename) y luego ejecutarlo ./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

información relacionada