Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

dd (Unix)

From Wikipedia, the free encyclopedia
Shell command for copying and converting file data
dd
Original authorsKen Thompson
(AT&T Bell Laboratories)
DevelopersVariousopen-source andcommercial developers
Initial releaseJune 1974; 51 years ago (1974-06)
Written inPlan 9:C
Operating systemUnix,Unix-like,Plan 9,Inferno,Windows
PlatformCross-platform
TypeCommand
Licensecoreutils:GPLv3+
Plan 9:MIT License
Repositorycoreutils:git.savannah.gnu.org/cgit/coreutils.git/

dd (Data(set) Definition) is ashellcommand for reading, writing and convertingfiledata. Originally developed forUnix, it has been implemented on many other environments includingUnix-likeoperating systems,Windows,Plan 9 andInferno.[1]

The command can be used for many purposes. For relatively simple copying operations, it tends to be slower than domain-specific alternatives, but it excels at overwriting or truncating a file at any point or seeking in a file.[2]

The command supports reading and writing files, and if adriver is available to support file-like access, the command can access devices too. Such access is typically supported on Unix-based systems that provide file-like access to devices (such asstorage) and specialdevice files (such as/dev/zero and/dev/random). Therefore, the command can be used for tasks such as backing up theboot sector of a drive, and obtaining random data.

The command can also support converting data while copying, includingbyte order swapping and converting betweenASCII andEBCDIC text encodings.[3]

dd is sometimes humorously called "Disk Destroyer", due to its drive-erasing capabilities involvingtypos.[4]

History

[edit]

In 1974, thedd command appeared as part ofVersion 5 Unix. According toDennis Ritchie, the name is an allusion to theDD statement found inIBM'sJob Control Language (JCL),[5][6] whereDD is short fordatadefinition.[7][8] Explaining the cultural context of its syntax,Douglas McIlroy has remarked thatdd was "originally intended for converting files between theASCII,little-endian, byte-stream world ofDEC computers and theEBCDIC, big-endian, blocked world ofIBM".[9]Eric S. Raymond believes "the interface design was clearly a prank", due to the command's syntax resembling a JCL statement more than other Unix commands do.[6]

In 1987, thedd command is specified in theX/Open Portability Guide issue 2 of 1987[citation needed]. This is inherited byIEEE Std 1003.1-2008 (POSIX)[citation needed], which is part of theSingle UNIX Specification.[10]

In 1990, David MacKenzie announcedGNU fileutils (now part ofcoreutils) which includes thedd command;[11] it was written by Paul Rubin, David MacKenzie, and Stuart Kemp.[12] Since 1991, Jim Meyering is its maintainer.[13]

In 1995,Plan 9 2nd edition was released with add command with a more traditional command-line option style than the JCL statement style.[14]

Since at least 1999,UnxUtils has provided anative implementation for theWindows platform.[15][16]

Use

[edit]

Thecommand line interface significantly differs from most modern shell commands in that anoption is formatted asoption=value instead of the more typical syntax that denotes an option with a dash prefix such as:-x,-yvalue,--abc,--defvalue.

By default,dd reads fromstandard input and writes tostandard output, but input and output can be overridden. Optionif specifies an input file and optionof specifies an output file.

Non-standardized aspects ofdd depend on the underlying system or implementation, including:

  • Direct memory access
  • Signal handling
  • End-of-file (EOF) handling; in particular theWindows ports vary:Cygwin usesCtrl+D (the usual for Unix) andMKS Toolkit usesCtrl+Z (the usual for Windows)

Output messages

[edit]

On completion,dd writes statistics tostandard error. The format is standardized in POSIX.[10]: STDERR  The manual page for GNU dd does not describe this format, but the BSD manuals do. Each of the "Records in" and "Records out" lines shows the number of complete blocks transferred + the number of partial blocks, e.g. because the physical medium ended before a complete block was read, or a physical error prevented reading the complete block.

Ifdd receives aSIGINFO signal while it's running – typically triggered by the user pressingCtrl+T – it writes intermediate statistics to standard error and continues processing.

Block size

[edit]

The command processes data inblocks. The default size is 512 (the POSIX-mandated size and a common legacy size for disk hardware) but can be specified via command-line options. Optionbs specifies the size for both input (read) and output (write) operations. Alternatively, optionibs specifies the size for input operations andobs for output operations. Optioncbs affects conversion operations.

