看板Linux
标 题Re: [问题] dd 指令问题.
发信站SayYA 资讯站 (Wed Jun 4 03:17:09 2008)
转信站ptt!ctu-reader!ctu-peer!news.nctu!News.Math.NCTU!SayYa
※ 引述《[email protected] (MortonRainey)》之铭言:
> ※ 引述《MortonRainey (MortonRainey)》之铭言:
> : 若一个档案 ifile (500bytes)欲输出成512bytes的ofile,
> : 有什麽方法可以padding後面不足的部份?
> : 目前知道
> : dd if=ifile of=ofile bs=512 conv=sync
> : 透过conv=sync可以达成,但它是用NULs来填充.
> : 有什麽方法可以指定改用其他值来填充?
> : 谢谢.
如果是要填 0 的话:
dd if=/dev/zero of=ifile conv=notrunc oflag=append bs=1 count=12
> 不好意思再次请教各位先进这个问题。
> 若是不用dd指令,有其他的方法达成吗?
一样假设要填 0 的话:
head -c 12 /dev/zero >> ifile
* 操作实例:假设原档案是从 /dev/random 产生的 10 bytes 大小的档案,
想要在档案尾端填 0 直到档案大小变成 20 bytes。
* 产生两个相同的 10 bytes 的档案 test.dd 和 test.head
$ dd if=/dev/random of=./test.dd bs=1 count=10
10+0 records in
10+0 records out
复制了 10 位元组 (10 B),0.000459235 秒,21.8 kB/s
$ cp test.dd test.head
$ ls -l test.*
-rw-r--r-- 1 storm storm 10 2008-06-03 15:05 test.dd
-rw-r--r-- 1 storm storm 10 2008-06-03 15:07 test.head
* 使用 dd 填 0
$ dd if=/dev/zero of=test.dd conv=notrunc oflag=append bs=1 count=10
10+0 records in
10+0 records out
复制了 10 位元组 (10 B),0.000134921 秒,74.1 kB/s
$ ls -l test.dd
-rw-r--r-- 1 storm storm 20 2008-06-03 15:09 test.dd
* 使用 head 填 0
$ head -c 10 /dev/zero >> test.head
$ ls -l test.head
-rw-r--r-- 1 storm storm 20 2008-06-03 15:11 test.head
* 验证档案内容
$ diff test.dd test.head && echo '档案内容一致'
档案内容一致
$ hexdump test.dd
0000000 2d57 09bf cb4e 5118 6fb3 0000 0000 0000
0000010 0000 0000
0000014
--
※ Origin: SayYA 资讯站 <bbs.sayya.org>
◆ From: adsl-070-155-125-254.sip.asm.bellsouth.net