实用笔记08

xxd命令

xxd命令的作用是将给定的标准输入或者文件,做一次十六进制的输出,反之它也可以将十六进制的输出转换为原来的二进制格式。

  • xxd -h
Usage:
       xxd [options] [infile [outfile]]
    or
       xxd -r [-s [-]offset] [-c cols] [-ps] [infile [outfile]]
Options:
    -a          toggle autoskip: A single '*' replaces nul-lines. Default off.
    -b          binary digit dump (incompatible with -ps,-i,-r). Default hex.
    -C          capitalize variable names in C include file style (-i).
    -c cols     format <cols> octets per line. Default 16 (-i: 12, -ps: 30).
    -E          show characters in EBCDIC. Default ASCII.
    -e          little-endian dump (incompatible with -ps,-i,-r).
    -g          number of octets per group in normal output. Default 2 (-e: 4).
    -h          print this summary.
    -i          output in C include file style.
    -l len      stop after <len> octets.
    -o off      add <off> to the displayed file position.
    -ps         output in postscript plain hexdump style.
    -r          reverse operation: convert (or patch) hexdump into binary.
    -r -s off   revert with <off> added to file positions found in hexdump.
    -s [+][-]seek  start at <seek> bytes abs. (or +: rel.) infile offset.
    -u          use upper case hex letters.
    -v          show version: "xxd V1.10 27oct98 by Juergen Weigert".
  • 将文件内容转换为十六进制: xxd infile
