View the First Several Bytes, Kilobytes, or Megabytes of a File


head -c

The -n option allows you to specify the number of lines you view at the top of a file, but what if you what to see a certain number of bytes? Or kilobytes? Or even (and this is a bit silly because it would scroll on forever) megabytes? Then use the -c (or --bytes=) option.

To see the first 100 bytes of Chaucer's Canterbury Tales, you'd use this:

$ head -c 100 Canterbury_Tales.txt Here bygynneth the Book of the Tales of Caunterbury General Prologue Whan that Aprill, with his sh 


100 bytes means 100 bytes, and if that means the display is cut off in the middle of a word, so be it.

To view the first 100KB of Chaucer's Canterbury Tales, you'd use this:

$ head -c 100k Canterbury_Tales.txt Here bygynneth the Book of the Tales of Caunterbury General Prologue Whan that Aprill, with his shoures soote The droghte of March hath perced to the roote And bathed every veyne in swich licour, Of which vertu engendred is the flour; Whan Zephirus eek with his sweete breeth Inspired hath in every holt and heeth 


And to view the first 100MB of Chaucer's Canterbury Tales, you'd use...no, that would take up the rest of the book! But if you wanted to do it, try this:

$ head -c 100m Canterbury_Tales.txt 


The m here means 1048576 bytes, or 1024 x 1024.



Linux Phrasebook
Linux Phrasebook
ISBN: 0672328380
EAN: 2147483647
Year: 2007
Pages: 288

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net