fstatfs - Linux


Overview

fstatfs is a command-line utility that displays the file system statistics of the specified file or directory. It provides detailed information about the file system, including its type, size, free space, and mount point. This command is useful for monitoring file system usage, troubleshooting storage issues, and performing system administration tasks.

Syntax

fstatfs [options] <FILE>

Options/Flags

  • -a, –all: Display statistics for all file systems.
  • -E, –print-entries: Print filesystem entries.
  • -f, –file-system: Display only statistics for the specified file system type.
  • -l, –logical: Display logical block size.
  • -m, –megabytes: Display block size in megabytes.
  • -p, –physical: Display physical block size.
  • -t, –type: Display file system type.

Examples

Get file system statistics for a single file:

fstatfs my_file.txt

Display statistics for all file systems:

fstatfs -a

Show file system type and free space for all mounted file systems:

fstatfs -t -m

Common Issues

  • Incorrect file paths: Ensure you specify the correct path to the file or directory.
  • Permission denied: Make sure you have sufficient permissions to access the file system or directory.
  • Unknown file system type: If the file system type is not recognized, it may indicate an unsupported file system or a corrupted file system.

Integration

Combine with df:

df -hT | fstatfs -m

This command combines df and fstatfs to display file system usage and statistics in a table format.

Create a script to monitor file system usage:

#!/bin/bash
while true; do
  fstatfs -Ea | grep /dev/sda1;
  sleep 60
done

This script continuously monitors the file system usage of /dev/sda1 and prints the statistics every minute.

Related Commands

  • df: Display file system usage
  • mount: Mount and unmount file systems
  • umount: Unmount file systems