DD command introduction
dd
command is LINUX
a command-line tool for data transformation and processing. dd
Stands for " data copy ," which reads data from one device or file and writes it to another. dd
Commands can be used for a variety of purposes, including the following:
-
Disk backup and cloning
-
Data Recovery
-
blank file creation
-
Password cracking
Features of the DD command
-
Flexibility: Can be used for a variety of data processing and transformation operations, including backup and clone disks, data recovery, disk wiping, blank file creation, and more.
-
Reliability: Using the underlying block device interface to read and write data, the data can be completely copied to ensure data consistency and integrity.
-
Efficiency: Various caching mechanisms can be used to improve data transmission speed and make data replication more efficient.
-
Sensitivity: Different block sizes and cache sizes can be used and adjusted as needed to accommodate different hardware and data transfer requirements.
-
Versatility: It can run on different operating systems and hardware platforms, and has strong versatility.
DD Command Common Parameters
dd
The command can copy a file in blocks of a specified size, and perform specified transformations while copying.
parameter | note |
---|---|
if=文件名 |
Input file name, defaults to standard input. That is, specify the source file. <if=input file> |
of=文件名 |
The output file name, the default is standard output. That is, specify the destination file. <of=output file> |
ibs=bytes |
Read bytes bytes at a time, that is, specify a block size of bytes bytes |
obs=bytes |
Output bytes bytes at a time, that is, specify a block size of bytes bytes |
bs=bytes |
Also set the block size of read/output to bytes bytes |
cbs=bytes |
Convert bytes bytes at a time, that is, specify the conversion buffer size |
skip=blocks |
Skip blocks blocks from the beginning of the input file before starting copying |
seek=blocks |
Skip blocks blocks from the beginning of the output file before starting copying |
status=progress |
Display progress information, such as the number of bytes copied per second and the progress percentage, etc. |
Example of using the DD command
# 复制文件内容
dd if=input.txt of=output.txt bs=1024
将input.txt文件复制到output.txt文件中,块大小为1024字节
# 将一个磁盘的内容复制到另一个磁盘中
dd if=/dev/sda of=/dev/sdb bs=4096
将/dev/sda磁盘的内容复制到/dev/sdb磁盘中,块大小为4096字节
# 将一个磁盘的内容复制到一个文件中
dd if=/dev/sda of=image.img bs=4096 count=1000 status=progress
将/dev/sda磁盘的前1000个块复制到image.img文件中,块大小为4096字节,并显示进度信息
----------------------------
# 创建空文件
dd if=/dev/zero of=newfile bs=1M count=10
创建一个名为newfile的文件,大小为10MB,其中每个块的大小为1MB
# 磁盘克隆
dd if=/dev/sda of=/dev/sdb bs=4096 conv=noerror,sync
将/dev/sda磁盘的内容复制到/dev/sdb磁盘中,块大小为4096字节。conv=noerror,sync表示在复制过程中忽略读取错误,并将输出同步到磁盘中
# 数据恢复
dd if=/dev/sda1 of=/mnt/usbdrive/recovered_data.img bs=4096 conv=noerror,sync
将/dev/sda1分区的内容复制到/mnt/usbdrive/recovered_data.img文件中,块大小为4096字节。conv=noerror,sync表示在复制过程中忽略读取错误,并将输出同步到磁盘中
# 密码破解
dd if=/dev/sda | john --stdin
将/dev/sda磁盘的内容传递给john密码破解工具,用于破解磁盘中的密码
ddrescue命令:用于数据恢复,可以在损坏的磁盘上执行数据恢复操作