Table of Contents
Copy file" >Copy file
Backup and restore hard drive" >Backup and restore hard drive
Random data generation" >Random data generation
Adjust block size" >Adjust block size
Display progress information" >Display progress information
Skip and truncate data" >Skip and truncate data
Modify file size" >Modify file size
Copy and convert data format at the same time" >Copy and convert data format at the same time
Skip the beginning of the input file" >Skip the beginning of the input file
Limit the size of data copy" >Limit the size of data copy
Summarize" >Summarize
Home System Tutorial LINUX dd, a super powerful Linux command!

dd, a super powerful Linux command!

Mar 19, 2024 pm 01:52 PM
linux linux tutorial linux system linux command shell script data lost embeddedlinux Getting started with linux linux learning

In Linux systems, the dd command is a highly respected tool with powerful and diverse functions, mainly used for file copying and conversion. Because it is widely used in disk copy and data copy operations, it is named the "disk copy" or "data copy" command. This article aims to comprehensively introduce the various uses of the dd command and provide rich sample code to help readers fully appreciate its functions and potential. ddThe flexibility and customizability of the command make it a powerful tool for processing data conversion between files and devices, showing strong application value in various scenarios.

dd,一个超强的 Linux 命令!

Copy file

dd command can be used to copy files.

The following example copies a file to another location:

dd if=input.txt of=output.txt
Copy after login

This will copy the data from input.txt and write it to output.txt.

Backup and restore hard drive

The

dd command can be used to create a full backup of a hard drive and restore backup data to a new hard drive.

The following example demonstrates how to create a hard drive backup:

# Create hard disk backup
dd if=/dev/sda of=backup.img bs=4M
Copy after login

This will copy the contents of /dev/sda to a file named backup.img.

To restore the backup to a new hard drive, you can perform the following operations:

# Restore backup to new hard drive
dd if=backup.img of=/dev/sdb bs=4M
Copy after login

This will copy the data from backup.img and write it to the new hard drive /dev/sdb.

Random data generation

dd The command can also generate random data.

The following example generates a file containing random data:

dd if=/dev/urandom of=random_data.bin bs=1M count=10
Copy after login

This will generate a file called random_data.bin containing 10 megabytes of random data.

Adjust block size

The block size of the dd command can be adjusted to optimize copy performance by specifying the bs (block size) parameter.

The following example sets the block size to 1K:

dd if=input.txt of=output.txt bs=1K
Copy after login

Display progress information

To display progress information during the execution of the dd command, you can use the status=progress parameter.

For example:

dd if=input.txt of=output.txt bs=1M status=progress
Copy after login

This will display the progress information of the copy, including the number of bytes copied and the speed.

Skip and truncate data

The

dd command can be used to skip a portion of a file or truncate a file.

The following example will skip the first 1GB of the file:

dd if=input.txt of=output.txt bs=1G skip=1
Copy after login
Copy after login

This will copy the data from input.txt, skipping the first 1GB, and then write to output.txt.

Modify file size

dd The command can also be used to modify the file size. The following example truncates a file to a specific size:

dd if=/dev/null of=output.txt bs=1M seek=100
Copy after login

This will truncate output.txt to 100 megabytes, and if the file is originally larger, the excess data will be removed.

Copy and convert data format at the same time

dd The command can not only copy data, but also convert the data format while copying.

For example, you can convert the case of a file to uppercase:

dd if=input.txt of=output.txt conv=ucase
Copy after login

This will read data from input.txt, convert it to uppercase and write it to output.txt.

Skip the beginning of the input file

Sometimes, you may want to skip the beginning of the input file. This can be easily achieved using the skip parameter.

The following example skips the first 1GB of data in the input file:

dd if=input.txt of=output.txt bs=1G skip=1
Copy after login
Copy after login

This will read the data from input.txt, skipping the first 1GB, and then write output.txt.

Limit the size of data copy

dd The command can also limit the size of copied data.

For example, to copy the first 5GB of data in a file:

dd if=input.txt of=output.txt bs=1G count=5
Copy after login

This will read the data from input.txt, copy the first 5GB of data, and write to output.txt.

Summarize

dd The command is a very powerful tool in Linux that can be used to copy, convert, generate and modify files and device data. Its functionality is very diverse, but it also needs to be used with care, as incorrect command parameters can lead to data loss or unrecoverable damage. When using the dd command, always make sure you understand its functionality and carefully check the command parameters so that you can perform the required tasks safely and efficiently.

If you think the article is good, please like, share, and leave a message, because this will be the strongest motivation for me to continue to output more high-quality articles!

The above is the detailed content of dd, a super powerful Linux command!. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1655
14
PHP Tutorial
1253
29
C# Tutorial
1228
24
Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

vscode terminal usage tutorial vscode terminal usage tutorial Apr 15, 2025 pm 10:09 PM

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

vscode terminal command cannot be used vscode terminal command cannot be used Apr 15, 2025 pm 10:03 PM

Causes and solutions for the VS Code terminal commands not available: The necessary tools are not installed (Windows: WSL; macOS: Xcode command line tools) Path configuration is wrong (add executable files to PATH environment variables) Permission issues (run VS Code as administrator) Firewall or proxy restrictions (check settings, unrestrictions) Terminal settings are incorrect (enable use of external terminals) VS Code installation is corrupt (reinstall or update) Terminal configuration is incompatible (try different terminal types or commands) Specific environment variables are missing (set necessary environment variables)

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

vscode Previous Next Shortcut Key vscode Previous Next Shortcut Key Apr 15, 2025 pm 10:51 PM

VS Code One-step/Next step shortcut key usage: One-step (backward): Windows/Linux: Ctrl ←; macOS: Cmd ←Next step (forward): Windows/Linux: Ctrl →; macOS: Cmd →

How to run sublime after writing the code How to run sublime after writing the code Apr 16, 2025 am 08:51 AM

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

See all articles