linux - 如何使用 bash shell 脚本在 Linux 中读取 block 特殊设备和字符特殊设备?

标签 linux bash shell

我正在尝试从/dev/random 和/dev/urandom 读取数据,并且想知道使用 bash shell 脚本从它们读取数据和阻止/字符化特殊设备的最佳方法是什么?

最佳答案

使用dd从设备中获取数据 block 。例如。从 /dev/urandom 获取 8 个字节:

dd if=/dev/urandom count=1 bs=8 | ...

然后你可以使用od将字节转换为人类可读的形式:

$ dd if=/dev/urandom count=1 bs=8 2>/dev/null | od -t x1 -A n
b4 bc 2f 59 dd 55 1b 4a

顺便说一句,如果你只需要在 bash 中使用随机数,$RANDOM 可能更有用:

$ echo $RANDOM $RANDOM $RANDOM $RANDOM
3466 6521 4426 9349

关于linux - 如何使用 bash shell 脚本在 Linux 中读取 block 特殊设备和字符特殊设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5797051/

相关文章:

bash - ZSH 无法识别我的别名?

linux - 将关联数组作为 Bash 的参数传递

用于测试参数解析而不用 os.popen() 污染文档字符串的 shell 脚本的 Python doctest

linux - 减少读取许多小文件时的查找时间

linux - 查找 "string1"并删除它和 "string2"之间的内容

Linux变量不维护

c++ - 当 * 作为参数之一传递时 argc 的值在 c 中调用程序

linux - 在 Linux 中,内存映射了哪些文件?

bash - 询问时如何在 bash 脚本中自动按 Enter?

regex - 使用 sed 或 awk 拆分数据