dd命令是Linux/Unix下的一个很常见的文件拷贝工具。
我们先列下dd命名的常用的参数,再详细分析:
bs=BYTES read and write up to BYTES bytes at a time
cbs=BYTES convert BYTES bytes at a time
conv=CONVS convert the file as per the comma separated symbol list
count=BLOCKS copy only BLOCKS input blocks
ibs=BYTES read up to BYTES bytes at a time (default: 512)
if=FILE read from FILE instead of stdin
iflag=FLAGS read as per the comma separated symbol list
obs=BYTES write BYTES bytes at a time (default: 512)
of=FILE write to FILE instead of stdout
oflag=FLAGS write as per the comma separated symbol list
seek=BLOCKS skip BLOCKS obs-sized blocks at start of output
skip=BLOCKS skip BLOCKS ibs-sized blocks at start of input
status=noxfer suppress transfer statistics
1. dd if=/dev/block/block0 of=/dev/block/block1
直接把block0的数据拷贝到block1,默认每一次读取及写入都是512字节。
2. dd if =/dev/block/block0 of=/dev/block/block1 ibs=512k obs=1M skip=20 seek=50 count=20
把block0偏移10M(512k*20)的地方,读取10M(512k*20)的数据,写入到block1偏移50M(1M*50)的地方,每一次读512k,每一次写入1M
3. dd if =/dev/block/block0 of=/dev/block/block1 bs=1M skip=20 seek=50 count=20
如果每次读与每次写的数据相同,即ibs=obs, 则可使用bs代替
4. dd if=/dev/block/block0 of=/udsik/block0_dump.img
把block0分区镜像dump到U盘中,存储为文件block0_dump.img
5. dd if=/udsik/block0.img of=/dev/block/block0
把U盘中的block0.img更新到block0分区