Commands tagged dd (72)

  • Sends SIGINFO to the process. This is a BSD feature OS X inherited. You must have the terminal window executing dd selected when entering CTRL + T for this to work. Show Sample Output


    25
    CTRL + T
    unixmonkey44467 · 2012-12-19 02:21:41 19
  • If you have some drive imaging to do, you can boot into any liveCD and use a commodity machine. The drives will be written in parallel. To improve efficiency, specify a larger block size in dd: dd if=/dev/sda bs=64k | tee >(dd of=/dev/sdb bs=64k) | dd of=/dev/sdc bs=64k To image more drives , insert them as additional arguments to tee: dd if=/dev/sda | tee >(dd of=/dev/sdb) >(dd of=/dev/sdc) >(dd of=/dev/sdd) | dd of=/dev/sde


    23
    dd if=/dev/sda | tee >(dd of=/dev/sdb) | dd of=/dev/sdc
    nerd65536 · 2009-12-11 17:34:38 12
  • Create a temporary file that acts as swap space. In this example it's a 1GB file at the root of the file system. This additional capacity is added to the existing swap space. Show Sample Output


    18
    sudo dd if=/dev/zero of=/swapfile bs=1024 count=1024000;sudo mkswap /swapfile; sudo swapon /swapfile
    dcabanis · 2009-05-27 21:10:50 12
  • This will create an exact duplicate image of your hard drive that you can then restore by simply reversing the "if" & "of" locations. sudo dd if=/media/disk/backup/sda.backup of=/dev/sda Alternatively, you can use an SSH connection to do your backups: dd if=/dev/sda | ssh user@ssh.server.com dd of=~/backup/sda.backup


    16
    sudo dd if=/dev/sda of=/media/disk/backup/sda.backup
    bandit36 · 2009-02-27 20:23:37 17
  • "killall -USR1 dd" does not work in OS X for me. However, sending INFO instead of USR1 works. Show Sample Output


    16
    killall -INFO dd
    jearsh · 2010-04-22 18:38:37 5
  • This line removes the 300k header from a Nero image file converting it to ISO format


    15
    dd bs=1k if=image.nrg of=image.iso skip=300
    rpavlick · 2010-03-30 22:07:58 7

  • 12
    dd if=/path/inputfile | pv | dd of=/path/outpufile
    lucafaus · 2010-12-02 18:11:42 5
  • every 1sec sends DD the USR1 signal which causes DD to print its progress. Show Sample Output


    10
    while :;do killall -USR1 dd;sleep 1;done
    oernii2 · 2010-04-07 09:23:31 9
  • This version was mentioned in the comments. Credits go to flatcap.


    10
    pv -tpreb /dev/urandom | dd of=file.img
    marrowsuck · 2012-04-11 22:32:52 16
  • A dear friend of mine asked me how do I copy a DVD to your hard drive? If you want to make a copy of the ISO image that was burned to a CD or DVD, insert that medium into your CD/DVD drive and (assuming /dev/cdrom is associated with your computer?s CD drive) type the following command


    9
    dd if=/dev/cdrom of=whatever.iso
    0disse0 · 2009-09-05 09:19:41 13

  • 9
    dd if=/dev/zero | pv | dd of=/dev/null
    richard · 2010-05-14 16:58:42 6
  • Create an image of "device" and send it to another machine through the network ("target" and "port" sets the ip and port the stream will be sent to), outputting a progress bar On the machine that will receive, compress and store the file, use: nc -l -p <port> | 7z a <filename> -si -m0=lzma2 -mx=9 -ms=on Optionally, add the -v4g switch at the end of the line in order to split the file every 4 gigabytes (or set another size: accepted suffixes are k, m and g). The file will be compressed using 7z format, lzma2 algorithm, with maximum compression level and solid file activated. The compression stage will be executed on the machine which will store the image. It was planned this way because the processor on that machine was faster, and being on a gigabit network, transfering the uncompressed image wasn't much of a problem.


    8
    dd if=<device> | pv | nc <target> <port>
    quitaiskiluisf · 2012-01-27 18:37:36 16
  • if you need see progress of long dd command, enter subj on other console Show Sample Output


    7
    killall -USR1 dd
    vint · 2009-03-04 08:30:20 8
  • The above command will send 4GB of data from one host to the next over the network, without consuming any unnecessary disk on either the client nor the host. This is a quick and dirty way to benchmark network speed without wasting any time or disk space. Of course, change the byte size and count as necessary. This command also doesn't rely on any extra 3rd party utilities, as dd, ssh, cat, /dev/zero and /dev/null are installed on all major Unix-like operating systems. Show Sample Output


    6
    dd if=/dev/zero bs=4096 count=1048576 | ssh user@host.tld 'cat > /dev/null'
    atoponce · 2010-06-08 18:49:51 10
  • An easy method to generate ISOs from CD/DVD media.


    6
    dd if=/dev/cdrom of=~/cdrom_image.iso
    o0110o · 2012-07-10 06:03:25 10
  • This command clone the first partition of the primary master IDE drive to the second partition of the primary slave IDE drive (!!! back up all data before trying anything like this !!!)


    5
    sudo dd if=/dev/hda1 of=/dev/hdb2
    0disse0 · 2009-09-05 09:16:52 4
  • This is similar to how you would generate a file with all zeros dd if=/dev/zero of=allzeros bs=1024 count=2k


    4
    tr '\000' '\377' < /dev/zero | dd of=allones bs=1024 count=2k
    azeey · 2009-12-08 16:05:28 4
  • This is a more accurate way to watch the progress of a dd process. The $DDPID=$! is needed so that you don't get the PID of the sleep. The sleep 1 is needed because in my testing at least, if you run kill -USR1 against dd too quickly, it will kill it off instead of display the status. So you need to wait a second, probably so that it can configure itself to trap the USR1 signal. Show Sample Output


    4
    dd if=fromfile of=tofile & DDPID=$! ; sleep 1 ; while kill -USR1 $DDPID ; do sleep 5; done
    deltaray · 2010-01-12 15:01:44 4
  • the speed is about 500MB/s on my machine. i think it's fast enough to output not too many bytes. while a C program may output 1GB per sencond on my machine. if the size is not the power of 512,you may change the bs and count in dd. Show Sample Output


    4
    tr '\0' '\377' < /dev/zero|dd count=$((<bytes>/512))
    cfy · 2011-04-05 14:26:02 3
  • Your platform may not have pv by default. If you are using Homebew on OSX, simply 'brew install pv'. Show Sample Output


    4
    pv -tpreb /dev/sda | dd of=/dev/sdb bs=1M
    sc0ttyd · 2013-08-19 23:04:15 7
  • The 'dd' command doesn't provide a progress when writing data. So, sending the "USR1" signal to the process will spit out its progress as it writes data. This command is superior to others on the site, as it doesn't require you to previously know the PID of the dd command. Show Sample Output


    3
    pkill -USR1 ^dd$
    atoponce · 2010-05-14 16:25:01 8
  • In general, this is actually not better than the "scrot -d4" command I'm listing it as an alternative to, so please don't vote it down for that. I'm adding this command because xwd (X window dumper) comes with X11, so it is already installed on your machine, whereas scrot probably is not. I've found xwd handy on boxen that I don't want to (or am not allowed to) install packages on. NOTE: The dd junk for renaming the file is completely optional. I just did that for fun and because it's interesting that xwd embeds the window title in its metadata. I probably should have just parsed the output from file(1) instead of cutting it out with dd(1), but this was more fun and less error prone. NOTE2: Many programs don't know what to do with an xwd format image file. You can convert it to something normal using NetPBM's xwdtopnm(1) or ImageMagick's convert(1). For example, this would work: "xwd | convert fd:0 foo.jpg". Of course, if you have ImageMagick already installed, you'd probably use import(1) instead of xwd. NOTE3: Xwd files can be viewed using the X Window UnDumper: "xwud <foo.xwd". ImageMagick and The GIMP can also read .xwd files. Strangely, eog(1) cannot. NOTE4: The sleep is not strictly necessary, I put it in there so that one has time to raise the window above any others before clicking on it. Show Sample Output


    3
    sleep 4; xwd >foo.xwd; mv foo.xwd "$(dd skip=100 if=foo.xwd bs=1 count=256 2>/dev/null | egrep -ao '^[[:print:]]+' | tr / :).xwd"
    hackerb9 · 2010-09-19 08:03:02 3
  • Adjust "sleep X" to your needs. *NOTE: First sleep is required because bash doesn't have a "post-test" syntax (do XXX while). Show Sample Output


    3
    dd if=/path/to/inputfile of=/path/to/outputfile & pid=$! && sleep X && while kill -USR1 $pid; do sleep X; done
    cyrusza · 2010-12-02 15:07:18 7
  • Replace (as opposed to insert) hex opcodes, data, breakpoints, etc. without opening a hex editor. HEXBYTES contains the hex you want to inject in ascii form (e.g. 31c0) OFFSET is the hex offset (e.g. 49cf) into the binary FILE


    2
    echo -n $HEXBYTES | xxd -r -p | dd of=$FILE seek=$((0x$OFFSET)) bs=1 conv=notrunc
    zombiedeity · 2009-03-11 17:02:24 328
  • Requires the dc3dd package - available at http://dc3dd.sourceforge.net Show Sample Output


    2
    dc3dd progress=on bs=512 count=2048 if=/dev/zero of=/dev/null
    ubahmapk · 2010-01-12 22:54:27 4
  •  1 2 3 > 

