Hacker News new | past | comments | ask | show | jobs | submit login

The author neglects to mention any of the use cases where "dd" really is the best alternative. Such as when you need to copy a bootloader from an existing image without damaging your partition table:

# My partition table is in sector 0 and my Linux partition starts at sector 62500

dd if=random-linux-image.img of=/dev/mmcblk0 bs=512 count=62499 seek=1 skip=1

How do you make "cat" seek 512 bytes into its stdout before writing? You can't. And even if you used a temporary file, I think the above is better than a pipeline of "head" and "tail" with uses of $(()) to convert from sector to byte units.

Once you have learned to use the tool in such situations a few times, you mentally start to associate it with "disk operations". So you start to use it also in simpler situations where simpler tools would be sufficient. You start teaching its use to others. I don't think it's that strange, or bad in any way.




A generous interpretation of the title might be that the author is only writing about those for whom dd is so ingrained in their style that they use it where another command would be more natural, hence they're "cultish".


You can use head as stated in the article:

sudo dd if=/dev/sda of=/tmp/boot.1 bs=512 count=1

sudo head -c 512 /dev/sda > /tmp/boot.2

md5sum /tmp/boot.1

06d6f2aa3e7c33ad06282f70aa4e133b /tmp/boot.1

md5sum /tmp/boot.2

06d6f2aa3e7c33ad06282f70aa4e133b /tmp/boot.2


You missed a nuance in the GP's problem set:

> dd if=random-linux-image.img of=/dev/mmcblk0 bs=512 count=62499 seek=1 skip=1

is not the same as:

> sudo dd if=/dev/sda of=/tmp/boot.1 bs=512 count=1

You are missing the "seek" and "skip" arguments which the GP challenges you to make `head` do.


You right. To skip you can pipe tail.

sudo head -c 1024 /dev/sda | tail -zc 512 > /tmp/boot.2

Read 1024, keep last 512


What if the position is not at 512 but at 512G?


Not tested, by I think the performance will be in the same order. Would be nice to do a benchmark test.


No, it is O(n) vs O(1). Why would you read 512G + 512 bytes if you only need to read 512 bytes at offset 512G?


I think you can just invert and do tail first

sudo tail -zc +513 /dev/sda | head -c 512 > /tmp/boot.2


Well now you're seeking to the offset (tail is).


That "sudo head" only works for reading, not writing though.

I use dd when redirect doesn't have permission.


I've seen tee used for that, but I myself stick to dd (out of habbit or because I belong to said cult).




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: