Operations 7 min read

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.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Linux dd: Copy, Backup, and Transform Files with Powerful Commands

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

dd

can 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=4M

The 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=4M

This copies the data from backup.img to the new disk /dev/sdb.

Generate Random Data

dd

can also generate files filled with random data.

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

The 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=1K

Show Progress Information

To display progress while dd runs, add the status=progress option.

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

This prints the number of bytes transferred and the transfer speed.

Skip and Truncate Data

dd

can 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

dd

can 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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Linuxcommand-lineddfile copydisk backup
Liangxu Linux
Written by

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.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.