gpt4 book ai didi

linux - 使用 bash 从文件中获取随机字节数?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:54:24 25 4
gpt4 key购买 nike

我有一个 256MB 的文件。我想从此文件中检索随机数量的数据并将其复制到另一个文件。

有没有办法用 bash 或其他方式做到这一点?

编辑:在 1 到 256 之间选择一个随机数,然后将该 mb 数从一个文件复制到另一个文件。

最佳答案

从头开始复制:

# (random) blocks of one byte
dd of=output_file if=input_file ibs=1 count=$((($RANDOM % 256) + 1)M

# one block of (random) bytes
dd of=output_file if=input_file ibs=$((($RANDOM % 256) + 1)M count=1

如果需要,可以使用 skip= 选项从其他地方开始。

(糟糕,忘了指定 block 大小。)

关于linux - 使用 bash 从文件中获取随机字节数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2898518/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com