Optionscount,skip andseek specify a number of blocks: maximum to read, to start reading at offset from the start of the input, and to start writing at offset from the start of the output, respectively.[10]: OPERANDS 

A block size option value is specified as a whole decimal number of bytes with an optional suffix to indicate a multiplier. POSIX requires suffixesb (blocks) for 512 andk (kibibytes) for 1024,[10]: OPERANDS  but implementations differ on other suffixes. (Free) BSD usesm formebibytes,g forgibibytes and so on for largerpower of two units.[17] GNU usesM andG and so on for these units and useskB,MB, andGB forSI units.[12] For example, for GNUdd,bs=16M indicates a size of16 MiB (16777216 bytes) andbs=3kB specifies3000 bytes.

For POSIX compliance, some implementations interpret thex character as a multiplication operator for both block size and count option values. For example,bs=2x80x18b is interpreted as 2 × 80 × 18 × 512 =1474560 bytes, the size of a1440 KiBfloppy disk.[10]: OPERANDS  For implementations that do not support this feature, thePOSIX shell arithmetic syntax ofbs=$((2*80*18))b may be used.

Block size affects performance. Many small reads and writes is often slower than fewer, larger ones. On the downside, larger blocks require moreRAM and can complicate error recovery.

When used with a variable block size device such as a tape drive or a network, the block size may determine the tape record size ornetwork packet size, depending on thenetwork protocol.

Examples

[edit]

The examples below apply to many implementations, but are specifically written for GNU dd. Generally, the only difference between implementations is block size values and can be portable by using shell arithmetic expression instead of a size multiplier suffix. For example, instead ofbs=64M usebs=$((64*1024*1024)) orbs=$((64<<20)).

Data transfer

[edit]

The command can duplicate data across files, devices, partitions and volumes, and it can transform data during transfer as specified via optionconv. In some cases, data transfer is faster withcat.[2]

To create anISOdisk image from aCD-ROM,DVD orBlu-ray disc:[18]

blocks=$(isosize-d2048/dev/sr0)dd if=/dev/sr0 of=isoimage.iso bs=2048 count=$blocks status=progress

To restore a drive from an image file:

dd if=system.img of=/dev/sdc bs=64M conv=noerror

To create an image of partition sdb2, using a64 MiB block size:

dd if=/dev/sdb2 of=partition.image bs=64M conv=noerror

Toclone onepartition to another:

dd if=/dev/sda2 of=/dev/sdb2 bs=64M conv=noerror

To clone drive ad0 to ad1; ignoring any errors:

dd if=/dev/ad0 of=/dev/ad1 bs=64M conv=noerror

In-place modification

[edit]

The command can modify data in place. For example, this overwrites the first512 bytes of a file with null bytes:

dd if=/dev/zero of=path/to/file bs=512 count=1 conv=notrunc

Optionconv=notrunc requests to not truncate the output file. That is, if the output file already exists, replace the specified bytes and leave the rest of the output file as-is. Without this option, the command would create an output file 512 bytes long.

Master boot record backup and restore

[edit]

The example above can also be used to backup and restore any region of a device to a file, including amaster boot record. To duplicate the first two sectors of a floppy disk:

dd if=/dev/fd0 of=MBRboot.img bs=512 count=2

Disk wipe

[edit]
Main article:Data erasure

For security reasons, it is sometimes necessary to have adisk wipe of a discarded device. This can be achieved by a "data transfer" from the Unix special files.

When compared to the data modification exampleabove,notrunc conversion option is not required as it has no effect when the output file is a block device.[19]

Optionbs=16M makes dd read and write16 MiB at a time. For modern systems, an even greater block size may be faster. Note that filling the drive with random data may take longer than zeroing the drive, because the random data must be created by the CPU, while creating zeroes is very fast. On modern hard-disk drives, zeroing the drive will render most data it contains permanently irrecoverable.[20] However, with other kinds of drives such as flash memories, much data may still be recoverable bydata remanence.

Modernhard disk drives contain aSecure Erase command designed to permanently and securely erase every accessible and inaccessible portion of a drive. It may also work for somesolid-state drives (flash drives). As of 2017, it does not work onUSB flash drives nor onSecure Digital flash memories.[citation needed] When available, this is both faster than using dd, and more secure.[citation needed] OnLinux machines it is accessible via thehdparm command's--security-erase-enhanced option.

