4 ms·
There's one good (?) reason to use dd with devices: it specifies target in the same command. For devices, writing to them usually requires root privileges, so i
by viraptor 10y ago
There's one good (?) reason to use dd with devices: it specifies target in the same command. For devices, writing to them usually requires root privileges, so it's easy to:
sudo dd .... of=/dev/...
But there's no trivial cat equivalent:
sudo cat ... > target
Will open target as your current user anyway. You can play around with tee and redirection of course. But that's getting more complicated than the original.
- digi_owl 10y agoI think the trick is to do sudo sh, or some such.
- thom_nic 10y agoThis. The alternative: sudo sh -c 'cat some.img > /dev/sdb' or even more baroque: cat some.img | sudo tee /dev/sdb > /dev/null is a pain by comparison, and the `sudo sh -c` variant has env implications when spawning a sub-shell. I have an ARM/linux installer script that writes the u-boot image to a specific offset before the first partition: dd if=${UBOOT_DIR}/MLO of=$LO_DEVICE count=1 seek=1 bs=128k dd if=${UBOOT_DIR}/u-boot.img of=$LO_DEVICE count=2 seek=1 bs=384k This is admittedly somewhat esoteric, but it seems like a stretch to say `dd` does not have some place, especially when transferring binary data in very specific ways.
- majewsky 10y agoSince we're sharing shell tricks: The "sudo tee > /dev/null" may be baroque, but I find it useful whenever I start editing stuff in /etc in vim, only to find that I cannot write my changes because I'm not root. In that case, :w !sudo tee % does the trick. (What "w!" does is send the buffer into the given shell command as stdin.)
- quesera 10y agoEven simpler: sudo cp image.iso /dev/sdb
- notamy 10y agoWould that seriously work?
- skykooler 10y agoYep! See this: http://askubuntu.com/questions/751193/what-is-the-difference-in-using-cp-and-dd-when-cloning-usb-sticks http://askubuntu.com/questions/751193/what-is-the-difference... Basically, you can use cp wherever you use dd, as long as you're not changing any low-level parameters (e.g. starting 500 bytes into the file or something).
- pilif 10y agoYes. Yes it does. Reminds me of a Sunday evening in the late 90ies when I stopped working as root all the time: cp backup.tar.bz /dev/sda Nowadays I would know enough to at least get the contents of the backup.tar.bz back. Back then, this was the end of both my / partition (or any other partition) and the backup of my music collection. Still, that didn't end my love affair with Unix. It did make me a whole lot more careful though.
- jacquesm 10y ago> cp backup.tar.bz /dev/sda Ouch. That just hurts seeing that line.
- btilly 10y agoThere is a trivial alternative. Just use a subshell. sudo (cat ... > target)
- gkya 10y agoI don't know if this works but I believe it doesn't.
- deno 10y agoIt doesn’t. In fact, I would be very careful using subshellsm in general, because it can lead to bugs like this one: http://danwalsh.livejournal.com/74642.html http://danwalsh.livejournal.com/74642.html .
- throwanem 10y agoThat link 404s due to some url-encoded garbage at the end. This should work: http://danwalsh.livejournal.com/74642.html http://danwalsh.livejournal.com/74642.html
- gkya 10y agoWell that's strictly a bug caused by mistaken use, as strings are not expanded lazily and heredocs are just another string syntax. How can one use the unix shell without string interpolation? Also, a similar programme would give the wrong result in, say, Ruby or Perl too.
- _ZeD_ 10y agobut a (boring) su and working as root?
- IshKebab 10y agosudo bash