我正在尝试从整个磁盘映像复制分区。
该命令正在运行:dd if=image.iso of=test bs=512 skip=1161215 count=32768
为了提高速度,我想设置一个更大的bs.
dd if=image.iso of=test bs=1M skip=1161215 count=32768
skip和count的单位是bs,是否可以单独设置单位?
然后我可以发出这个命令:
dd if=image.iso of=test bs=4M skip=1161215*512 bytes count=32768*512 bytes
小智 7
是的,可以为bs和指定不同的单位skip。然而,和单位count只有两种选择。并且必须与值匹配或以字节为单位指定。要将单位设置为字节,您必须添加额外的操作数for和for或for Both。skipcountskipcountbsiflag=skip_bytesskipiflag=count_bytescountiflag=skip_bytes,count_bytes
在您的情况下,此命令应该可以实现您的目标:
dd if=image.iso of=test iflag=skip_bytes,count_bytes bs=4M \
skip=$((1161215*512)) count=$((32768*512))
Run Code Online (Sandbox Code Playgroud)
看起来你想提取正好 16M。仅设置bs=4M count=4和使用skip_bytes:
dd if=input.file of=output.file iflag=skip_bytes bs=4M \
skip=$((1161215*512)) count=4
Run Code Online (Sandbox Code Playgroud)
包含内容的输入文件:
aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz
Run Code Online (Sandbox Code Playgroud)
使用count_bytes(精确提取count字节):
$ dd if=input.file of=output.file iflag=skip_bytes,count_bytes bs=8 skip=5 count=20
Run Code Online (Sandbox Code Playgroud)
产生 20 个字符:
cddeeffgghhiijjkkllm
Run Code Online (Sandbox Code Playgroud)
没有count_bytes(count乘以bs):
dd if=input.file of=output.file iflag=skip_bytes bs=8 skip=5 count=3
Run Code Online (Sandbox Code Playgroud)
产生 24 个字符:
cddeeffgghhiijjkkllmmnno
Run Code Online (Sandbox Code Playgroud)
您的版本dd可能不包括iflag、、skip_bytes或count_bytes。这些示例是在Debian 9上使用dd (coreutils) 8.26进行测试的。
更新: skip_bytes并从 coreutils v8.16count_bytes (2012 年 3 月)开始支持,因此几乎所有发行版都会默认支持它