Working with DD utility in Linux command line interface
Shakhzhakhan Maxudbek

Shakhzhakhan Maxudbek @xinitd

About: System administrator, software engineer, technical blogger and open source contributor. Passionate about automation and cloud technologies.

Location:
Kazakhstan
Joined:
Nov 30, 2024

Working with DD utility in Linux command line interface

Publish Date: Feb 16
0 0

DD (Data Definition) - powerful command line interface utility, designed for work with files (copy, converting, etc...) byte-by-byte. Similar to cp command it may copy from source file (if=...) to destination file (of=...). But difference from cp command - DD may control input/output parameters in low level. Also DD may clone, backup, mirror partitions.

Most frequently used args:
if - input file, which must be copied. May be plain file or device.
of - output file. Also may be plain file or device.
bs - size of one block, which will be writed at one time. The default value is 512 bytes.
count - quantity of blocks for copy at one time.
status - display data transfer statistics. Three values available: none, noxfer and progress.

Attention! Be careful when working with DD, because it allows low level instructions, and you may lose data at the slightest mistake.

Basic DD syntax:

dd if=source-file of=destination-file params
Enter fullscreen mode Exit fullscreen mode

If you get permission issues, run DD as root with sudo command:

sudo dd if=source-file of=destination-file params
Enter fullscreen mode Exit fullscreen mode

Creating bootable device. For example, when you need to create Live USB stick. Command write content of iso file in USB drive:

sudo dd if=~/Downloads/ubuntu-24.04.1-desktop-amd64.iso of=/dev/sdb status=progress
Enter fullscreen mode Exit fullscreen mode

Generating file with a certain size. Create file, filled with zeros and 20 mb size:

dd if=/dev/zero of=~/myfile.txt bs=20M count=1
Enter fullscreen mode Exit fullscreen mode

Generating large file with a specified size. This example will give out file with 1024 mb (1 gb) size:

dd if=/dev/zero of=~/myfile.txt bs=1M count=1024
Enter fullscreen mode Exit fullscreen mode

Creating image from CD. Just specify source and destination files, does not need any args. Insert disc in cdrom and run:

sudo dd if=/dev/cdrom of=~/my-image.img
Enter fullscreen mode Exit fullscreen mode

Extension of output file also may be iso.

Rewriting partition with random data. Needs for security reasons. Command fill devices with random data and make harder data recovery from this device. Usage:

sudo dd if=/dev/urandom of=/dev/sdb status=progress
Enter fullscreen mode Exit fullscreen mode

Comments 0 total

    Add comment