• Linux命令学习总结:hexdump


    命令简介:

    hexdump是Linux下的一个二进制文件查看工具,它可以将二进制文件转换为ASCII、八进制、十进制、十六进制格式进行查看。

    指令所在路径:/usr/bin/hexdump

     

    命令语法:

    hexdump: [-bcCdovx] [-e fmt] [-f fmt_file] [-n length] [-s skip] [file ...]

     

    命令参数:

    此命令参数是Red Hat Enterprise Linux Server release 5.7下hexdump命令参数,不同版本Linux的hexdump命令参数有可能不同。

    参数

    长参数

    描叙

    -b

     

    每个字节显示为8进制。一行共16个字节,一行开始以十六进制显示偏移值

    -c

     

    每个字节显示为ASCII字符

    -C

     

    每个字节显示为16进制和相应的ASCII字符

    -d

     

    两个字节显示为10进制

    -e

     

    格式化输出

    -f

     

    Specify a file that contains one or more newline separated format strings.  Empty lines and lines whose first non-blank character is a hash mark (#) are ignored.

    -n

     

    只格式前n个长度的字符

    -o

     

    两个字节显示为8进制

    -s

     

    从偏移量开始输出

    -v

     

    The -v option causes hexdump to display all input data.  Without the -v option, any number of groups of output lines, which would be identical to the immediately preceding group of output lines

    -x

     

    双字节十六进制显示

     

    使用示例:

     

    1: 查看hexdmp命令的帮助信息

    [root@DB-Server ~]# man hexdump

     

    2: 以8进制显示文件里面的字符。

    [root@DB-Server ~]# cat >test.txt
    ABCDEF    
    GHIJKM
    123456
    [root@DB-Server ~]#  hexdump -b test.txt
    0000000 101 102 103 104 105 106 012 107 110 111 112 113 115 012 061 062
    0000010 063 064 065 066 012                                            
    0000015

    注意:一行共16个字节,一行开始以十六进制显示偏移值(如下所示,第一行字符串只显示到D,第十六个字节,后面的F12*DFDF换行显示)

    [root@DB-Server ~]# cat >test.txt
    ABCDEFGHIJKLMNODF12*DFDF
     
    [2]+  Stopped                 cat > test.txt
    You have new mail in /var/spool/mail/root
    [root@DB-Server ~]# hexdump -b test.txt 
    0000000 101 102 103 104 105 106 107 110 111 112 113 114 115 116 117 104
    0000010 106 061 062 052 104 106 104 106 012                            
    0000019
    [root@DB-Server ~]# hexdump -c test.txt 
    0000000   A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   D
    0000010   F   1   2   *   D   F   D   F  
                                
    0000019

    clip_image001

     

    3:以ASCII字符显示文件中字符

    [root@DB-Server ~]# hexdump -c test.txt 
    0000000   A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   D
    0000010   F   1   2   *   D   F   D   F  
                                
    0000019
     

    hexdump 以ASCII字符显示时,可以输出换行符,这个功能可以用来检查文件是Linux的换行符格式还是Widows格式换行符。如下所示

    clip_image002

     

    4:以16进制和相应的ASCII字符显示文件里的字符

    [root@DB-Server ~]# hexdump -C test.txt 
    00000000  41 42 43 44 45 46 47 48  49 4a 4b 4c 4d 4e 4f 44  |ABCDEFGHIJKLMNOD|
    00000010  46 31 32 2a 44 46 44 46  0a                       |F12*DFDF.|
    00000019

     

    5:只格式文件中前n个字符

    [root@DB-Server ~]# hexdump -C -n 5 test.txt 
    00000000  41 42 43 44 45                                    |ABCDE|
    00000005

     

    6:以偏移量开始格式输出。如下所示指定参数-s 5 ,前面的ABCDE字符没有了。

     
    [root@DB-Server ~]# hexdump -C test.txt 
    00000000  41 42 43 44 45 46 47 48  49 4a 4b 4c 4d 4e 4f 44  |ABCDEFGHIJKLMNOD|
    00000010  46 31 32 2a 44 46 44 46  0a                       |F12*DFDF.|
    00000019
    [root@DB-Server ~]# hexdump -C -s 5 test.txt 
    00000005  46 47 48 49 4a 4b 4c 4d  4e 4f 44 46 31 32 2a 44  |FGHIJKLMNODF12*D|
    00000015  46 44 46 0a                                       |FDF.|
    00000019
  • 相关阅读:
    Salesforce LWC学习(三十七) Promise解决progressindicator的小问题
    Salesforce Consumer Goods Cloud 浅谈篇三之 行动计划(Action Plan)相关配置
    python 3.7环境安装并使用csv
    分享数据库优化文章
    php 5.4 var_export的改进
    CentOS7 启动 firewalld 防火墙失败,查看日志提示超时
    使用 SSL 加密的 JDBC 连接 SAP HANA 数据库
    CAS学习笔记一:CAS 授权服务器简易搭建
    202110期自考总结
    自定义 OpenShift s2i 镜像与模板——OracleJDK8
  • 原文地址:https://www.cnblogs.com/kerrycode/p/5077687.html
Copyright © 2020-2023  润新知