Master Linux dd: Copy, Backup, and Transform Files with Powerful Commands
Learn how to harness the versatile Linux dd command for copying files, creating and restoring disk images, generating random data, adjusting block sizes, showing progress, skipping or truncating data, and performing on‑the‑fly conversions, with clear examples and practical tips for safe usage.
Copy Files
The dd command can be used to copy a file from one location to another. dd if=input.txt of=output.txt This copies the contents of input.txt to output.txt.
Backup and Restore Disks
ddcan create a full backup of a disk and restore that backup to a new disk.
# Create a disk backup
dd if=/dev/sda of=backup.img bs=4MThe command copies the entire content of /dev/sda into the file backup.img.
# Restore the backup to a new disk
dd if=backup.img of=/dev/sdb bs=4MThis copies the data from backup.img to the new disk /dev/sdb.
Generate Random Data
ddcan also generate files filled with random data.
dd if=/dev/urandom of=random_data.bin bs=1M count=10The result is a file random_data.bin containing 10 MiB of random bytes.
Adjust Block Size
By specifying the bs (block size) parameter, you can control the block size used by dd, which can affect copy performance.
dd if=input.txt of=output.txt bs=1KShow Progress Information
To display progress while dd runs, add the status=progress option.
dd if=input.txt of=output.txt bs=1M status=progressThis prints the number of bytes transferred and the transfer speed.
Skip and Truncate Data
ddcan skip a portion of the input file or truncate the output. dd if=input.txt of=output.txt bs=1G skip=1 This skips the first 1 GiB of input.txt and writes the remainder to output.txt.
Modify File Size
You can truncate or extend a file to a specific size using seek or count. dd if=/dev/null of=output.txt bs=1M seek=100 This creates (or truncates) output.txt to exactly 100 MiB; any excess data is discarded.
Convert Data Format While Copying
ddcan perform on‑the‑fly data conversion. For example, converting all text to uppercase: dd if=input.txt of=output.txt conv=ucase The command reads from input.txt, converts the data to uppercase, and writes it to output.txt.
Skip the Beginning of an Input File
The skip parameter lets you ignore the first part of the input file. dd if=input.txt of=output.txt bs=1G skip=1 This reads input.txt, skips the first 1 GiB, and writes the rest to output.txt.
Limit the Amount of Data Copied
You can restrict dd to copy only a specific amount of data. dd if=input.txt of=output.txt bs=1G count=5 This copies the first 5 GiB from input.txt to output.txt.
Summary
The dd command is a powerful Linux utility for copying, converting, generating, and modifying file and device data. Its versatility makes it useful for many tasks, but incorrect parameters can cause data loss, so always verify the command before execution.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
