od 命令详解

| 选择喜欢的代码风格  

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

od 命令安装:


-bash/zsh: od command not found

#Debian
apt-get install coreutils

#Ubuntu
apt-get install coreutils

#Alpine
apk add coreutils

#Arch Linux
pacman -S coreutils

#Kali Linux
apt-get install coreutils

#CentOS
yum install coreutils

#Fedora
dnf install coreutils

#OS X
brew install coreutils

#Raspbian
apt-get install coreutils

#Docker
docker run cmd.cat/od od

od 命令补充说明:


od 命令写入,使用八进制字节默认的 FILE 标准输出。如果指定了多个 FILE ,则 od 以列出的顺序将它们串联起来以形成输入。如果没有 FILEFILE 为破折号( - ),则 od 从标准输入读取。

od 命令语法:


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

od 命令选项:


-A RADIX, --address-radix=RADIX decide how file offsets are printed

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

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

-S BYTES, --strings[=BYTES] output strings of at least BYTES graphic chars

-t TYPE, --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

--traditional accept arguments in traditional form

--help  display help and exit

--version display version information and exit

od 命令格式规范:


-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 ASCII 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

od 命令参数:


目标文件

od 命令实例:


od 以八进制格式(每个整数一个字节)显示 file.txt 的内容。

od -b file.txt

ob 以ASCII(字符)格式显示 file.txt 的内容,字节偏移显示为十六进制:

od -Ax -c file.txt

ob 使用默认设置显示文件:八进制格式,每行8个字节,八进制字节偏移量,重复行用`*`代替:

od path/to/file

ob 以详细模式显示文件,即不将重复行替换为`*`:

od -v path/to/file

ob 以十六进制格式(2字节为单位)显示文件,以十进制格式显示字节偏移量:

od --format=x --address-radix=d -v path/to/file

ob 以十六进制格式(1字节为单位)显示文件,每行4字节:

od --format=x1 --width=4 -v path/to/file

ob 以十六进制格式显示文件及其字符表示,并且不打印字节偏移量:

od --format=xz --address-radix=n -v path/to/file

ob 从第 500 个字节开始仅读取文件的 100 个字节:

od --read-bytes 100 --skip-bytes=500 -v path/to/file

od 命令扩展阅读:




od 命令评论