arv*_*ndh 6 linux command-line binary-files xxd
我一直在xxd
用来创建文件的六进制表示(任何文件,如 .jpg、.docx、.zip 等),像这样,..
$ xxd -p original_file.zip > hexa_format.txt
Run Code Online (Sandbox Code Playgroud)
并扭转
$ xxd -r -p hexa_format.txt > original_file.zip
Run Code Online (Sandbox Code Playgroud)
如果有人觉得这不是正确的方法,请纠正我。无论如何这不是我的问题。现在我必须将它们转换为二进制而不是六进制。所以命令是这样的,如果我是正确的。
$ xxd -p -b original_file.zip > binary_format.txt
Run Code Online (Sandbox Code Playgroud)
我的问题是,
如何将其从上述命令创建的二进制文件 (binary_format.txt) 反转回原始文件。xxd 的手册页说它不能完成(在最后一行)。
-b | -bits
Switch to bits (binary digits) dump, rather than hexdump. This
option writes octets as eight digits "1"s and "0"s instead of a
normal hexadecimal dump. Each line is preceded by a line number
in hexadecimal and followed by an ascii (or ebcdic) representa?
tion. The command line switches -r, -p, -i do not work with this
mode.
Run Code Online (Sandbox Code Playgroud)
如果无法做到这一点,是否还有其他命令可以做到这一点,。就像管道多个命令一样。
您必须编写自己的二进制到十六进制函数...
cut -f2-8 -d' ' infile | tr -d '\n' | tr ' ' '\n' | while read l;
do
echo -n $(bin_to_hex($l)) >> outfile
(( ++n ))
(( n % 60 == 0)) && echo "" >> outfile
done
Run Code Online (Sandbox Code Playgroud)
-p
这应该输出与随后可以运行的格式相同的格式-r
。如果您阅读 for 的手册页,xxd
您会发现没有-r
for -b
。您在问题中包含的摘录中是这样说的。