How to extract the first x-megabyte from a large file in unix/linux? How to extract the first x-megabyte from a large file in unix/linux? linux linux

How to extract the first x-megabyte from a large file in unix/linux?


E.g.

 dd if=largefile count=6 bs=1M > largefile.6megsonly

The 1M spelling assumes GNU dd. Otherwise, you could do

 dd if=largefile count=$((6*1024)) bs=1024 > largefile.6megsonly

This again assumes bash-style arithmetic evaluation.


Head works with binary files and the syntax is neater than dd.

head -c 2M input.file > output.file

Tail works the same way if you want the end of a file.


Try the command dd. You can use "man dd" to get main ideas of it.