FreeBSD: How To See How Much Disk Space You're Using
Written by: Donovan / Last updated: Aug 23, 2023Need to know how much free disk space you have?
FreeBSD has several utilities to check disk space and partition usage.
In this guide, I’ll run through some of the most commonly used tools to achieve this.
Different methods for checking your free disk space on FreeBSD
df - Disk Filesystem
df is a Unix command used to display the amount of disk space used and available on filesystems.
Usage:
df [-h] [-t type]Options:
-h: Display sizes in a “human-readable” format, e.g., 1K, 234M, 2G.-t type: Display only filesystems of a specified type.
Steps:
- Open a terminal.
- Type
dfto view all mounted filesystems. - For a more readable output, use
df -h.
Example:
$ df -hdu - Disk Usage
du provides disk usage statistics for specific directories or files.
Usage:
du [-h] [-d depth] [directory_or_file]Options:
-h: Display sizes in a “human-readable” format.-d depth: Display only up to a specified directory depth.
Steps:
- Open a terminal.
- Navigate to a directory you wish to check, or stay in the home directory.
- Type
duto view disk usage statistics for the current directory. - For more readable output, use
du -h. - To see disk usage of a specific directory depth, use the
-doption.
Example:
$ du -h -d 1 /usrNOTE: There’s an ncurses program called ncdu that I personally use, which is a graphical representation of the du command. It’ll show you which directories are hogging space, and you can directly delete them as well.
sysctl
sysctl can be used to query system data, including disk data.
Usage:
sysctl hw.disksSteps:
- Open a terminal.
- Type
sysctl hw.disksto list available disks. - Use
dfordufor detailed usage stats for the listed disks.
Example:
$ sysctl hw.disksgeom - Disk Geometry
geom is a modular framework that provides block I/O services. We can use the geom class to display disk status.
Usage:
geom disk statusSteps:
- Open a terminal.
- Type
geom disk statusto display the disk status, including name, state, and more.
Example:
$ geom disk statuszfs list - ZFS Dataset Listing
zfs list displays the properties of ZFS datasets. It’s one of the primary methods for checking space usage in ZFS file systems.
Usage:
zfs list [-H] [-o property[,property2,...]] [dataset_name]Options:
-H: Display without headers and in tab-delimited format. Useful for scripting.-o property[,property2,...]: Display only the specified properties. Common properties includename,used,available,referenced, andmountpoint.
Steps:
- Open a terminal.
- Type
zfs listto view all ZFS datasets and their disk usage. - If you want to see specific properties, use the
-ooption.
Example:
$ zfs listTo see only the name, used space, and available space:
$ zfs list -o name,used,availablezpool list - ZFS Pool Listing
This command displays the storage capacity of the ZFS storage pools (zpools).
Usage:
zpool listSteps:
- Open a terminal.
- Type
zpool listto see the size, used space, free space, and other details of all available zpools.
Example:
$ zpool listDepending on your use case, you might want to automate the checking or set up alerts if the space usage exceeds a certain threshold.
If you’re using a desktop environment like Gnome or KDE, you’ll find gui tools that give you a graphical representation of free disk space as well. For window managers like DWM or Awesome , you’ll need to write a script using one of the commands above to output a string to your bar of choice.
View Archive