方法总共有三种:
- od - dump files in octal and other formats
- xxd - make a hexdump or do the reverse.
- hexdump, hd — ASCII, decimal, hexadecimal, octal dump
这三种方法都是用来以指定格式查看文件,没有本质区别。
其中只有 od 是 POSIX 标准,原因参考 Single UNIX rationale。
以上面三种方式分别实现 hex + ASCII 显示:
od
$ od -Ax -tx1z .dircache/index
000000 43 52 49 44 01 00 00 00 01 00 00 00 38 f7 ac da >CRID........8...<
000010 a1 c2 12 6e 2c 39 a6 4a cc 65 ce 6f d9 ae 50 df >...n,9.J.e.o..P.<
000020 b4 b9 06 61 1b 4c 95 19 b4 b9 06 61 1b 4c 95 19 >...a.L.....a.L..<
000030 05 08 00 00 ca 1f 10 00 b4 81 00 00 e8 03 00 00 >................<
000040 e8 03 00 00 0d 00 00 00 0a 3b 8a 97 55 ad c2 ed >.........;..U...<
000050 07 76 33 7c e2 ee 6b 14 4b f8 54 c2 08 00 74 65 >.v3|..k.K.T...te<
000060 73 74 2e 74 78 74 00 00 >st.txt..<
000068
xxd
$ xxd .dircache/index
00000000: 4352 4944 0100 0000 0100 0000 38f7 acda CRID........8...
00000010: a1c2 126e 2c39 a64a cc65 ce6f d9ae 50df ...n,9.J.e.o..P.
00000020: b4b9 0661 1b4c 9519 b4b9 0661 1b4c 9519 ...a.L.....a.L..
00000030: 0508 0000 ca1f 1000 b481 0000 e803 0000 ................
00000040: e803 0000 0d00 0000 0a3b 8a97 55ad c2ed .........;..U...
00000050: 0776 337c e2ee 6b14 4bf8 54c2 0800 7465 .v3|..k.K.T...te
00000060: 7374 2e74 7874 0000 st.txt..
hexdump
$ hexdump -C .dircache/index
00000000 43 52 49 44 01 00 00 00 01 00 00 00 38 f7 ac da |CRID........8...|
00000010 a1 c2 12 6e 2c 39 a6 4a cc 65 ce 6f d9 ae 50 df |...n,9.J.e.o..P.|
00000020 b4 b9 06 61 1b 4c 95 19 b4 b9 06 61 1b 4c 95 19 |...a.L.....a.L..|
00000030 05 08 00 00 ca 1f 10 00 b4 81 00 00 e8 03 00 00 |................|
00000040 e8 03 00 00 0d 00 00 00 0a 3b 8a 97 55 ad c2 ed |.........;..U...|
00000050 07 76 33 7c e2 ee 6b 14 4b f8 54 c2 08 00 74 65 |.v3|..k.K.T...te|
00000060 73 74 2e 74 78 74 00 00 |st.txt..|```