Aug 292013
 

Debian unfortunately has pv in an older version, the newest one includes a very practical “-S” option, which will stop at a certain size (which is specified by –s in bytes).

I use it to calculate checksums of SD cards (Raspberry Pi images!). Now some SD cards are larger than others, but still the same image size is written.

Fortunately, we can combine several Linux tools to still get a predictable MD5 sum of a fixed size of the input file / SD card:

pv -tprebc -B 512K -s 7742685184 /dev/sdn | head -qc 7742685184 | md5sum

pv: Pipe Viewer, will show a progress bar

  • t – turn the timer on – will show the total time pv has been running
  • p – show progress bar
  • r – turn the rate counter on – will show the data transfer rate
  • e – show estimated time of arrival
  • b – turn total byte counter on
  • c – cursor mode (do not use carriage returns). May be handy when displaying multiple pv’s on the screen?
  • B – Buffer size
  • s <bytes> – assume file is <bytes> big, when calculating the percentages and ETAs
  • S – stop after s <bytes> have been read (NOT available in the Debian version currently)

head: show only the first bytes of a file

  • q – quiet: don’t show the file name
  • c <bytes> – read <bytes> from the beginning of the file (otherwise head will assume you mean lines)

md5sum: calculate the md5sum of a file

Bonus:

du –b <filename> 

will show the size of a file in bytes

blockdev --getsize64 /dev/sdb

will show the size of /dev/sdb (for instance a USB card reader with a SD card inserted) in bytes.

Optimization WordPress Plugins & Solutions by W3 EDGE