回文章列表
作者MortonRainey.bbs@ptt.cc (MortonRainey) 看板: linux
標題Re: [問題] dd 指令問題.
時間批踢踢實業 (2008/06/04 Wed 23:05:43)
※ 引述《Storm.bbs@bbs.sayya.org (風)》之銘言:
: ※ 引述《MortonRainey.bbs@ptt.cc (MortonRainey)》之銘言:
:     如果是要填 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
謝謝大大詳細的解說,不過這個方法需自行算出欲append的bytes數,
此外填充值能改成其他的值如0xFF嗎?

--
※ 發信站: 批踢踢實業坊(ptt.cc) 
◆ From: 123.193.253.31
文章選讀←離開[主題上]主題下(k)上篇(j)下篇S/a搜尋 G串列 TAB精華 ↑↓捲 Pg/Space翻