getfsspec - Linux


Overview

getfsspec retrieves the underlying filesystem specification for a file or directory. It is commonly used to obtain detailed information about filesystems or partitions, making it useful for system administrators and forensic analysis.

Syntax

getfsspec [-hV] [-b SIZE] [-f FIELDS] [files | devices]

Options/Flags

  • -h, –help: Print usage information and exit.
  • -V, –version: Print version information and exit.
  • -b, –buffer-size SIZE: Specify the buffer size (in bytes) for reading data. Default: 4096.
  • -f, –fields FIELDS: Specify a comma-separated list of fields to include in the output. Defaults to "fstype,mountpoint". Available fields:
    • fstype: Filesystem type (e.g., ext4, xfs)
    • mountpoint: Mount point for the filesystem
    • size: Total size of the filesystem (in bytes)
    • used: Used space on the filesystem (in bytes)
    • avail: Available space on the filesystem (in bytes)
    • percent: Percentage of used space
    • blocksize: Filesystem block size (in bytes)
    • iused: Number of used inodes
    • ifree: Number of free inodes

Examples

Get filesystem specification for a file

getfsspec /home/user/file.txt

Get filesystem specification for multiple files

getfsspec /home/user/file1.txt /etc/passwd /var/log/messages

Get filesystem specification for a device

getfsspec /dev/sda

Get specific filesystem fields

getfsspec -f fstype,mountpoint /home/user/file.txt

Common Issues

  • "No filesystem found" error: Ensure that the specified file or device is valid and exists.
  • Incorrect filesystem type or mountpoint: Verify that the file or device is correctly mounted.

Integration

getfsspec can be combined with other tools for advanced tasks:

  • df: Display disk usage information with df | getfsspec -f fstype,mountpoint to show the filesystem type for each mounted partition.
  • df -h: Get a human-readable summary of disk usage with df -h | getfsspec -f mountpoint.
  • du: Display disk usage for a directory or file with du -s /path/to/directory | getfsspec -f fstype.

Related Commands

  • df
  • mount
  • fstype
  • e2fsprogs