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
df
to view all mounted filesystems. - For a more readable output, use
df -h
.
Example:
$ df -h
du - 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
du
to 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
-d
option.
Example:
$ du -h -d 1 /usr
NOTE: 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.disks
Steps:
- Open a terminal.
- Type
sysctl hw.disks
to list available disks. - Use
df
ordu
for detailed usage stats for the listed disks.
Example:
$ sysctl hw.disks
geom - 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 status
Steps:
- Open a terminal.
- Type
geom disk status
to display the disk status, including name, state, and more.
Example:
$ geom disk status
zfs 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 list
to view all ZFS datasets and their disk usage. - If you want to see specific properties, use the
-o
option.
Example:
$ zfs list
To see only the name, used space, and available space:
$ zfs list -o name,used,available
zpool list - ZFS Pool Listing
This command displays the storage capacity of the ZFS storage pools (zpools).
Usage:
zpool list
Steps:
- Open a terminal.
- Type
zpool list
to see the size, used space, free space, and other details of all available zpools.
Example:
$ zpool list
Depending 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