close
dd 在manual裡的解釋是convert and copy a file
語法:dd if=輸入檔案 of=輸出檔案 選項
參數 | 說明 |
if | 指定輸入檔案 |
of | 指定輸出檔案 |
ibs | 指定每次讀取之大小(預設為512byte) |
obs | 指定每次寫入之大小(預設為512byte) |
bs | 同時指定ibs和obs之大小(預設為512byte) |
cbs | 指定每次轉換之大小 |
count | 僅轉換ibs所指定的block數(N) |
seek | 於開始始略過N個obs所指定的block數(N=指定的數字) |
skip | 於開始始略過N個ibs所指定的block數(N=指定的數字) |
conv=ascii | 將EBCDIC碼轉換成ASCII碼 |
conv=ebcdic | 將ASCII碼轉換成EBCDIC碼 |
conv=ibm | 將ASCII碼轉換成alternate EBCDIC碼 |
conv=lcase | 把大寫字母轉換為小寫 |
conv=ucase | 把小寫字母轉換為大寫 |
conv=nocreat | 不建立輸出檔案 |
conv=noerror | 讀取發生錯誤仍繼續讀取 |
conv=notrunc | 輸出時不做裁剪 |
conv=sync | 將每個輸入的block都和ibs大小一樣(若不足由NULs填滿) |
最常使用的大概就是光碟或硬碟的複製
ubuntu@ubuntu ~ $ sudo dd if=/dev/sda1 of=/dev/sdb1 #將第一顆硬碟的第一個磁區複製到第二顆硬碟的第一個磁碟。
若硬碟有壞軌可加上noerror參數
ubuntu@ubuntu ~ $ sudo dd if=/dev/sda1 of=/dev/sdb1 bs=4M conv=noerror,notrunc #將第一顆硬碟的第一個磁區複製到第二顆硬碟的第一個磁碟,將讀取和寫入之block值設定為4M,並在讀取錯誤時繼續讀取,輸出時不做裁剪。
利用dd製作ISO檔
ubuntu@ubuntu ~ $ sudo dd if=/dev/cdrom of=/tmp/ubuntu1604.iso #讀取cdrom並將檔案存成/tmp/ubuntu1604.sio
小寫字母轉換為大寫字母
ubuntu@ubuntu ~ $ dd if=original.txt of=dd_s_to_b.txt conv=ucase #將original.txt輸出為dd_s_to_b.txt並將所有字母大寫轉換為小寫 輸入 0+1 個紀錄 輸出 0+1 個紀錄 510 bytes copied, 0.000214348 s, 2.4 MB/s ubuntu@ubuntu ~ $ cat dd_s_to_b.txt #查看dd_s_to_b.txt內容 ONCE ON A DARK WINTER'S DAY, WHEN THE YELLOW FOG HUNG SO THICK AND HEAVY IN THE STREETS OF LONDON THAT THE LAMPS WERE LIGHTED AND THE SHOP WINDOWS BLAZED WITH GAS AS THEY DO AT NIGHT, AN ODD-LOOKING LITTLE GIRL SAT IN A CAB WITH HER FATHER AND WAS DRIVEN RATHER SLOWLY THROUGH THE BIG THOROUGHFARES. SHE SAT WITH HER FEET TUCKED UNDER HER, AND LEANED AGAINST HER FATHER, WHO HELD HER IN HIS ARM, AS SHE STARED OUT OF THE WINDOW AT THE PASSING PEOPLE WITH A QUEER OLD-FASHIONED THOUGHTFULNESS IN HER BIG EYES.
大寫字母轉換為小寫字母
ubuntu@ubuntu ~ $ dd if=original.txt of=dd_b_to_s.txt conv=lcase #將original.txt輸出為dd_b_to_s.txt並將所有字母小寫轉換為大寫 輸入 0+1 個紀錄 輸出 0+1 個紀錄 510 bytes copied, 0.000173607 s, 2.9 MB/s ubuntu@ubuntu ~ $ cat dd__to_l.txt #查看dd_l_to_u.txt內容 once on a dark winter's day, when the yellow fog hung so thick and heavy in the streets of london that the lamps were lighted and the shop windows blazed with gas as they do at night, an odd-looking little girl sat in a cab with her father and was driven rather slowly through the big thoroughfares. she sat with her feet tucked under her, and leaned against her father, who held her in his arm, as she stared out of the window at the passing people with a queer old-fashioned thoughtfulness in her big eyes.
文章標籤
全站熱搜
留言列表