freecon - Linux


Overview

freecon is a command-line tool used to manage and query free space on Linux systems. It provides detailed information about all mounted file systems, including their usage, available space, inodes, and mount points.

Syntax

freecon [options]

Options/Flags

  • -a, –all: Show all file systems, including those that are not mounted.
  • -i, –inodes: Display inode usage information instead of space usage.
  • -m, –megabytes: Display space usage in megabytes instead of kilobytes.
  • -g, –gigabytes: Display space usage in gigabytes instead of kilobytes.
  • -h, –human-readable: Display space usage in human-readable format (e.g., 123MB).
  • -n, –no-header: Suppress the header row in the output.
  • -s, –sort-by-size: Sort the output by file system size.
  • -S, –sort-by-name: Sort the output by file system name.
  • -p, –percentage: Display space usage as a percentage.
  • -c, –color: Colorize the output for better readability.
  • -f, –filesystem: Filter the output to only include specific file systems.
  • -v, –version: Display version information and exit.
  • -h, –help: Display help information and exit.

Examples

  • Display free space information for all mounted file systems:
freecon
  • Display inode usage information:
freecon -i
  • Display space usage in gigabytes:
freecon -g
  • Show only the largest file system:
freecon -s | tail -n 1
  • Search for a specific file system:
freecon -f /var

Common Issues

  • Output is too cluttered: Use the -n option to suppress the header row.
  • Space usage is incorrect: Ensure the file systems are correctly mounted and accessible.
  • Permission denied: Run the command with root privileges using sudo.

Integration

  • Combine with df to get more detailed information:
df -h | freecon -h
  • Use in scripts to monitor disk space:
#!/bin/bash

# Check if disk space is below a certain threshold
if freecon | grep -q 90%; then
  echo "Warning: Disk space is low!"
  notify-send "Disk Space Warning"
fi

Related Commands

  • df: Display free disk space.
  • du: Estimate file space usage.
  • ps: Show running processes.