Theshred program offers multiple overwrites, as well as more secure deletion of individual files.

Data recovery

[edit]

Data recovery involves reading from a drive with some parts potentially inaccessible. The command is a good fit with this job with its flexible skipping (seek) and other low-level settings. The vanilladd, however, is clumsy to use as the user has to read the error messages and manually calculate the regions that can be read. The single block size also limits the granularity of the recovery, as a trade-off has to be made: either use a small one for more data recovered or use a large one for speed.

A C program calleddd_rescue[21] was written in October 1999. It did away with the conversion functionality ofdd, and supports two block sizes to deal with the dilemma. If a read using a large size fails, it falls back to the smaller size to gather as much as data possible. It can also run backwards. In 2003, add_rhelp script was written to automate the process of usingdd_rescue, keeping track of what areas have been read on its own.[22]

In 2004, GNU wrote a separate utility, unrelated todd, calledddrescue. It has a more sophisticated dynamic block-size algorithm and keeps track of what has been read internally. The authors of bothdd_rescue anddd_rhelp consider it superior to their implementation.[23] To help distinguish the newer GNU program from the older script, alternate names are sometimes used for GNU'sddrescue, includingaddrescue (the name on freecode.com and freshmeat.net),gddrescue (Debian package name), andgnu_ddrescue (openSUSE package name).

Benchmark drive performance

[edit]

To make drive benchmark test and analyze the sequential (and usually single-threaded) system read and write performance for 1024-byte blocks:

  • Write performance:dd if=/dev/zero bs=1024 count=1000000 of=1GB_file_to_write
  • Read performance:dd if=1GB_file_to_read of=/dev/null bs=1024

Generate a file with random data

[edit]

To make a file of 100 random bytes using the random driver:

dd if=/dev/urandom of=myrandom bs=100 count=1

Convert a file to upper case

[edit]

To convert a file to uppercase:

dd if=filename of=filename1 conv=ucase,notrunc

Progress feedback

[edit]

On request, the command reports progress. When it receives signalUSR1 (INFO on BSD systems), it writes the number of transferred blocks to standard error.

The following bash script requests progress every10 s until the transfer completes. The textPID stands for thedd process identifier.

whilekill-USR1PID;dosleep10;done

Newer versions of GNUdd support the optionstatus=progress which enables periodic status feedback.[24]

Forks

[edit]

dcfldd

[edit]

dcfldd is afork of GNUdd that is an enhanced version developed by Nick Harbour, who at the time was working for the United States'Department of Defense Computer Forensics Lab.[25][26][27] Compared todd,dcfldd allows more than one output file, supports simultaneous multiple checksum calculations, provides a verification mode for file matching, and can display the percentage progress of an operation. As of February 2026, the last release was 1.9.3 from June 2025.[28]

dc3dd

[edit]

dc3dd is another fork of GNUdd from the United StatesDepartment of Defense Cyber Crime Center (DC3). It can be seen as a continuation of the dcfldd, with a stated aim of updating whenever the GNU upstream is updated. As of June 2023[update], the last release was 7.3.1 from April 2023.[29]

See also

[edit]

References

