title: How to flush cache of hard-disk and flash-disk (or filesystem) from command line?
body: <p>I'm writing a backup script which </p>
  
  <ol>
  <li>Copies the data to backup disk.</li>
  <li>Flushes the backup disk.</li>
  <li>Performs a hash integrity check.</li>
  </ol>
  
  <p>Before I used to do <code>sleep(60)</code> for waiting a minute so that data is automatically flushed by the kernel. Which I guess is overkill so now I'm trying <code>sudo hdparm -F --verbose /dev/disk</code> but it reports error - <code>HDIO_DRIVE_CMD(flushcache) failed: Invalid exchange</code> multiple times.</p>
  
  <p>I'm wondering is there any standard way to flush the cache to hard disk. I think there is because <code>usb-creator-gtk</code> does it, <code>umount</code> does it.</p>
  
  <p>I'm using Ubuntu x64 9.10</p>
  
  <p>PS: I'm trying to avoid <strong>"sync"</strong> because this page says that it is <em>not</em> safe. <a href="http://ubuntuforums.org/showthread.php?t=589975" rel="noreferrer">http://ubuntuforums.org/showthread.php?t=589975</a></p>