Linux之超强16进制命令:xxd(三十)

简介: CSDN博客专家,专注Android/Linux系统,分享多mic语音方案、音视频、编解码等技术,与大家一起成长!

优质专栏:Audio工程师进阶系列原创干货持续更新中......】🚀

人生格言: 人生从来没有捷径,只有行动才是治疗恐惧和懒惰的唯一良药.
更多原创,欢迎关注:Android系统攻城狮

1.前言

本篇目的:理解xxd工具的用法

xxd 是一个 Linux 命令,它在文本和二进制之间进行转换,并且还可以显示文件的十六进制内容。它主要有两个功能:

  1. 二进制与十六进制的转换:xxd 可以将二进制文件转换为十六进制表示,并将结果输出到终端或保存到文件中。它还可以将十六进制文件转换回原始的二进制格式。这对于分析二进制文件、网络数据包以及编写脚本和工具非常有用。

  2. 十六进制文件的显示:xxd 还可以以十六进制和 ASCII 的形式显示文件的内容。这对于查看文件的内容、检查文件是否有特定的模式或用于调试目的非常有帮助。

2.实践

html 复制代码
# xxd -help
Usage:
       xxd [options] [infile [outfile]]
    or
       xxd -r [-s [-]offset] [-c cols] [-ps] [infile [outfile]]
Options:
    -a          toggle autoskip: A single '*' replaces nul-lines. Default off.
    -b          binary digit dump (incompatible with -ps,-i,-r). Default hex.
    -C          capitalize variable names in C include file style (-i).
    -c cols     format <cols> octets per line. Default 16 (-i: 12, -ps: 30).
    -E          show characters in EBCDIC. Default ASCII.
    -e          little-endian dump (incompatible with -ps,-i,-r).
    -g bytes    number of octets per group in normal output. Default 2 (-e: 4).
    -h          print this summary.
    -i          output in C include file style.
    -l len      stop after <len> octets.
    -o off      add <off> to the displayed file position.
    -ps         output in postscript plain hexdump style.
    -r          reverse operation: convert (or patch) hexdump into binary.
    -r -s off   revert with <off> added to file positions found in hexdump.
    -d          show offset in decimal instead of hex.
    -s [+][-]seek  start at <seek> bytes abs. (or +: rel.) infile offset.
    -u          use upper case hex letters.
    -v          show version: "xxd 2021-10-22 by Juergen Weigert et al."
  1. 安装xxd命令

sudo apt install xxd

  1. 将二进制文件转换为十六进制并输出到终端:

    xxd test.txt

  2. 将二进制文件转换为十六进制并保存到文件:

    xxd test.txt > test_hex.txt

只转换裸数据,不填加ascii码.

复制代码
xxd  -p test.txt >  test_hex.txt
  1. 将十六进制转换原始裸数据二进制格式:

    xxd -r -p test_hex.txt test.bin

  2. 以十六进制和 ASCII 形式显示文件的内容:

    xxd -g 1 test.txt

相关推荐
养海绵宝宝的小蜗8 分钟前
Linux 例行性工作任务(定时任务)知识点总结
linux·运维·服务器
乌萨奇也要立志学C++26 分钟前
【Linux】基础IO(二)深入理解“一切皆文件” 与缓冲区机制:从原理到简易 libc 实现
linux·运维·服务器
这周也會开心30 分钟前
通过ssh连接GitHub远程仓库
运维·ssh·github
Ronin30532 分钟前
【Linux网络】封装Socket
linux·网络·socket·网络通信
不会写DN1 小时前
用户头像文件存储功能是如何实现的?
java·linux·后端·golang·node.js·github
---学无止境---1 小时前
Linux中slab缓存初始化kmem_cache_init函数和定时回收函数的实现
linux
草莓熊Lotso1 小时前
Linux 进阶指令实操指南:文件查看、时间管理、搜索压缩全场景覆盖(附高频案例)
linux·运维·服务器
Cx330❀1 小时前
《Linux进阶指令实操指南》:文件查看、时间管理、搜索压缩全覆盖(附高频案例)
linux·运维·服务器
努力努力再努力wz2 小时前
【C++进阶系列】:万字详解unordered_set和unordered_map,带你手搓一个哈希表!(附模拟实现unordered_set和unordered_map的源码)
java·linux·开发语言·数据结构·数据库·c++·散列表
Small___ming2 小时前
【Linux基础学习】Linux Ubuntu 权限管理:从入门到精通
linux·学习·ubuntu