*ARGS.TECH | BLOG | Working with DD utility in Linux command line interface
Loading...
BLOG

Working with DD utility in Linux command line interface

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. DD is preinstalled in GNU/Linux distributions.


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:

xinit@localhost:~$ dd if=source-file of=destination-file params


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

xinit@localhost:~$ sudo dd if=source-file of=destination-file params


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

xinit@localhost:~$ sudo dd if=~/Downloads/ubuntu-24.04.3-desktop-amd64.iso of=/dev/sdb status=progress

6345669120 bytes (6.3 GB, 5.9 GiB) copied, 3342 s, 1.9 MB/s

12394312+0 records in

12394312+0 records out

6345887744 bytes (6.3 GB, 5.9 GiB) copied, 3346.29 s, 1.9 MB/s


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

xinit@localhost:~$ dd if=/dev/zero of=~/myfile.txt bs=20M count=1

1+0 records in

1+0 records out

20971520 bytes (21 MB, 20 MiB) copied, 0.0154739 s, 1.4 GB/s


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

xinit@localhost:~$ dd if=/dev/zero of=~/myfile.txt bs=1M count=1024

1024+0 records in

1024+0 records out

1073741824 bytes (1.1 GB, 1.0 GiB) copied, 0.615053 s, 1.7 GB/s


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

xinit@localhost:~$ sudo dd if=/dev/cdrom of=~/myimage.img status=progress

626162176 bytes (626 MB, 597 MiB) copied, 3 s, 209 MB/s

1348805+0 records in

1348805+0 records out

690588160 bytes (691 MB, 659 MiB) copied, 3.37326 s, 205 MB/s

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:

xinit@localhost:~$ sudo dd if=/dev/urandom of=/dev/sdb status=progress

6345669120 bytes (6.3 GB, 5.9 GiB) copied, 3342 s, 1.9 MB/s

12394312+0 records in

12394312+0 records out

6345887744 bytes (6.3 GB, 5.9 GiB) copied, 3346.29 s, 1.9 MB/s

Top button
© *ARGS.TECH
2025
v 2.29.0