linux 命令 xxd


xxd,能夠查看linux下文件的二進制表示。man一下xxd。能夠得到下面信息

NAME
       xxd - make a hexdump or do the reverse.


SYNOPSIS
       xxd -h[elp]
       xxd [options] [infile [outfile]]
       xxd -r[evert] [options] [infile [outfile]]


DESCRIPTION
       xxd  creates  a hex dump of a given file or standard input.  It can also convert a hex dump back to its original binary form.  Like uuencode(1) and uudecode(1) it allows the
       transmission of binary data in a `mail-safe' ASCII representation, but has the advantage of decoding to standard output.  Moreover, it can be used  to  perform  binary  file
       patching.


OPTIONS
       If no infile is given, standard input is read.  If infile is specified as a `-' character, then input is taken from standard input.  If no outfile is given (or a `-' charac‐
       ter is in its place), results are sent to standard output.


       Note that a "lazy" parser is used which does not check for more than the first option letter, unless the option is followed by a parameter.  Spaces between a  single  option
       letter and its parameter are optional.  Parameters to options can be specified in decimal, hexadecimal or octal notation.  Thus -c8, -c 8, -c 010 and -cols 8 are all equiva‐
       lent.


       -a | -autoskip
              toggle autoskip: A single '*' replaces nul-lines.  Default off.


       -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) representation. The command line switches -r, -p, -i do not work with this mode.


       -c cols | -cols cols
              format <cols> octets per line. Default 16 (-i: 12, -ps: 30, -b: 6). Max 256.


       -E | -EBCDIC
              Change  the character encoding in the righthand column from ASCII to EBCDIC.  This does not change the hexadecimal representation. The option is meaningless in combi‐
              nations with -r, -p or -i.


       -g bytes | -groupsize bytes
              separate the output of every <bytes> bytes (two hex characters or eight bit-digits each) by a whitespace.  Specify -g 0 to suppress grouping.  <Bytes> defaults  to  2
              in normal mode and 1 in bits mode.  Grouping does not apply to postscript or include style.


       -h | -help
              print a summary of available commands and exit.  No hex dumping is performed.

      -i | -include
              output in C include file style. A complete static array definition is written (named after the input file), unless xxd reads from stdin.


       -l len | -len len
              stop after writing <len> octets.


       -p | -ps | -postscript | -plain
              output in postscript continuous hexdump style. Also known as plain hexdump style.


       -r | -revert
              reverse operation: convert (or patch) hexdump into binary.  If not writing to stdout, xxd writes into its output file without truncating it. Use the combination -r -p
              to read plain hexadecimal dumps without line number information and without a particular column layout. Additional Whitespace and line-breaks are allowed anywhere.


       -seek offset
              When used after -r: revert with <offset> added to file positions found in hexdump.


       -s [+][-]seek
              start at <seek> bytes abs. (or rel.) infile offset.  + indicates that the seek is relative to the current stdin file  position  (meaningless  when  not  reading  from
              stdin).   - indicates that the seek should be that many characters from the end of the input (or if combined with +: before the current stdin file position).  Without
              -s option, xxd starts at the current file position.


       -u     use upper case hex letters. Default is lower case.


       -v | -version
              show version string.


舉例說明:

比方有以下這個文件叫proces_watch,假設記不住選項也沒什么關系

1)、由於有些文件比較大,假設直接xxd 。那么刷屏刷的你也看不到你想要的。能夠結合一下more命令進行查看

即 

xxd 輸入文件  |  more

這個時候,就能夠一屏一屏的查看!

!!

2)、命令選項 -l。能夠查看從文件起始查看多少個字節。比如查看前16個字節的內容

能夠例如以下

xxd -l 長度 輸入文件

root@user-virtual-machine:/tftpboot# xxd -l 16 process_watch
0000000: 7f45 4c46 0101 0103 0400 0000 0000 0000  .ELF............

3)、假設,這樣的顯示風格看着不舒服,能夠使用 -g 選項,選擇分組字節數,默覺得2

root@user-virtual-machine:/tftpboot# xxd -g1 -l 16 process_watch

0000000: 7f 45 4c 46 01 01 01 03 04 00 00 00 00 00 00 00  .ELF............

4)、假設想把輸入文件,定位成一個數組形式。那么選擇 -i選項

root@user-virtual-machine:/tftpboot# xxd -i process_watch | more
unsigned char process_watch[] = {
  0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x03, 0x04, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00,
  0x20, 0xf6, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x02, 0x00, 0x00, 0x04, 0x34, 0x00, 0x20, 0x00, 0x02, 0x00, 0x28, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x7f, 0x7e, 0x00, 0x00,
  0x7f, 0x7e, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
  0x01, 0x00, 0x00, 0x00, 0x60, 0x2e, 0x00, 0x00, 0x60, 0x2e, 0x02, 0x00,
  0x60, 0x2e, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x06, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0xf2, 0xa0, 0xad, 0xd4,
  0x55, 0x50, 0x58, 0x21, 0x7c, 0x08, 0x0d, 0x17, 0x00, 0x00, 0x00, 0x00,
  0x40, 0x87, 0x01, 0x00, 0x40, 0x87, 0x01, 0x00, 0x34, 0x01, 0x00, 0x00,
  0x92, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf9, 0x7f, 0x45, 0x4c,
  0x46, 0x01, 0x64, 0x00, 0x3f, 0x02, 0x00, 0x28, 0x00, 0x7e, 0x0d, 0xbc,

5)、假設想從文件某個偏移量開始顯示數據。須要用的-s選項。即s=seek
root@user-virtual-machine:/tftpboot# xxd -g1 -s 16 -l 16 process_watch
0000010: 02 00 28 00 01 00 00 00 20 f6 00 00 34 00 00 00  ..(..... ...4...












免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM