cacheflush - Linux


cacheflush is a command-line tool used to flush the disk cache in Linux. It is primarily used to ensure that data written to disk is immediately persisted, without relying on the system’s default write-back caching mechanism. This is particularly useful in scenarios where data integrity and consistency are critical.


cacheflush [options]


  • -i, –inodes: Flush only file metadata.
  • -d, –data: Flush both file metadata and data. (Default)
  • -n, –dry-run: Perform a simulation of the flush operation without actually flushing the cache.
  • -f, –force: Force the flush even if the system is in a busy state.
  • -a, –all: Flush all filesystems and partitions.
  • -l, –log-file: Specify a log file for debugging purposes.


Flush file metadata only:

cacheflush -i

Flush both file metadata and data:

cacheflush -d

Simulate a flush operation:

cacheflush -n

Force flush despite system busyness:

cacheflush -f

Common Issues

System slowdown: Flushing the disk cache can temporarily slow down the system as it writes data to disk.

Data loss: If the system crashes or power is lost during a cache flush, unsaved changes may be lost.

Avoidance: Ensure that the system is in a stable state before flushing the cache and consider backing up sensitive data beforehand.


Combined with rsync:

rsync -avz /source /destination && cacheflush -fd

This command chain ensures that files are securely copied and the disk cache is flushed to prevent data loss in case of a system reboot.

Related Commands

  • sync: Synchronizes cached data to disk, but does not flush metadata.
  • fsync: Flushes data from a single file or file descriptor to disk.
  • rsync: A tool for efficiently backing up and synchronizing files across systems.