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,會提前推出程序,導致實際生成的文件小於期望值。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章