Technické
Netechnické
- Jídlo a pití
.. unixový program pro kopírování dat ze zdroje do cíle po skupině bajtů s možností volby počátečního bajtu, počtu bajtů atp.
dd if=<zdroj> of=<cil> [parametry]
Vytvoření 100MB souboru plného nulových bajtů.
dd if=/dev/zero of=soubor bs=1024K count=100
Pro náhodné bajty stačí použít 'if=/dev/urandom'
dd if=/dev/sda1 of=/dev/sdb1 bs=512
dd if=/dev/sda of=/dev/sdb bs=512
dd if=/dev/xxx of=/tmp/obrazDisku.img
Do 'dd' můžeme poslat libovolný vstup a ten se bude zpracovávat stejně jako by byl předán pomocí 'if='
Toto vypíše na standartní výstup to co obdrží standartním vstupem skrz rouru.
echo "DD is da best" | dd 2> /dev/null
Tady standartní vstup rozdělíme na bloky o velikosti 1 bajt a na výstupu oddělíme jednotlivé bloky novou řádkou. Zajímavý je rozdíl mezi 'cbs=' a 'bs='.
echo "DD is da best" | dd cbs=1 conv=unblock 2> /dev/null
dd if=/dev/sda of=mbr.img count=1 bs=512
Obnovení MBR
dd if=mbr.img of=/dev/sda
Desetkrát přepíše soubor 512×10 bajtů náhodných dat a pak ještě 512×10 bajtů nul.
{ for ((i=0; i<10; i++)); do dd if=/dev/urandom of=$FILE bs=512 count=10; done; dd if=/dev/zero of=$FILE bs=512 count=10; } 2>/dev/null
dd if=/proc/kcore | hexdump -C | less
Všechna písmena velká
dd if=soubor conv=ucase
Všechna písmena malá
dd if=soubor conv=lcase
Překopíruje obsah celé operační paměti do souboru
dd if=/dev/mem of=/tmp/mem.img bs=1024
dd if=/dev/sda1 | hexdump -C | less
Nebo místo hexdump můžeme použít třeba xxd
dd if=/dev/sda1 | xxd | less
Nelze však výstup použít v editorech jako hexedit, hexcurse, ht a dalších. Výstup je (zpravidla) příliš veliký. Takovýto postup nemá příliš praktické využití, ale v případě, že jej zkombinujeme s prohledáváním blokových zařízení a vyřezáváním oblasti, můžeme provádět (nepříliš efektivní, ale nenahraditelnou) editaci.
Určení, zda se hledané slovo nachází na blokovém zařízení nebo v souboru.
dd if=/dev/sda | strings | grep 'hledane slovo'
Určení na jaké adrese se hledané slovo nachází. (Nefunguje pokud je slovo rozděleno do dvou řádků)
dd if=/dev/sda | hexdump -C | grep 'hledane slovo'
Vytiskne 16 bajtů od bajtu číslo 3372
dd if=disk.img bs=1 skip=3372 count=16 | hexdump -C
Příjemce
netcat -c -l 3000 | dd of=soubor bs=512
Odesílatel
dd if=soubor bs=512 | netcat 127.0.0.1 3000
Specifikuje zdroj dat. Výchozím zdrojem je standartní vstup.
Specifies the output path. Standard output is the default. If the seek=expr conversion is not also specified, the output file will be truncated before the copy begins, unless conv=notrunc is specified. If seek=expr is specified, but conv=notrunc is not, the effect of the copy will be to preserve the blocks in the output file over which dd seeks, but no other portion of the output file will be preserved. (If the size of the seek plus the size of the input file is less than the previous size of the output file, the output file is shortened by the copy.)
Specifies the input block size in n bytes (default is 512).
Specifies the output block size in n bytes (default is 512).
Nastaví výstupní velikost bloku (obs) a vstupní velikost bloku (ibs) na 'n' bajtů. If no conversion other than sync, noerror, and notrunc is specified, each input block is copied to the output as a single block without aggregating short blocks.
Specifies the conversion block size for block and unblock in bytes by n (default is 0). If cbs= is omitted or given a value of 0, using block or unblock produces unspecified results. This option is used only if ASCII or EBCDIC conversion is specified. For the ascii and asciib operands, the input is handled as described for the unblock operand except that characters are converted to ASCII before the trailing SPACE characters are deleted. For the ebcdic, ebcdicb, ibm, and ibmb operands, the input is handled as described for the block operand except that the characters are converted to EBCDIC or IBM EBCDIC after the trailing SPACE characters are added.
Copies and concatenates n input files before terminating (makes sense only where input is a magnetic tape or similar device).
Skips n input blocks (using the specified input block size) before starting to copy. On seekable files, the implementation reads the blocks or seeks past them. On non-seekable files, the blocks are read and the data is discarded.
Seeks n blocks from beginning of input file before copying (appropriate for disk files, where skip can be incredibly slow).
Seeks n blocks from beginning of output file before copying.
Skips n blocks (using the specified output block size) from beginning of output file before copying. On non-seekable files, existing blocks are read and space from the current end-of-file to the specified offset, if any, is filled with null bytes. On seekable files, the implementation seeks to the specified offset or reads the blocks as described for non-seekable files.
Specifikuje počet bajtů, který se ze zdroje má číst
Where values are comma-separated symbols from the following list:
Převede EBCDIC na ASCII.
Converts EBCDIC to ASCII using BSD-compatible character translations.
Converts ASCII to EBCDIC. If converting fixed-length ASCII records without NEWLINEs, sets up a pipeline with dd conv=unblock beforehand.
Converts ASCII to EBCDIC using BSD-compatible character translations. If converting fixed-length ASCII records without NEWLINEs, sets up a pipeline with dd conv=unblock beforehand.
Slightly different map of ASCII to EBCDIC. If converting fixed-length ASCII records without NEWLINEs, sets up a pipeline with dd conv=unblock beforehand.
Slightly different map of ASCII to EBCDIC using BSD-compatible character translations. If converting fixed-length ASCII records without NEWLINEs, sets up a pipeline with dd conv=unblock beforehand.
The ascii (or asciib), ebcdic (or ebcdicb), and ibm (or ibmb) values are mutually exclusive.
Treats the input as a sequence of NEWLINE-terminated or EOF-terminated variable-length records independent of the input block boundaries. Each record is converted to a record with a fixed length specified by the conversion block size. Any NEWLINE character is removed from the input line. SPACE characters are appended to lines that are shorter than their conversion block size to fill the block. Lines that are longer than the conversion block size are truncated to the largest number of characters that will fit into that size. The number of truncated lines is reported.
Converts fixed-length records to variable length. Reads a number of bytes equal to the conversion block size (or the number of bytes remaining in the input, if less than the conversion block size), delete all trailing SPACE characters, and append a NEWLINE character. The block and unblock values are mutually exclusive.
Maps upper-case characters specified by the LC_CTYPE keyword tolower to the corresponding lower-case character. Characters for which no mapping is specified are not modified by this conversion.
Maps lower-case characters specified by the LC_CTYPE keyword toupper to the corresponding upper-case character. Characters for which no mapping is specified are not modified by this conversion. The lcase and ucase symbols are mutually exclusive.
Swaps every pair of input bytes. If the current input record is an odd number of bytes, the last byte in the input record is ignored.
Does not stop processing on an input error. When an input error occurs, a diagnostic message is written on standard error, followed by the current input and output block counts in the same format as used at completion. If the sync conversion is specified, the missing input is replaced with null bytes and processed normally. Otherwise, the input block will be omitted from the output.
Does not truncate the output file. Preserves blocks in the output file not explicitly written by this invocation of dd. (See also the preceding of=file operand.)
Pads every input block to the size of the ibs= buffer, appending null bytes. (If either block or unblock is also specified, appends SPACE characters, rather than null bytes.) If operands other than conv= are specified more than once, the last specified operand=value is used. For the bs=, cbs=, ibs=, and obs= operands, the application must supply an expression specifying a size in bytes. The expression, expr, can be:
a positive decimal number a positive decimal number followed by k, specifying multiplication by 1024 a positive decimal number followed by M, specifying multiplication by 1024*1024 a positive decimal number followed by b, specifying multiplication by 512 two or more positive decimal numbers (with or without k or b) separated by x, specifying the product of the indicated values.
Pokud nám běží 'dd' delší dobu, může nás zajímat stav jeho činnosti. Ten můžeme zjistit pomocí příkazu 'kill' s použitím signálu USR1.
bash$ dd if=/dev/zero of=/dev/null & [1] 10775 bash$ jobs [1]+ Running dd if=/dev/zero of=/dev/null & bash$ kill -10 10775 bash$ 13006004+0 vstoupivších záznamů 13006003+0 vystoupivších záznamů 6 659 073 536 bajtů (6,7 GB) zkopírováno, 12,0784 s, 551 MB/s bash$ kill -10 10775 bash$ 31481047+0 vstoupivších záznamů 31481046+0 vystoupivších záznamů 16 118 295 552 bajtů (16 GB) zkopírováno, 29,1654 s, 553 MB/s bash$ kill -10 10775 bash$ 36411541+0 vstoupivších záznamů 36411541+0 vystoupivších záznamů 18 642 708 992 bajtů (19 GB) zkopírováno, 33,7022 s, 553 MB/s bash$ kill -10 10775 bash$ 38414511+0 vstoupivších záznamů 38414510+0 vystoupivších záznamů 19 668 229 120 bajtů (20 GB) zkopírováno, 35,5485 s, 553 MB/s bash$ kill 10775 bash$ jobs [1]+ Terminated dd if=/dev/zero of=/dev/null bash$