The other answers explained it already, but if you have any doubts, you can see what dd
does with strace
.
$ strace dd if=/dev/urandom bs=4096 seek=7 count=2 of=file_with_holes
# output is shortened considerably
open("/dev/urandom", O_RDONLY) = 0
open("file_with_holes", O_RDWR|O_CREAT, 0666) = 1
ftruncate(1, 28672) = 0
lseek(1, 28672, SEEK_CUR) = 28672
read(0, "\244\212\222v\25\342\346\226\237\211\23\252\303\360\201\346@\351\6c.HF$Umt\362;E\233\261"..., 4096) = 4096
write(1, "\244\212\222v\25\342\346\226\237\211\23\252\303\360\201\346@\351\6c.HF$Umt\362;E\233\261"..., 4096) = 4096
read(0, "~\212q\224\256\241\277\344V\204\204h\312\25pw9\34\270WM\267\274~\236\313|{\v\6i\22"..., 4096) = 4096
write(1, "~\212q\224\256\241\277\344V\204\204h\312\25pw9\34\270WM\267\274~\236\313|{\v\6i\22"..., 4096) = 4096
close(0) = 0
close(1) = 0
write(2, "2+0 records in\n2+0 records out\n", 312+0 records in
2+0 records out
) = 31
write(2, "8192 bytes (8.2 kB) copied", 268192 bytes (8.2 kB) copied) = 26
write(2, ", 0.00104527 s, 7.8 MB/s\n", 25, 0.00104527 s, 7.8 MB/s
) = 25
+++ exited with 0 +++
It opens /dev/urandom
for reading (if=/dev/urandom
), opens file_with_holes
for create/write (of=file_with_holes
).
Then it truncates file_with_holes
to 4096*7
=28672
bytes (bs=4096 seek=7
). The truncate means that file contents after that position are lost. (Add conv=notrunc
to avoid this step). Then it seeks to 28672
bytes.
Then it reads 4096
bytes (bs=4096
used as ibs
) from /dev/urandom
, writes 4096
bytes (bs=4096
used as obs
) to file_with_holes
, followed by another read and write (count=2
).
Then it closes /dev/urandom
, closes file_with_holes
, and prints that it copied 2*4096
= 8192
bytes. Finally it exits without error (0).