Commands using dd (158)

  • This example is taken from Cygwin running on Win7Ent-64. Device names will vary by platform. Both commands resulted in identical files per the output of md5sum, and ran in the same time down to the second (2m45s), less than 100ms apart. I timed the commands with 'time', which added before 'dd' or 'readom' gives execution times after the command completes. See 'man time' for more can be found on any Unix or Linux newer than 1973. Yeah, that means everywhere. readom is supposed to guarantee good reads, and does support flags for bypassing bad blocks where dd will either fail or hang. readom's verbosity gave more interesting output than dd. On Cygwin, my attempt with 'readom' from the first answer actually ended up reading my hard drive. Both attempts got to 5GB before I killed them, seeing as that is past any CD or standard DVD. dd: 'bs=1M' says "read 1MB into RAM from source, then write that 1MB to output. I also tested 10MB, which shaved the time down to 2m42s. 'if=/dev/scd0' selects Cygwin's representation of the first CD-ROM drive. 'of=./filename.iso' simply means "create filename.iso in the current directory." readom: '-v' says "be a little noisy (verbose)." The man page implies more verbosity with more 'v's, e.g. -vvv. dev='D:' in Cygwin explicitly specifies the D-drive. I tried other entries, like '/dev/scd0' and '2,0', but both read from my hard drive instead of the CD-ROM. I imagine my LUN-foo (2,0) was off for my system, but on Cygwin 'D:' sort of "cut to the chase" and did the job. f='./filename.iso' specifies the output file. speed=2 simply sets the speed at which the CD is read. I also tried 4, which ran the exact same 2m45s. retries=8 simply means try reading a block up to 8 times before giving up. This is useful for damaged media (scratches, glue lines, etc.), allowing you to automatically "get everything that can be copied" so you at least have most of the data. Show Sample Output

    dd bs=1M if=/dev/scd0 of=./filename.iso OR readom -v dev='D:' f='./filename.iso' speed=2 retries=8
    scotharkins · 2013-10-23 15:53:27 0
  • removes all files/filesystems of a harddisk. It removes EVERYTHING of your hard disk. Be carefull when to select a device. It does not prompt for and second check. Show Sample Output

    dd if=/dev/null of=/dev/sda
    metaverse · 2013-08-30 21:06:36 0
  • Your platform may not have pv by default. If you are using Homebew on OSX, simply 'brew install pv'. Show Sample Output

    pv -tpreb /dev/sda | dd of=/dev/sdb bs=1M
    sc0ttyd · 2013-08-19 23:04:15 1
  • For DVD: dd if=/dev/cdrom of=cd.iso Show Sample Output

    dd if=/dev/cdrom of=cd.iso
    neilmccauley · 2013-06-12 14:13:41 0
  • MBR is first 512B in partions.

    dd if=/dev/sda of=mbr.bk bs=512 count=1
    lili · 2013-05-17 02:59:33 0

  • 0
    dd if=/dev/zero of=/fs/to/fill/dummy00 bs=8192 count=$(df --block-size=8192 / | awk 'NR!=1 {print $4-100}')
    veenaloke · 2013-04-21 13:57:14 0
  • The posting by St?phane Chazelas also lists the following offsets: type 32768 (1 byte) id 32769 (5 bytes) version 32774 (1 byte) system_id 32776 (32 bytes) volume_id 32808 (32 bytes) volume_space_size 32848 (8 bytes) escape_sequences 32856 (32 bytes) volume_set_size 32888 (4 bytes) volume_sequence_number 32892 (4 bytes) logical_block_size 32896 (4 bytes) path_table_size 32900 (8 bytes) type_l_path_table 32908 (4 bytes) opt_type_l_path_table 32912 (4 bytes) type_m_path_table 32916 (4 bytes) opt_type_m_path_table 32920 (4 bytes) root_directory_record 32924 (34 bytes) volume_set_id 32958 (128 bytes) publisher_id 33086 (128 bytes) preparer_id 33214 (128 bytes) application_id 33342 (128 bytes) copyright_file_id 33470 (37 bytes) abstract_file_id 33507 (37 bytes) bibliographic_file_id 33544 (37 bytes) creation_date 33581 (17 bytes) modification_date 33598 (17 bytes) expiration_date 33615 (17 bytes) effective_date 33632 (17 bytes) file_structure_version 33649 (1 byte) application_data 33651 (512 bytes)

    dd if=/dev/cdrom bs=1 skip=32808 count=32 conv=unblock cbs=32 2>/dev/null
    mlk · 2013-04-14 20:50:58 0
  • It will produce passwords with length of 20 printable characters within a reasonable time. For shorter or longer passwords just change the 20 in bs=20 to something more convenient. To create only alpha numeric passwords change [:print:] to [:alnum:] Show Sample Output

    dd if=/dev/urandom | tr -d -c [:print:] | tr -d " " | dd count=1 bs=20 2> /dev/null; echo
    Progent · 2013-03-01 22:42:29 0

  • 5
    sudo dd if=/dev/sdc bs=4096 | pv -s `sudo mount /dev/sdc /media/sdc && du -sb /media/sdc/ |awk '{print $1}' && sudo umount /media/sdc`| sudo dd bs=4096 of=~/USB_BLACK_BACKUP.IMG
    juanmi · 2013-02-06 09:29:10 2
  • This is a useful command to backup an sd card with relative total size for piping to pv with a progressbar

    export BLOCKSIZE='sudo blockdev --getsize64 /dev/sdc' && sudo dd if=/dev/sdc bs=1MB | pv -s $BLOCKSIZE | gzip -9 > USB_SD_BACKUP.img.gz
    hur1can3 · 2013-02-05 18:10:25 1
  • This is just a proof of concept: A FILE WHICH CAN AUTOMOUNT ITSELF through a SIMPLY ENCODED script. It takes advantage of the OFFSET option of mount, and uses it as a password (see that 9191? just change it to something similar, around 9k). It works fine, mounts, gets modified, updated, and can be moved by just copying it. USAGE: SEE SAMPLE OUTPUT The file is composed of three parts: a) The legible script (about 242 bytes) b) A random text fill to reach the OFFSET size (equals PASSWORD minus 242) c) The actual filesystem Logically, (a)+(b) = PASSWORD, that means OFFSET, and mount uses that option. PLEASE NOTE: THIS IS NOT AN ENCRYPTED FILESYSTEM. To improve it, it can be mounted with a better encryption script and used with encfs or cryptfs. The idea was just to test the concept... with one line :) It applies the original idea of for encrypting the file. The embedded bash script can be grown, of course, and the offset recalculation goes fine. I have my own version with bash --init-file to startup a bashrc with a well-defined environment, aliases, variables. Show Sample Output

    dd if=/dev/zero of=T bs=1024 count=10240;mkfs.ext3 -q T;E=$(echo 'read O;mount -o loop,offset=$O F /mnt;'|base64|tr -d '\n');echo "E=\$(echo $E|base64 -d);eval \$E;exit;">F;cat <(dd if=/dev/zero bs=$(echo 9191-$(stat -c%s F)|bc) count=1) <(cat T;rm T)>>F
    rodolfoap · 2013-01-31 01:38:30 5

  • 0
    sudo dd if=/your.img of=/dev/rdiskx bs=1m
    raaiman · 2012-10-30 05:57:33 0

  • 1
    dd if=mybackup.ab bs=24 skip=1 | openssl zlib -d > mybackup.tar
    bugmenot · 2012-10-28 10:33:07 0
  • Blocksize (bs) is not mandatory. It's only needed when the count option is specified.

    dd.exe --progress if=\\.\Volume{0b1a0cbe-11da-11c0-ab53-003045c00008} of=pendrive.img
    bugmenot · 2012-10-13 08:25:48 0

  • 0
    perl -e '$s="$s\xFF" while length($s)<512; print $s while 1' | dd of=/dev/sdX
    stonefoz · 2012-08-20 05:33:28 0
  • This example will close the pipe after transferring 100MB at a speed of 3MB per second.

    cat /dev/urandom | pv -L 3m | dd bs=1M count=100 iflag=fullblock > /dev/null
    bugmenot · 2012-07-29 00:42:16 2
  • An easy method to generate ISOs from CD/DVD media.

    dd if=/dev/cdrom of=~/cdrom_image.iso
    o0110o · 2012-07-10 06:03:25 6
  • Write 200 blocks of 512k to a dummy file with dd, timing the result. The is useful as a quick test to compare the performance of different file systems. Show Sample Output

    time dd if=/dev/zero of=dummy_file bs=512k count=200
    rdc · 2012-04-20 13:47:27 0
  • dd can be used with /dev/zero to easily create a file of all zero-bytes. Pipe that through tr and use octal conversions to change the byte values from zero to 0xff (octal 0377). You can replace 0377 with the byte of your choice. You can also use \\0 and \\377 instead of the quoted version.

    dd if=/dev/zero bs=64K count=1 | tr "\0" "\377" > all_ones
    anduril462 · 2012-04-17 18:01:59 0
  • This version was mentioned in the comments. Credits go to flatcap.

    pv -tpreb /dev/urandom | dd of=file.img
    marrowsuck · 2012-04-11 22:32:52 1

  • 1
    dd if=/dev/cdrom of=~/cdimage.iso
    mesuutt · 2012-03-23 15:26:38 1
  • Keep width to a power of 2 to see patterns emerge. 512 is good. So is 4096 for huge maps. PNM headers are super basic. Show Sample Output

    x=1024; y=32768; cat <(echo -e "P5\n$x $y\n255\n") <(dd if=/dev/sda1 bs=$x count=$y) > sda1.pgm
    adeverteuil · 2012-03-06 03:09:16 1

  • 1
    SIZE=`fdisk -s /dev/sdx`; dd if=/dev/sdx bs=1M | pv -s "$SIZE"k > hdd.img
    dash · 2012-02-29 19:55:26 0
  • The previously-posted one-liner didn't work for me for whatever reason, so I ended up doing this instead.

    dd if=/dev/urandom of=file.img bs=4KB& sleep 1 && pid=`pidof dd`; while [[ -d /proc/$pid ]]; do kill -USR1 $pid && sleep 10 && clear; done
    unixmonkey31714 · 2012-02-23 01:45:53 0
  • This command dumps a mounted disk to an ISO image. (Use "mount" to get the mounted disk's name.) Make sure to un-mount the disk first.

    dd if=/dev/disk1 of=disk1.iso
    DevEd · 2012-02-06 13:58:15 0
  •  < 1 2 3 4 >  Last ›

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: