Live data from Hacker News

The Cult of DD

eklitzke.org

101–110 of 178 posts

Re: The Cult of DD

#101
post #97
post #90

Earlier quoted context omitted.

Unless the input file is a device, and then you need to call: ioctl(STDIN_FILENO, BLKGETSIZE64, &size)

But I guess this is orthogonal to where the file descriptor comes from (i.e. stdin or opening a file whose name is passed in the args)

It's an orthogonal issue, yes, but calling stat or fstat on any block device whether from stdin or argv will return .st_size == 0, so your progress bar won't display the correct answers (or could display better answers if it used the ioctl).

Re: The Cult of DD

#102

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.

but a (boring) su and working as root?

Re: The Cult of DD

#103
post #97
post #90

Earlier quoted context omitted.

Unless the input file is a device, and then you need to call: ioctl(STDIN_FILENO, BLKGETSIZE64, &size)

But I guess this is orthogonal to where the file descriptor comes from (i.e. stdin or opening a file whose name is passed in the args)

[deleted]

Re: The Cult of DD

#104
post #61
post #49

Earlier quoted context omitted.

Even simpler: sudo cp image.iso /dev/sdb

Would that seriously work?

Yes. 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.

Re: The Cult of DD

#105

Earlier quoted context omitted.

Actually, that's not completley true. pv will detect the file size if you use the shell to read a file into it, like pv < file.

At first I thought, no, that's not possible. Then I thought, no, they wouldn't do THAT would they? But I guess they do... http://stackoverflow.com/questions/1734243/in-c-how-do-i-pri... I've seen that kind of brokenness from programs trying to find their binary image on disk. Don't do it, it's bad.

It makes a decent interview question tho', "explain the difference between cat file|./prog and ./prog <file". It doesn't even matter if they get it wrong, that they even know there is a difference is a very good sign.

Re: The Cult of DD

#106
post #72

"This is a strange program of obscure provenance that somehow, still manages to survive in the 21st century." -> links to wikipedia page with direct discription of lineage back to 5th ed research unix "That weird bs=4M argument in the dd version isn’t actually doing anything special—all it’s doing is instructing the dd command to use a 4 MB buffer size while copying. But who cares? Why not just let the command figure…

> pv

(You probably know this as you use OpenBSD, but) something I really like about BSDs is that nost of the core commands respond to ^T with progress info ofsome kin, dd included.

Re: The Cult of DD

#107
post #76

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.

There is a trivial alternative. Just use a subshell. sudo (cat ... > target)

I don't know if this works but I believe it doesn't.

Re: The Cult of DD

#109

not sure status=progress is that obscure a command, it was added relatively recently as well (in terms of dd).

The fact that it was added relatively recently is exactly why it's so obscure. Unlike if, of, bs and count, I haven't had status=progress drilled into my head by every single dd command I've read out of a manual or tutorial, so even now I still forget whether it's "status=progress" or "progress=status" or something else.

Also it's a victim of dd's bizarre non-Unix syntax - an option like "--status" or "--progress" would be more in keeping with expectations.

Re: The Cult of DD

#110
post #105

Earlier quoted context omitted.

At first I thought, no, that's not possible. Then I thought, no, they wouldn't do THAT would they? But I guess they do... http://stackoverflow.com/questions/1734243/in-c-how-do-i-pri... I've seen that kind of brokenness from programs trying to find their binary image on disk. Don't do it, it's bad.

It makes a decent interview question tho', "explain the difference between cat file|./prog and ./prog <file". It doesn't even matter if they get it wrong, that they even know there is a difference is a very good sign.

I think most people wouldn't know the difference (I had no idea!) and the knowledge might fall into the realm of obscure trivia.
Post reply on HN