What's this?

commandlinefu.com 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


Check These Out

securely erase unused blocks in a partition
This command securely erases all the unused blocks on a partition. The unused blocks are the "free space" on the partition. Some of these blocks will contain data from previously deleted files. You might want to use this if you are given access to an old computer and you do not know its provenance. The command could be used while booted from a LiveCD to clear freespace space on old HD. On modern Linux LiveCDs, the "ntfs-3g" system provides ReadWrite access to NTFS partitions thus enabling this method to also be used on Wind'ohs drives. NB depending on the size of the partition, this command could take a while to complete.

Use the builtin ':' bash command to increment variables
I just found another use for the builtin ':' bash command. It increments counters for me in a loop if a certain condition is met... : [arguments] No effect; the command does nothing beyond expanding arguments and performing any specified redirections. A zero exit code is returned.

Gets the last string of previous command with !$
It helps you save a lot of writing :-)

run php code inline from the command line
Most people know that you can run a PHP script from the command line like so: $php ./my_script.php But sometimes I just want to run a quick bit of code, the PHP Command Line Interface allows me to do so with the -r option. Requires package php5-cli

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Make vim open in tabs by default (save to .profile)
I always add this to my .profile rc so I can do things like: "vim *.c" and the files are opened in tabs.

List your installed Chromium extensions (with url to each page)
Gives you a list for all installed chrome (chromium) extensions with URL to the page of the extension. With this you can easy add a new Bookmark folder called "extensions" add every URL to that folder, so it will be synced and you can access the names from every computer you are logged in. ------------------------------------------------------------------------------------------------------------------ Only tested with chromium, for chrome you maybe have to change the find $PATH.

Commandline document conversion with Libreoffice
In this example, the docx gets converted to Open Document .odt format. For other formats, you'll need to specify the correct filter (Hint: see "Comments" link below for a nice list).

Delete recursively only empty folders on present dir

find which lines in a file are longer than N characters
Filter out lines of input that contain 72, or fewer, characters. This uses bash only. ${#i} is the number of characters in variable i.


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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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: