cheat.sheets:dd
# dd
# Convert and copy a file (AKA: Destroyer of Disks)
# Read from `/dev/urandom`, 2*512 Bytes, and put it into `/tmp/test.txt`.
# Note: each iteration reads 512 bytes (the selected block size).
dd if=/dev/urandom of=/tmp/test.txt count=2 bs=512
# Watch the progress of dd(1).
dd if=/dev/zero of=/dev/null bs=4KB &
export dd_pid=`pgrep '^dd'`
while [[ -d /proc/$dd_pid ]]; do
kill -USR1 $dd_pid && sleep 1
clear
done
# Watch the progress of dd(1) with pv(1) and dialog(1), both of which can be
# installed with the following command: apt-get install pv dialog
(
pv -n /dev/zero | dd of=/dev/null bs=128M conv=notrunc,noerror
) 2>&1 | dialog --gauge "Running dd command (cloning), please wait..." 10 70 0
# Watch the progress of dd(1) with pv(1) and zenity(1), both of which can be
# installed with the following command: apt-get install pv zenity
(
pv -n /dev/zero | dd of=/dev/null bs=128M conv=notrunc,noerror
) 2>&1 | zenity --title 'Cloning with dd(1) -- please wait...' --progress
# Watch the progress of dd(1) with the built-in `progress` functionality, -
# introduced in CoreUtils v8.24.
dd if=/dev/zero of=/dev/null bs=128M status=progress
# DD with "graphical" return
dcfldd if=/dev/zero of=/dev/null bs=500K
# This will output the sound from your microphone port to the ssh target
# computer's speaker port. The sound quality is very bad, so you will hear a
# lot of hissing.
dd if=/dev/dsp | ssh -c arcfour -C username@host dd of=/dev/dsp
# Show current progress without interruption (USR1)
dd if=/dev/zero of=/dev/null & pid=$!
kill -USR1 $pid
# Create a 1GiB file with nothing but zeros, ready to mkswap(8) it.
dd if=/dev/zero of=/swapfile count=1048576 bs=1024 status=progress
cheat:dd
# Read from {/dev/urandom} 2*512 Bytes and put it into {/tmp/test.txt}
# Note: At the first iteration, we read 512 Bytes.
# Note: At the second iteration, we read 512 Bytes.
dd if=/dev/urandom of=/tmp/test.txt count=2 bs=512
# Watch the progress of 'dd'
dd if=/dev/zero of=/dev/null bs=4KB &; export dd_pid=`pgrep '^dd'`; while [[ -d /proc/$dd_pid ]]; do kill -USR1 $dd_pid && sleep 1 && clear; done
# Watch the progress of 'dd' with `pv` and `dialog` (apt-get install pv dialog)
(pv -n /dev/zero | dd of=/dev/null bs=128M conv=notrunc,noerror) 2>&1 | dialog --gauge "Running dd command (cloning), please wait..." 10 70 0
# Watch the progress of 'dd' with `pv` and `zenity` (apt-get install pv zenity)
(pv -n /dev/zero | dd of=/dev/null bs=128M conv=notrunc,noerror) 2>&1 | zenity --title 'Running dd command (cloning), please wait...' --progress
# Watch the progress of 'dd' with the built-in `progress` functionality
# (introduced in coreutils v8.24)
dd if=/dev/zero of=/dev/null bs=128M status=progress
# DD with "graphical" return
dcfldd if=/dev/zero of=/dev/null bs=500K
# This will output the sound from your microphone port to the ssh target
# computer's speaker port. The sound quality is very bad, so you will hear a
# lot of hissing.
dd if=/dev/dsp | ssh -c arcfour -C username@host dd of=/dev/dsp
# Create a 1MB file with zero allocated blocks:
dd if=/dev/zero of=foo1 seek=1 bs=1M count=0
tldr:dd
# dd
# Convert and copy a file.
# More information: <https://www.gnu.org/software/coreutils/dd>.
# Make a bootable USB drive from an isohybrid file (such like `archlinux-xxx.iso`):
dd if=path/to/file.iso of=/dev/usb_drive
# Clone a drive to another drive with 4 MiB block and ignore error:
dd if=/dev/source_drive of=/dev/dest_drive bs=4194304 conv=noerror
# Generate a file of 100 random bytes by using kernel random driver:
dd if=/dev/urandom of=path/to/random_file bs=100 count=1
# Benchmark the write performance of a disk:
dd if=/dev/zero of=path/to/file_1GB bs=1024 count=1000000
# Generate a system backup into an IMG file:
dd if=/dev/drive_device of=path/to/file.img
# Restore a drive from an IMG file:
dd if=path/to/file.img of=/dev/drive_device
$
cheat.sh