回文章列表
作者Storm.bbs@bbs.sayya.org (風) 看板: linux
標題Re: [問題] dd 指令問題.
時間SayYA 資訊站 (2008/06/04 Wed 03:17:09)
※ 引述《MortonRainey.bbs@ptt.cc (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
文章選讀←離開[主題上]主題下(k)上篇(j)下篇S/a搜尋 G串列 TAB精華 ↑↓捲 Pg/Space翻