Several implementations of head
support a -c
option for that. The GNU implementation also accepts suffixes, M
for mebibytes, recent versions also supporting MB
for megabyte (1,000,000) and MiB
for mebibyte (1,048,576).
head -c 2097152
head -c 2M
head -c 2MiB
head -c 2000000
head -c 2MB
With pv
, you can specify the size with -s
and tell it to stop reading as soon as it's reached with -S
. Again, suffixes are supported, but that's for powers of 1024, not 1000.
pv -Ss 2M
pv -Ss 2097152
pv -Ss 2000000
(add -q
if you don't want progress information)
With GNU dd
, you can do:
dd iflag=fullblock,count_bytes bs=64k count=2097152 status=none
dd iflag=fullblock,count_bytes bs=64k count=2MiB status=none
dd iflag=fullblock,count_bytes bs=64k count=2M status=none
dd iflag=fullblock,count_bytes bs=64k count=2000000 status=none
dd iflag=fullblock,count_bytes bs=64k count=2MB status=none
head
can do bytes, too - which flavor are you using?dd bs=2M count=1
?