linux dd urandom 生成指定大小随机内容文件

正确方法

[yeqiang@localhost tmp]$ ll -h | grep data.bin
-rw-rw-r--. 1 yeqiang yeqiang 100K 2020-06-17 15:43:20 data.bin
[yeqiang@localhost tmp]$ dd if=/dev/urandom of=data.bin bs=100K count=1
1+0 records in
1+0 records out
102400 bytes (102 kB, 100 KiB) copied, 0.000479058 s, 214 MB/s
[yeqiang@localhost tmp]$ ll -h | grep data.bin
-rw-rw-r--. 1 yeqiang yeqiang 100K 2020-06-17 15:43:31 data.bin

错误:

[yeqiang@localhost tmp]$ dd if=/dev/random of=data.bin bs=100K count=1
0+1 records in
0+1 records out
115 bytes copied, 0.000361449 s, 318 kB/s
[yeqiang@localhost tmp]$ ll -h | grep data.bin
-rw-rw-r--. 1 yeqiang yeqiang  115 2020-06-17 15:43:52 data.bin

可以看到,如果使用/dev/random,会提前推出程序,导致实际生成的文件小于期望值。

猜你喜欢

转载自blog.csdn.net/hknaruto/article/details/106809808