天天看點

Linux壓縮打包指令使用方法(dd 指令)

dd 指令

dd if="input_file" of="outptu_file" bs="block_size" /

count="number"

參數:

if :就是 input file 啰~也能夠是裝置喔!

of :就是 output file 喔~也能夠是裝置;

bs :規劃的一個 block 的大小,假如沒有設定時,預設是 512 bytes

count:多少個 bs 的意思。

範例:

範例一:将 /etc/passwd 備份到 /tmp/passwd.back 當中

[root@linux ~]# dd if=/etc/passwd of=/tmp/passwd.back

3+1 records in

3+1 records out

[root@linux ~]# ll /etc/passwd /tmp/passwd.back

-rw-r--r-- 1 root root 1746 Aug 25 14:16 /etc/passwd

-rw-r--r-- 1 root root 1746 Aug 29 16:57 /tmp/passwd.back

# 仔細的看一下,我的 /etc/passwd 文檔大小為 1746 bytes,因為我沒有設定 bs ,

# 是以預設是 512 bytes 為一個機關,是以,上面那個 3+1 表示有 3 個完整的

# 512 bytes,連同未滿 512 bytes 的另一個 block 的意思啦!

# 事實上,感覺似乎是 cp 這個指令啦~

範例二:備份 /dev/hda 的 MBR

[root@linux ~]# dd if=/dev/hda of=/tmp/mbr.back bs=512 count=1

1+0 records in

1+0 records out

# 這就得好好瞭解一下啰~我們知道整顆硬碟的 MBR 為 512 bytes,

# 就是放在硬碟的第一個 sector 啦,是以,我能夠利用這個方式來将

# MBR 内的任何資料都紀錄下來,真的很厲害吧! ^_^

範例三:将整個 /dev/hda1 partition 備份下來。

[root@linux ~]# dd if=/dev/hda1 of=/some/path/filenaem

# 這個指令很厲害啊!将整個 partition 的内容全部備份下來~

# 後面接的 of 必須要不是在 /dev/hda1 的目錄内啊~否則,怎麼讀也讀不完~

# 這個動作是很有效用的,假如改天您必須要完整的将整個 partition 的内容填回去,

# 則能夠利用 dd if=/some/file of=/dev/hda1 來将資料寫入到硬碟當中。

# 假如想要整個硬碟備份的話,就類似 Norton 的 ghost 軟體一般,

# 由 disk 到 disk ,嘿嘿~利用 dd 就能夠啦~厲害厲害!

繼續閱讀