The difference between ‘bs’, ‘count’ and ‘seek’ in dd command

dd

I've read many guides and forum posts describing how to use dd, but one thing I've noticed is that people always use different values for the bs=, count= and seek= switches.

Please can someone explain what these switches do exactly (the man page isn't very detailed), and explain what the best settings for them are for different tasks, such as creating files from /dev/random or /dev/zero, and overwriting partitions and external drives.

Best Answer

I really don't know how to explain this better than the manpage does.

bs= sets the blocksize, for example bs=1M would be 1MiB blocksize.

count= copies only this number of blocks (the default is for dd to keep going forever or until the input runs out). Ideally blocks are of bs= size but there may be incomplete reads, so if you use count= in order to copy a specific amount of data (count*bs), you should also supply iflag=fullblock.

seek= seeks this number of blocks in the output, instead of writing to the very beginning of the output device.

So, for example, this copies 1MiB worth of y\n to position 8MiB of the outputfile. So the total filesize will be 9MiB.

$ yes | dd bs=1M count=1 seek=8 iflag=fullblock of=outputfile
$ ls -alh outputfile
9.0M Jun  3 21:02 outputfile
$ hexdump -C outputfile
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00800000  79 0a 79 0a 79 0a 79 0a  79 0a 79 0a 79 0a 79 0a  |y.y.y.y.y.y.y.y.|
*
00900000

Since you mention /dev/random and overwriting partitions... it will take forever since /dev/random (as well as /dev/urandom) is just too slow. You could just use shred -v -n 1 instead, that's fast and usually available anywhere.

Related Question