xxd test.txt
------------------------------------------------------------------ 
00000000: 626f 6f6c 2063 6c6f 7365 5f66 6c61 6720  bool close_flag 
00000010: 3d20 2173 7472 6361 7365 636d 7028 5f70  = !strcasecmp(_p
00000020: 6172 7365 725b 2243 6f6e 6e65 6374 696f  arser["Connectio
00000030: 6e22 5d2e 6461 7461 2829 2c20 2263 6c6f  n"].data(), "clo
00000040: 7365 2229 3b0a 5f6d 6564 6961 496e 666f  se");._mediaInfo
00000050: 2e5f 7374 7265 616d 6964 2e65 7261 7365  ._streamid.erase
00000060: 285f 6d65 6469 6149 6e66 6f2e 5f73 7472  (_mediaInfo._str
00000070: 6561 6d69 642e 7369 7a65 2829 202d 2075  eamid.size() - u
00000080: 726c 5f73 7566 6669 782e 7369 7a65 2829  rl_suffix.size()
00000090: 293b 0a77 6561 6b5f 7074 723c 4874 7470  );.weak_ptr<Http
000000a0: 5365 7373 696f 6e3e 2077 6561 6b5f 7365  Session> weak_se
000000b0: 6c66 203d 2064 796e 616d 6963 5f70 6f69  lf = dynamic_poi
000000c0: 6e74 6572 5f63 6173 743c 4874 7470 5365  nter_cast<HttpSe
000000d0: 7373 696f 6e3e 2873 6861 7265 645f 6672  ssion>(shared_fr
000000e0: 6f6d 5f74 6869 7328 2929 3b              om_this());

十六进制转储获得了它的默认格式,例如:
索引行数
每组的默认八位字节数为2,其分组大小为4字节
标准列长度为16位,带有空格

  • xxd跳过n bytes: xxd -s n test.txt
    跳过32个bytes
xxd -s 0x20 test.txt
00000020: 6172 7365 725b 2243 6f6e 6e65 6374 696f  arser["Connectio
00000030: 6e22 5d2e 6461 7461 2829 2c20 2263 6c6f  n"].data(), "clo
00000040: 7365 2229 3b0a 5f6d 6564 6961 496e 666f  se");._mediaInfo
00000050: 2e5f 7374 7265 616d 6964 2e65 7261 7365  ._streamid.erase
00000060: 285f 6d65 6469 6149 6e66 6f2e 5f73 7472  (_mediaInfo._str
00000070: 6561 6d69 642e 7369 7a65 2829 202d 2075  eamid.size() - u
00000080: 726c 5f73 7566 6669 782e 7369 7a65 2829  rl_suffix.size()
00000090: 293b 0a77 6561 6b5f 7074 723c 4874 7470  );.weak_ptr<Http
000000a0: 5365 7373 696f 6e3e 2077 6561 6b5f 7365  Session> weak_se
000000b0: 6c66 203d 2064 796e 616d 6963 5f70 6f69  lf = dynamic_poi
000000c0: 6e74 6572 5f63 6173 743c 4874 7470 5365  nter_cast<HttpSe
000000d0: 7373 696f 6e3e 2873 6861 7265 645f 6672  ssion>(shared_fr
000000e0: 6f6d 5f74 6869 7328 2929 3b              om_this());
  • 限制标准输出的长度: xxd -l n test.txt
xxd -l 0x20 text.txt
00000000: 626f 6f6c 2063 6c6f 7365 5f66 6c61 6720  bool close_flag 
00000010: 3d20 2173 7472 6361 7365 636d 7028 5f70  = !strcasecmp(_p
  • 将文件内容转换为二进制文件: xxd -b text.txt
xxd -b text.txt 
00000000: 01100010 01101111 01101111 01101100 00100000 01100011  bool c
00000006: 01101100 01101111 01110011 01100101 01011111 01100110  lose_f
0000000c: 01101100 01100001 01100111 00100000 00111101 00100000  lag = 
00000012: 00100001 01110011 01110100 01110010 01100011 01100001  !strca
00000018: 01110011 01100101 01100011 01101101 01110000 00101000  secmp(
0000001e: 01011111 01110000 01100001 01110010 01110011 01100101  _parse
00000024: 01110010 01011011 00100010 01000011 01101111 01101110  r["Con
0000002a: 01101110 01100101 01100011 01110100 01101001 01101111  nectio
00000030: 01101110 00100010 01011101 00101110 01100100 01100001  n"].da
00000036: 01110100 01100001 00101000 00101001 00101100 00100000  ta(), 
0000003c: 00100010 01100011 01101100 01101111 01110011 01100101  "close
00000042: 00100010 00101001 00111011 00001010 01011111 01101101  ");._m
00000048: 01100101 01100100 01101001 01100001 01001001 01101110  ediaIn
0000004e: 01100110 01101111 00101110 01011111 01110011 01110100  fo._st
00000054: 01110010 01100101 01100001 01101101 01101001 01100100  reamid
0000005a: 00101110 01100101 01110010 01100001 01110011 01100101  .erase
00000060: 00101000 01011111 01101101 01100101 01100100 01101001  (_medi
00000066: 01100001 01001001 01101110 01100110 01101111 00101110  aInfo.
0000006c: 01011111 01110011 01110100 01110010 01100101 01100001  _strea
00000072: 01101101 01101001 01100100 00101110 01110011 01101001  mid.si
00000078: 01111010 01100101 00101000 00101001 00100000 00101101  ze() -
0000007e: 00100000 01110101 01110010 01101100 01011111 01110011   url_s
00000084: 01110101 01100110 01100110 01101001 01111000 00101110  uffix.
0000008a: 01110011 01101001 01111010 01100101 00101000 00101001  size()
00000090: 00101001 00111011 00001010 01110111 01100101 01100001  );.wea
00000096: 01101011 01011111 01110000 01110100 01110010 00111100  k_ptr<
0000009c: 01001000 01110100 01110100 01110000 01010011 01100101  HttpSe
000000a2: 01110011 01110011 01101001 01101111 01101110 00111110  ssion>
000000a8: 00100000 01110111 01100101 01100001 01101011 01011111   weak_
000000ae: 01110011 01100101 01101100 01100110 00100000 00111101  self =
000000b4: 00100000 01100100 01111001 01101110 01100001 01101101   dynam
000000ba: 01101001 01100011 01011111 01110000 01101111 01101001  ic_poi
000000c0: 01101110 01110100 01100101 01110010 01011111 01100011  nter_c
000000c6: 01100001 01110011 01110100 00111100 01001000 01110100  ast<Ht
000000cc: 01110100 01110000 01010011 01100101 01110011 01110011  tpSess
000000d2: 01101001 01101111 01101110 00111110 00101000 01110011  ion>(s
000000d8: 01101000 01100001 01110010 01100101 01100100 01011111  hared_
000000de: 01100110 01110010 01101111 01101101 01011111 01110100  from_t
000000e4: 01101000 01101001 01110011 00101000 00101001 00101001  his())
000000ea: 00111011                                               ;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值