我熟悉dd命令,但我很少需要自己使用它.今天我需要,但是我遇到似乎很奇怪的行为.
我想创建一个100M的文本文件,其中每一行都包含单词“测试”.这是我第一次尝试:
- ~$perl -e 'print "testing\n" while 1' | dd of=X bs=1M count=100
- 0+100 records in
- 0+100 records out
- 561152 bytes (561 kB) copied,0.00416429 s,135 MB/s
嗯,很奇怪其他组合呢?
- ~$perl -e 'print "testing\n" while 1' | dd of=X bs=100K count=1K
- 0+1024 records in
- 0+1024 records out
- 4268032 bytes (4.3 MB) copied,0.0353145 s,121 MB/s
- ~$perl -e 'print "testing\n" while 1' | dd of=X bs=10K count=10K
- 86+10154 records in
- 86+10154 records out
- 42524672 bytes (43 MB) copied,0.35403 s,120 MB/s
- ~$perl -e 'print "testing\n" while 1' | dd of=X bs=1K count=100K
- 102400+0 records in
- 102400+0 records out
- 104857600 bytes (105 MB) copied,0.879549 s,119 MB/s
所以这四个明显相当的命令,都产生不同大小的文件,只有其中一个是我期待的.这是为什么?
编辑:由于,我有点尴尬,我没有想到“是测试”,而不是更长的Perl命令.
我还不知道为什么,但使用这种方法在保存之前不会填满整个块.尝试:
- perl -e 'print "testing\n" while 1' | dd of=output.txt bs=10K count=10K iflag=fullblock
- 10240+0 records in
- 10240+0 records out
- 104857600 bytes (105 MB) copied,2.79572 s,37.5 MB/s
iflag = fullblock似乎强制dd累积输入,直到块已满,虽然我不知道为什么这不是默认值,或者它实际上是默认的.