[edit]
  1. ^Austin Group."POSIX standard: dd invocation".Archived from the original on 2010-03-10. Retrieved2016-09-29.
  2. ^abGilles (2011)."cloning - dd vs cat – is dd still relevant these days?".Unix & Linux Stack Exchange.Archived from the original on 2023-10-24. Retrieved2020-04-24.
  3. ^Chessman, Sam."How and when to use the dd command?". CodeCoffee. Archived fromthe original on 14 Feb 2008. Retrieved2008-02-19.
  4. ^"How to use dd in Linux without destroying your disk".Opensource.com. 2018-07-05.Archived from the original on 2020-10-11. Retrieved2020-10-11.
  5. ^Ritchie, Dennis (Feb 17, 2004)."Re: origin of the UNIX dd command".Newsgroupalt.folklore.computers.Usenet: c0s1he$1atuh9$1@ID-156882.news.uni-berlin.de.Archived from the original on January 22, 2011. RetrievedJanuary 10, 2016.dd was always named after JCL dd cards.
  6. ^abRaymond, Eric S."dd".Archived from the original on 2018-12-13. Retrieved2008-02-19.
  7. ^Struble, George (1969).Assembler language programming: the IBM System/360. Reading, Mass., Addison-Wesley Pub. Co. p. 123.
  8. ^Shein, Barry (Apr 22, 1990)."Re: etymology of the Unix "dd" command".Newsgroupalt.folklore.computers.Usenet: 1990Apr22.191928.11180@world.std.com.Archived from the original on 2023-10-24. Retrieved2016-07-14.
  9. ^McIlroy, M. D. (1987).A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986(PDF) (Technical report). CSTR. Bell Labs. 139.
  10. ^abcdedd – Shell and Utilities Reference,The Single UNIX Specification, Version 5 fromThe Open Group
  11. ^"GNU file utilities release 1.0".groups.google.com.Archived from the original on 2023-04-28. Retrieved2023-04-28.
  12. ^abdd(1) – Linux UserManual – User Commands from Manned.org
  13. ^"GNU's Who".Archived from the original on 2023-04-28. Retrieved2023-04-28.
  14. ^dd(1) – Plan 9 Programmer's Manual, Volume 1
  15. ^"Native Win32 ports of some GNU utilities". 15 August 2000.Archived from the original on 2000-08-15. Retrieved2023-04-28.
  16. ^"Native Win32 ports of some GNU utilities".unxutils.sourceforge.net.Archived from the original on 2006-02-09. Retrieved2022-02-23.
  17. ^dd(1) – FreeBSD General CommandsManual
  18. ^"Creating an ISO image from a CD, DVD, or BD".ArchWiki.Archived from the original on April 18, 2022. RetrievedApril 18, 2022.
  19. ^"linux - Why using conv=notrunc when cloning a disk with dd?". Stack Overflow. 2013-12-11.Archived from the original on 2014-03-24. Retrieved2014-03-24.
  20. ^Wright, Craig S.; Kleiman, Dave; S., Shyaam Sundhar R. (2008). "Overwriting Hard Drive Data: The Great Wiping Controversy". In Sekar, R.; Pujari, Arun K. (eds.).Information Systems Security, 4th International Conference, ICISS 2008, Hyderabad, India, December 16-20, 2008. Proceedings. Lecture Notes in Computer Science. Vol. 5352. Springer. pp. 243–257.doi:10.1007/978-3-540-89862-7_21.ISBN 978-3-540-89861-0.
  21. ^"dd_rescue".garloff.de.Archived from the original on 2001-05-16. Retrieved2006-11-10.
  22. ^LAB Valentin (19 September 2011)."dd_rhelp author's repository".Archived from the original on 16 May 2008. Retrieved13 May 2008.Important note : For some times, dd_rhelp was the only tool (AFAIK) that did this type of job, but since a few years, it is not true anymore: Antonio Diaz did write a ideal replacement for my tool: GNU 'ddrescue'.
  23. ^"Ddrescue - GNU Project - Free Software Foundation (FSF)".gnu.org.Archived from the original on 2021-07-02. Retrieved2016-07-22.
  24. ^"GNU Coreutils: dd invocation".The GNU Operating System and the Free Software Movement.Archived from the original on 2019-08-22. Retrieved2019-08-26.
  25. ^"DCFLDD at Source Forge". Source Forge.Archived from the original on 2013-08-02. Retrieved2013-08-17.
  26. ^Jeremy Faircloth, Chris Hurley (2007).Penetration Tester's Open Source Toolkit. Syngress. pp. 470–472.ISBN 9780080556079.
  27. ^Jack Wiles, Anthony Reyes (2011).The Best Damn Cybercrime and Digital Forensics Book Period. Syngress. pp. 408–411.ISBN 9780080556086.
  28. ^"dcfldd: Enhanced version of dd for forensics and security". GitHub.Archived from the original on 2020-10-31. Retrieved2020-11-19.
  29. ^"dc3dd".SourceForge. 25 April 2023.Archived from the original on 25 February 2020. Retrieved24 April 2020.
The WikibookGuide to Unix has a page on the topic of:Commands
Cross-platform
Windows
macOS
Unix-like
File system
Processes
User environment
Text processing
Shell builtins
Searching
Documentation
Software development
Miscellaneous
File system
Processes
User environment
Text processing
Shell builtins
Networking
Searching
Software development
Miscellaneous
File system
Text utilities
Shell utilities
Active
Retrieved from "https://en.wikipedia.org/w/index.php?title=Dd_(Unix)&oldid=1337257928"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp