【发布时间】:2017-04-17 01:03:52
【问题描述】:
我想创建一个特定大小的文件,只包含 bash 中的可打印字符串。
我的第一个想法是使用/dev/urandom:
dd if=/dev/urandom of=/tmp/file bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB, 100 MiB) copied, 10,3641 s, 10,1 MB/s
file /tmp/file && du -h /tmp/file
/tmp/file: data
101M /tmp/file
这给我留下了一个我想要大小的文件,但不仅包含可打印的字符串。
现在,我可以使用strings 创建一个只包含可打印字符串的文件。
cat /tmp/file | strings > /tmp/file.txt
file /tmp/file.txt && du -h /tmp/file.txt
/tmp/file.txt: ASCII text
7,0M /tmp/file.txt
这给我留下了一个只包含可打印字符串但文件大小错误的文件。
TL;DR
如何在 bash 中创建一个特定大小的文件,只包含可打印的字符串?
【问题讨论】: