As we all know, there are numerous Linux commands, each of which has its own significance. This article shares the powerful and practical aspects of the dd command. Although some may not have used or even heard of this command, by the end of this article, you will be amazed by its powerful features!dd is a powerful and classic command in the Linux system, which stands for Dataset Definition. It is often referred to as the “disk destroyer,” which, although a nickname, reflects the potentially disastrous consequences of improper use.dd is a tool for low-level, block copying and converting files. It can be used for copying files, converting file formats, creating disk images, and performing disk backups and restorations.
It is fundamentally different from the ordinary <span><span>cp</span></span> command:
-
<span>cp</span>operates on file contents. -
<span>dd</span>operates on raw, low-level disk sectors or data blocks, regardless of the file system or file structure.
1. dd Command Syntax
The basic syntax of the dd command is as follows:
dd [option]...
Where option refers to optional parameters for the dd command, specifying its functionality and operations.For example, here is a specific instance of the dd command that copies a file named input.py to another file named output.py, with a read and write byte size of 1024 bytes:
dd if=input.py of=output.py ibs=1024 obs=1024
The following are common parameters and options for the dd command:
1. if=filename: Specifies the input file name, defaulting to standard input.
2. of=filename: Specifies the output file name, defaulting to standard output.
3. ibs=bytes: Reads bytes bytes at a time, specifying a block size of bytes bytes.
4. cbs=bytes: Converts bytes bytes at a time, specifying the conversion buffer size.
5. skip=blocks: Skips blocks blocks from the beginning of the input file before starting to copy.
6. obs=bytes: Writes bytes bytes at a time, specifying the number of bytes written to the buffer.
7. bs=bytes: Sets the byte size for read/write buffers simultaneously (equal to setting ibs and obs).
8. cbs=bytes: Converts bytes bytes at a time.
9. count=blocks: Copies only blocks blocks of input, with block size equal to the bytes specified by ibs.
10. seek=blocks: Skips blocks blocks from the beginning of the output file before starting to copy.
11. status=progress: Displays progress information, such as the number of bytes copied per second and the percentage of progress.
12. conv=: The keyword can be one of the following 11 types:
conversion: Converts files with specified parameters. ascii: Converts ebcdic to ascii ebcdic: Converts ascii to ebcdic ibm: Converts ascii to alternate ebcdic block: Converts each line to a length of cbs, padding with spaces if insufficient unblock: Makes each line length equal to cbs, padding with spaces if insufficient lcase: Converts uppercase characters to lowercase ucase: Converts lowercase characters to uppercase swap: Swaps every pair of input bytes noerror: Does not stop on errors notrunc: Does not truncate output files sync: Pads each input block to ibs bytes, filling insufficient parts with null (NUL) characters.
3. Common Examples of the dd Command
1. Create an empty file using the dd command
dd if=/dev/zero of=test.txt bs=1M count=1000
This command creates an empty file named test.txt, with a size of 1000MB, where each block is 1MB.
2. Complete file copying using the dd command
dd if=test_in.txt of=test_out.txt ibs=1024 obs=1024
This command copies a file named test_in.txt to another file named test_out.txt, with a read and write byte size of 1024 bytes.3. Convert lowercase letters in test1 to uppercase and save to test2 using the dd command.
dd if=test1 of=test2 conv=ucase
4. Copy the contents of one disk to another using the dd command
dd if=/dev/sda of=/dev/sdb bs=4096
This command copies the contents of the /dev/sda disk to the /dev/sdb disk, with a block size of 4096 bytes.
5. Copy the contents of a disk to a file using the dd command
dd if=/dev/sda of=test.txt bs=4096 count=1000 status=progress
This command copies the first 1000 blocks of the /dev/sda disk to the test.txt file, with each block size of 4096 bytes, and displays progress information.
6. Backup an entire hard drive using dd: The dd command can back up an entire hard drive to another hard drive
dd if=/dev/sda of=/dev/sdb bs=4096 conv=noerror,sync
This command copies the contents of the /dev/sda disk to the /dev/sdb disk, with each block size of 4096 bytes. conv=noerror,sync indicates that errors during reading are ignored, and the output is synchronized to the corresponding disk.
7. Convert files from one format to another using the dd command
dd if=input.txt of=output.bin bs=1 count=1
8. Create a disk image file using the dd command
dd if=/dev/cdrom of=image.iso
This command creates a CDROM image file named image.iso.
9. Test the read and write speed of a disk using the dd command
dd if=/dev/sda of=/dev/null bs=1M count=1000
10. Test disk read and write operations using the dd command in conjunction with the time command
[root@localhost ~]# time dd if=/dev/zero of=test.txt bs=1M count=1000 oflag=direct
This command shows that the speed of disk read operations can reach 95.9MB/s, generating the test.txt file.
4. Conclusion
The dd command can be used in many testing scenarios, with several characteristics:
1. Powerful data conversion and copying capabilities
The dd command can be used to copy and convert files, devices, etc., and can perform format conversions during the copying process. It can read and write specified data blocks, supporting various block sizes and conversion methods, enabling complex data processing tasks.
2. Flexible parameters and options
The dd command has many parameters and options that can be flexibly configured as needed. For example, the “if=” option specifies the input file, the “of=” option specifies the output file, and block sizes and conversion methods can also be set. These options provide great flexibility, allowing the dd command to meet various needs.
3. Low-level data processing
The dd command processes data at a low level, allowing interaction with the operating system’s core. This makes it suitable for tasks that require direct manipulation of low-level data, such as creating disk images and converting file formats.
4. Requires careful use
Although the dd command is very powerful, improper use can lead to data loss or corruption. Therefore, it is essential to understand the meaning of its parameters and options carefully before using the dd command and to ensure the correctness of the command. Additionally, careful handling of data is necessary to avoid accidentally overwriting or deleting important data.
— EOF —Recommended Reading Click the title to jump
1. Amazing! A single command to permanently activate Win11/Win10 & Office ~
2. Euler Linux System Management Guide: A Comprehensive List of Efficient and Practical Commands!
3. Please keep this, one-click activation for Pycharm 2025 Professional Edition! (With activation code)
4. Huawei Euler System has been heavily criticized! We should be grateful for having CentOS in the past~
5. Efficiently modify files in Linux without using vi/vim editors~
6. Powerful and cool, this network diagnostic tool is amazing!
7. VMware virtual machines are now free, yet some still don’t know how to obtain and use them?
Did you gain something from this article? Please share it with more people
Recommended to follow “Aqiu’s Linux Advanced Path” to enhance Linux and other IT skills
Like Share Service always present 🌷 Give a like Looking Never down 🍀