Linux command
dd 命令
安全
权限或系统影响较大,执行前请核对目标。
常用示例
Example
sudo dd if=[path/to/file.iso] of=[/dev/usb_drive] status=progress
Clone
sudo dd bs=4M conv=fsync if=[/dev/source_drive] of=[/dev/dest_drive]
Example
dd bs=100 count=1 if=/dev/urandom of=[path/to/random_file]
Benchmark
dd bs=1M count=1024 if=/dev/zero of=[path/to/file_1GB]
Example
sudo dd if=[/dev/drive_device] of=[path/to/file.img] status=progress
Restore
sudo dd if=[path/to/file.img] of=[/dev/drive_device] status=progress
Skip
dd if=[input_file] of=[output_file] bs=512 skip=1
说明
dd converts and copies files at the block level, making it useful for low-level disk operations that bypass filesystem structures. It reads from standard input and writes to standard output by default, but is typically used with if= and of= operands to specify input and output files or devices. The tool operates in fixed block sizes (set with bs=), reading and writing data in chunks for efficiency. This block-oriented approach makes dd suitable for creating exact disk images, cloning entire drives, writing bootable USB drives from ISO files, and generating test files of specific sizes. Common use cases include forensic disk imaging, data backup and restoration, disk benchmarking, and creating files filled with zeros or random data. The status=progress option (added in GNU coreutils 8.24) provides real-time progress information. Sending a USR1 signal (or INFO signal on BSD) to a running dd process causes it to print I/O statistics to stderr.
参数
- if=_FILE_
- Read from FILE instead of stdin.
- of=_FILE_
- Write to FILE instead of stdout.
- bs=_BYTES_
- Read and write up to BYTES bytes at a time (default: 512). Overrides ibs and obs.
- ibs=_BYTES_
- Read up to BYTES bytes at a time (default: 512).
- obs=_BYTES_
- Write BYTES bytes at a time (default: 512).
- count=_N_
- Copy only N input blocks.
- skip=_N_
- Skip N ibs-sized blocks at start of input.
- seek=_N_
- Skip N obs-sized blocks at start of output.
- conv=_CONVS_
- Comma-separated conversion options: ascii, ebcdic, ibm, block, unblock, lcase, ucase, sparse, swab, sync, excl, nocreat, notrunc, noerror, fdatasync, fsync.
- status=_LEVEL_
- Output level: none (suppress everything except errors), noxfer (suppress transfer statistics), progress (show periodic transfer statistics).
- iflag=_FLAGS_
- Comma-separated input flags: append, direct, directory, dsync, sync, fullblock, nonblock, noatime, nocache, noctty, nofollow, count_bytes, skip_bytes.
- oflag=_FLAGS_
- Comma-separated output flags: append, direct, directory, dsync, sync, nonblock, noatime, nocache, noctty, nofollow, seek_bytes.
FAQ
What is the dd command used for?
dd converts and copies files at the block level, making it useful for low-level disk operations that bypass filesystem structures. It reads from standard input and writes to standard output by default, but is typically used with if= and of= operands to specify input and output files or devices. The tool operates in fixed block sizes (set with bs=), reading and writing data in chunks for efficiency. This block-oriented approach makes dd suitable for creating exact disk images, cloning entire drives, writing bootable USB drives from ISO files, and generating test files of specific sizes. Common use cases include forensic disk imaging, data backup and restoration, disk benchmarking, and creating files filled with zeros or random data. The status=progress option (added in GNU coreutils 8.24) provides real-time progress information. Sending a USR1 signal (or INFO signal on BSD) to a running dd process causes it to print I/O statistics to stderr.
How do I run a basic dd example?
Run `sudo dd if=[path/to/file.iso] of=[/dev/usb_drive] status=progress` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does if=_FILE_ do in dd?
Read from FILE instead of stdin.