国际访客建议访问 Primers 编程伙伴 国际版站点 > Bash 教程 > od 以获得更好的体验。

# Bash 的 od 命令

od [OPTION]... [FILE]...

!subtitle:功能

将文件转储为八进制或其它格式。

!subtitle:类型

可执行文件(/usr/bin/od),属于 coreutils

!subtitle:参数

  • OPTION 选项:

    • -A, --address-radix=RADIX - 文件偏移量的输出格式,RADIX 取值:

      • d - 十进制

      • o - 八进制

      • x - 十六进制

      • n - None

    • --endian={big|little} - 按照此字节序解析输入

    • -j, --skip-bytes=BYTES - 跳过开头的 BYTES 字节

    • -N, --read-bytes=BYTES - 仅转出 BYTES 字节

    • -S BYTES, --strings[=BYTES] - 仅打印长度不少于 BYTES 个可打印字符的以空字符(\0)结尾的字符串

    • -t, --format=TYPE - 输出格式(默认为 o2,八进制二字节):

      • a - 命名字符(以字符的名称而非本身显示),忽略高位

      • c - 可打印字符或转义字符

      • d[SIZE] - SIZE 字节的有符号十进制整数

      • f[SIZE] - SIZE 字节的浮点数

      • o[SIZE] - SIZE 字节的八进制整数

      • u[SIZE] - SIZE 字节的无符号十进制整数

      • x[SIZE] - SIZE 字节的十六进制整数

    • -v, --output-duplicates - 输出重复项,不用使用 * 省略

    • -w[BYTES], --width[=BYTES] - 每行输出 BYTE 字节;默认为 32

    • --traditional - 使用传统模式

    • --help - 显示帮助

    • --version - 显示版本

  • FILE - 文件列表,如果没有这个参数或指定为 -,则读取标准输入

# 示例

$ echo -e "Primers 编程伙伴 \n https://xplanc.org/primers/" | od
0000000 071120 066551 071145 020163 136347 163626 105650 136344
0000020 162231 132274 005040 064040 072164 071560 027472 074057
0000040 066160 067141 027143 071157 027547 071160 066551 071145
0000060 027563 000012
0000063
$ echo -e "Primers 编程伙伴 \n https://xplanc.org/primers/" | od -t c
0000000   P   r   i   m   e   r   s     347 274 226 347 250 213 344 274
0000020 231 344 274 264      \n       h   t   t   p   s   :   /   /   x
0000040   p   l   a   n   c   .   o   r   g   /   p   r   i   m   e   r
0000060   s   /  \n
0000063
$ echo -e "Primers 编程伙伴 \n https://xplanc.org/primers/" | od -t a
0000000   P   r   i   m   e   r   s  sp   g   < syn   g   (  vt   d   <
0000020  em   d   <   4  sp  nl  sp   h   t   t   p   s   :   /   /   x
0000040   p   l   a   n   c   .   o   r   g   /   p   r   i   m   e   r
0000060   s   /  nl
0000063

# 推荐阅读

# 手册

OD(1)                            User Commands                           OD(1)

NAME
       od - dump files in octal and other formats

SYNOPSIS
       od [OPTION]... [FILE]...
       od [-abcdfilosx]... [FILE] [[+]OFFSET[.][b]]
       od --traditional [OPTION]... [FILE] [[+]OFFSET[.][b] [+][LABEL][.][b]]

DESCRIPTION
       Write an unambiguous representation, octal bytes by default, of FILE to
       standard output.  With more than one FILE argument, concatenate them in
       the listed order to form the input.

       With no FILE, or when FILE is -, read standard input.

       If  first  and second call formats both apply, the second format is as‐
       sumed if the last operand begins with + or (if there are 2 operands)  a
       digit.  An OFFSET operand means -j OFFSET.  LABEL is the pseudo-address
       at  first byte printed, incremented when dump is progressing.  For OFF‐
       SET and LABEL, a 0x or 0X prefix indicates hexadecimal; suffixes may be
       . for octal and b for multiply by 512.

       Mandatory arguments to long options are  mandatory  for  short  options
       too.

       -A, --address-radix=RADIX
              output format for file offsets; RADIX is one of [doxn], for Dec‐
              imal, Octal, Hex or None

       --endian={big|little}
              swap input bytes according the specified order

       -j, --skip-bytes=BYTES
              skip BYTES input bytes first

       -N, --read-bytes=BYTES
              limit dump to BYTES input bytes

       -S BYTES, --strings[=BYTES]
              show only NUL terminated strings of at least BYTES (3) printable
              characters

       -t, --format=TYPE
              select output format or formats

       -v, --output-duplicates
              do not use * to mark line suppression

       -w[BYTES], --width[=BYTES]
              output  BYTES bytes per output line; 32 is implied when BYTES is
              not specified

       --traditional
              accept arguments in third form above

       --help display this help and exit

       --version
              output version information and exit

   Traditional format specifications may be intermixed; they accumulate:
       -a     same as -t a,  select named characters, ignoring high-order bit

       -b     same as -t o1, select octal bytes

       -c     same as -t c,  select printable characters or backslash escapes

       -d     same as -t u2, select unsigned decimal 2-byte units

       -f     same as -t fF, select floats

       -i     same as -t dI, select decimal ints

       -l     same as -t dL, select decimal longs

       -o     same as -t o2, select octal 2-byte units

       -s     same as -t d2, select decimal 2-byte units

       -x     same as -t x2, select hexadecimal 2-byte units

   TYPE is made up of one or more of these specifications:
       a      named character, ignoring high-order bit

       c      printable character or backslash escape

       d[SIZE]
              signed decimal, SIZE bytes per integer

       f[SIZE]
              floating point, SIZE bytes per float

       o[SIZE]
              octal, SIZE bytes per integer

       u[SIZE]
              unsigned decimal, SIZE bytes per integer

       x[SIZE]
              hexadecimal, SIZE bytes per integer

       SIZE is a number.   For  TYPE  in  [doux],  SIZE  may  also  be  C  for
       sizeof(char),   S  for  sizeof(short),  I  for  sizeof(int)  or  L  for
       sizeof(long).  If TYPE is f, SIZE may also be F  for  sizeof(float),  D
       for sizeof(double) or L for sizeof(long double).

       Adding  a z suffix to any type displays printable characters at the end
       of each output line.

   BYTES is hex with 0x or 0X prefix, and may have a multiplier suffix:
       b      512

       KB     1000

       K      1024

       MB     1000*1000

       M      1024*1024

       and so on for G, T, P, E, Z, Y, R, Q.  Binary  prefixes  can  be  used,
       too: KiB=K, MiB=M, and so on.

EXAMPLES
       od -A x -t x1z -v
              Display hexdump format output

       od -A o -t oS -w16
              The default output format used by od

AUTHOR
       Written by Jim Meyering.

REPORTING BUGS
       GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
       Report any translation bugs to <https://translationproject.org/team/>

COPYRIGHT
       Copyright  ©  2023  Free Software Foundation, Inc.  License GPLv3+: GNU
       GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
       This is free software: you are free  to  change  and  redistribute  it.
       There is NO WARRANTY, to the extent permitted by law.

SEE ALSO
       Full documentation <https://www.gnu.org/software/coreutils/od>
       or available locally via: info '(coreutils) od invocation'

GNU coreutils 9.4                 April 2024                             OD(1)
本文 更新于: 2025-11-27 09:38:15 创建于: 2025-11-27 09:38:15