# 默认cp拷贝,一个1GB的文件,花费1.05秒 $ time cp a b cp a b 0.02s user 1.05s system 75% cpu 1.403 total
# 默认dd拷贝,一个1GB的文件,竟然花费了29.17秒 $ time ddif=a of=b 2048000+0 records in 2048000+0 records out 1048576000 bytes (1.0 GB, 1000 MiB) copied, 34.7214 s, 30.2 MB/s ddif=a of=b 1.31s user 29.17s system 87% cpu 34.996 total
$ time ddif=a of=b bs=2M 500+0 records in 500+0 records out 1048576000 bytes (1.0 GB, 1000 MiB) copied, 1.04747 s, 1.0 GB/s ddif=a of=b bs=2M 0.00s user 1.05s system 78% cpu 1.332 total $ time ddif=a of=b bs=4M 250+0 records in 250+0 records out 1048576000 bytes (1.0 GB, 1000 MiB) copied, 1.00866 s, 1.0 GB/s ddif=a of=b bs=4M 0.00s user 1.00s system 76% cpu 1.304 total $ time ddif=a of=b bs=8M 125+0 records in 125+0 records out 1048576000 bytes (1.0 GB, 1000 MiB) copied, 0.937974 s, 1.1 GB/s ddif=a of=b bs=8M 0.00s user 0.92s system 79% cpu 1.164 total $ time ddif=a of=b bs=10M 100+0 records in 100+0 records out 1048576000 bytes (1.0 GB, 1000 MiB) copied, 1.01666 s, 1.0 GB/s ddif=a of=b bs=10M 0.00s user 1.03s system 82% cpu 1.257 total
测试硬盘速度
我最常使用的dd命令的用例是,测试硬盘的读写速度,比如很简单地写入1GB、10GB来看一下。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
$ ddif=/dev/zero of=tmp bs=1M count=1000 1000+0 records in 1000+0 records out 1048576000 bytes (1.0 GB, 1000 MiB) copied, 0.7338 s, 1.4 GB/s
$ ddif=/dev/zero of=tmp bs=2M count=500 500+0 records in 500+0 records out 1048576000 bytes (1.0 GB, 1000 MiB) copied, 0.611315 s, 1.7 GB/s
$ ddif=/dev/zero of=tmp bs=4M count=250 250+0 records in 250+0 records out 1048576000 bytes (1.0 GB, 1000 MiB) copied, 0.602517 s, 1.7 GB/s