Heim  >  Artikel  >  Betrieb und Instandhaltung  >  Tutorial zur Verwendung des dd-Befehls unter Linux

Tutorial zur Verwendung des dd-Befehls unter Linux

黄舟
黄舟Original
2017-05-28 11:42:332177Durchsuche

Der Befehl dd kopiert eine Datei unter Verwendung von Blöcken der angegebenen Größe und führt beim Kopieren die angegebene Konvertierung durch. Der folgende Artikel stellt Ihnen hauptsächlich die relevanten Informationen zur Verwendung des dd-Befehls unter Linux vor. Er hat einen gewissen Referenz- und Lernwert für alle Freunde, die ihn benötigen.

Dieser Artikel stellt Ihnen hauptsächlich die relevanten Inhalte zur Verwendung des dd-Befehls unter Linux vor und gibt ihn als Referenz und zum Studium weiter. Werfen wir einen Blick auf die ausführliche Einführung:

1 . Der Linux-Befehl dd kopiert eine Datei mit Blöcken einer bestimmten Größe und führt beim Kopieren bestimmte Konvertierungen durch.

Verwendung: dd [OPERAND]

ParameterKommentare:

 bs=BYTES  read and write BYTES bytes at a time (also see ibs=,obs=)
 cbs=BYTES  convert BYTES bytes at a time
 conv=CONVS  convert the file as per the comma separated symbol list
 count=N   copy only N input blocks
 ibs=BYTES  read BYTES bytes at a time (default: 512)
 if=FILE   read from FILE instead of stdin(默认为标准输入)
 iflag=FLAGS  read as per the comma separated symbol list
 obs=BYTES  write BYTES bytes at a time (default: 512)
 of=FILE   write to FILE instead of stdout(默认为标准输出)
 oflag=FLAGS  write as per the comma separated symbol list
 seek=BLOCKS  skip BLOCKS obs-sized blocks at start of output
 skip=BLOCKS  skip BLOCKS ibs-sized blocks at start of input
 status=WHICH WHICH info to suppress outputting to stderr;
     'noxfer' suppresses transfer stats, 'none' suppresses all

Optionale Parameter für CONVS

 ascii  from EBCDIC to ASCII
 ebcdic from ASCII to EBCDIC
 ibm  from ASCII to alternate EBCDIC
 block  pad newline-terminated records with spaces to cbs-size
 unblock replace trailing spaces in cbs-size records with newline
 lcase  change upper case to lower case
 nocreat do not create the output file
 excl  fail if the output file already exists
 notrunc do not truncate the output file
 ucase  change lower case to upper case
 sparse try to seek rather than write the output for NUL input blocks
 swab  swap every pair of input bytes
 noerror continue after read errors
 sync  pad every input block with NULs to ibs-size; when used
   with block or unblock, pad with spaces rather than NULs
 fdatasync physically write output file data before finishing
 fsync  likewise, but also write metadata

Optionale Parameter für FLAGS

 append append mode (makes sense only for output; conv=notrunc suggested)
 direct use direct I/O for data
 directory fail unless a directory
 dsync  use synchronized I/O for data
 sync  likewise, but also for metadata
 fullblock accumulate full blocks of input (iflag only)
 nonblock use non-blocking I/O
 noatime do not update access time
 noctty do not assign controlling terminal from file
 nofollow do not follow symlinks
 count_bytes treat 'count=N' as a byte count (iflag only)

Hinweis: If die Stelle, an der die Zahl angegeben wird, endet mit den folgenden Zeichen, die entsprechende Zahl wird multipliziert:

c =1, w =2, b =512, kB =1000, K =1024, MB =1000*1000, M =1024*1024, xM =M

GB =1000*1000*1000, G =1024*1024*1024, and so on for T, P, E, Z, Y

2. Anwendungsbeispiele

1. Sichern Sie die gesamte lokale /dev/hdb-Festplatte nach /dev/hdd

dd if=/dev/hdb of=/dev/hdd

2. Sichern Sie die gesamten Festplattendaten von /dev/hdb das Bild im angegebenen Pfad Datei

dd if=/dev/hdb of=/root/image

3. Sichern Sie die gesamten /dev/hdb-Daten, komprimieren Sie sie mit dem gzip-Tool und speichern Sie es in den angegebenen Pfad

dd if=/dev/hdb | gzip > /root/image.gz

4. Teilen Sie eine Datei in 3 Dateien auf

#文件大小为2.3k
[Oracle@rhel6 ~]$ ll db1_db_links.sql 
-rw-r--r-- 1 oracle oinstall 2344 Nov 21 10:39 db1_db_links.sql
#把这个文件拆成每个文件1k,bs=1k,count=1,使用skip参数指定在输入文件中跳过多少个bs支读取
[oracle@rhel6 ~]$ dd if=db1_db_links.sql of=dd01.sql bs=1k count=1
1+0 records in
1+0 records out
1024 bytes (1.0 kB) copied, 4.5536e-05 s, 22.5 MB/s
[oracle@rhel6 ~]$ dd if=db1_db_links.sql of=dd02.sql bs=1k count=1 skip=1
1+0 records in
1+0 records out
1024 bytes (1.0 kB) copied, 0.000146387 s, 7.0 MB/s
[oracle@rhel6 ~]$ dd if=db1_db_links.sql of=dd03.sql bs=1k count=1 skip=2
0+1 records in
0+1 records out
296 bytes (296 B) copied, 0.000204216 s, 1.4 MB/s
#拆分出的文件
[oracle@rhel6 ~]$ ll dd*sql
-rw-r--r-- 1 oracle oinstall 1024 May 20 14:58 dd01.sql
-rw-r--r-- 1 oracle oinstall 1024 May 20 14:58 dd02.sql
-rw-r--r-- 1 oracle oinstall 296 May 20 14:58 dd03.sql

5 1

#合并操作,此时用到seek参数,用于指定在输入文件中跳过的bs数
[oracle@rhel6 ~]$ dd of=1.sql if=dd01.sql 
2+0 records in
2+0 records out
1024 bytes (1.0 kB) copied, 0.000176 s, 5.8 MB/s
[oracle@rhel6 ~]$ dd of=1.sql if=dd02.sql bs=1k seek=1
1+0 records in
1+0 records out
1024 bytes (1.0 kB) copied, 0.000124038 s, 8.3 MB/s
[oracle@rhel6 ~]$ dd of=1.sql if=dd03.sql bs=1k seek=2
0+1 records in
0+1 records out
296 bytes (296 B) copied, 0.00203881 s, 145 kB/s
#与拆分前的文件进行校验
[oracle@rhel6 ~]$ diff 1.sql db1_db_links.sql
[oracle@rhel6 ~]$

6. Fügen Sie Daten an der angegebenen Position in die Ausgabedatei ein, ohne dass die Ausgabedatei

abgeschnitten werden muss Verwenden Sie den conv=notrunc-Parameter

[oracle@rhel6 ~]$ dd if=2.sql of=1.sql bs=1k seek=1 count=2 conv=notrunc

Zusammenfassung

Das obige ist der detaillierte Inhalt vonTutorial zur Verwendung des dd-Befehls unter Linux. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn