Introduction
Linux
In-housedd
Commands are a powerful data copy and conversion utility. It runs at a lower level and is usually used to create bootableUSB
Tasks such as drives, cloning disks, and generating random data.
dd
The full name can be:data duplicator
、disk destroyer
andData Definition
Functions and capabilities
Disk Image
: Creates an exact, bit-by-bit copy of the entire disk or partitionData erasing
: Safely overwrite the drive with zero or random dataFile conversion
: Conversion, byte order exchange and file fill between ASCII and EBCDICData recovery
: Read data from a failed drive by ignoring read errorsStart media creation
: Write the disk image to a USB drive or SD cardStorage performance testing
: A rough benchmark test for drive write speed
grammar
dd if=<input_file> of=<output_file> [options]
if
: Input file (source file or device, e.g./dev/sda
、/dev/zero
)of
: Output file (target file or device, for example,/dev/sdb
,)
Options
: Customized behavior options
Common options
-
bs=[BYTES]
: Set both input and output block sizes toBYTES
Block size representationdd
The data size that the command reads or writes at one time each input or output
count=[N]
: Copy onlyN
Input blocksskip=[N]
: Skip the input file before starting copyingN
A blockseek=[N]
: Skip the output file before starting writingN
A blockconv=[TYPE]
: Specify the conversion type (for example,sync、noerror、notrunc
)status=[LEVEL]
: Control the output verbosity (for example,none、 noxfer、 progress
)iflag=[FLAGS]
: Enter a specific flag (direct、sync
)oflag=[FLAGS]
: Output specific flags (append、sync
)ibs
: Set the input block sizeobs
: Set the output block sizenoerror
: Continue after reading errornotrunc
: Do not truncate the output filesync
:useNULL
Fill each input block toibs
size
Example usage
Basic usage
dd if= of= # If the target file does not exist, it will be created automatically, otherwise the target file will be overwritten.
Create a bootable USB drive
Will
ISO
File writingUSB
Drive
sudo dd if= of=/dev/sdb bs=4M status=progress
if=
: InputISO
documentof=/dev/sdb
: OutputUSB
equipmentbs=4M
: Use 4 MB block size to speed up copyingstatus=progress
: Display progress during operation
Backup disk
Create a disk image
sudo dd if=/dev/sda of= bs=64K conv=sync,noerror
if=/dev/sda
: The input original disk deviceof=
: Output disk imagebs=64K
: Block size is 64 KBconv=sync,noerror
: Continue reading when an error occurs and fill it with control
Recover disk from mirror
sudo dd if= of=/dev/sda bs=64K
Create a file containing random data
dd if=/dev/urandom of=random_data.bin bs=1M count=10
if=/dev/urandom
: Random input sourceof=random_data.bin
: The output filebs=1M
: Block size is 1 MBcount=10
: Create a 10 MB file
Securely erase disk
Overwrite disk with random data
sudo dd if=/dev/urandom of=/dev/sda bs=1M status=progress
Test disk write speed
Write zeros to disk to test write speed
sudo dd if=/dev/zero of=testfile bs=1G count=1 oflag=direct
Split the file into chunks
Split the file into smaller chunks
dd if=largefile of=smallfile bs=1M count=100
Prevent overwriting of target files
dd if= of= conv=notrunc
Append data to file
dd if= of= conv=append
Compress the data read by dd
sudo dd if=/dev/sda bs=1M | gzip -c -9 >
Display progress bar during operation
dd if=source_file of=destination_file status=progress
Convert file data format from EBCDIC to ASCII
sudo dd if= of= conv=ascii
Key conversion flags
sync
: Fill each block with empty bytes to reach the specified sizenoerror
: Even though there is a read error, continue operationnotrunc
: Do not truncate the output fileucase
: Convert text to capitallcase
: Convert text to lowercase
The above is the detailed information about how Linux uses the dd command to copy and convert data. For more information about copying and converting data from the Linux dd command, please pay attention to my other related articles!