Skip to main content

Gather essential disk and partition info for block devices and print it in a nice table

Project description

statblk

Gather disk and partition information for block devices and print it as a table or JSON.

Supports Linux and macOS.

Install

From PyPI:

pip install statblk

From a clone of this repository:

pip install .

Optional shell tab completion:

pip install 'statblk[completion]'

Requires Python 3.6+ and the multiCMD package (>= 1.47).

Quick start

statblk
statblk -j                    # JSON output
statblk -o NAME,SIZE,MOUNTPOINT
statblk sda nvme              # filter rows matching sda or nvme
statblk 2                     # refresh every 2 seconds (watch mode)

Output columns

By default all columns are shown:

Column Description
NAME Block device name
FSTYPE Filesystem type
SIZE Device or filesystem size
FSUSE% Filesystem space used (mounted entries)
MOUNTPOINT Mount path
SMART SMART health (OK, DENIED, etc.)
LABEL Volume label
UUID Filesystem UUID
MODEL Drive model
SERIAL Drive serial
DISCARD TRIM / discard support
READ Current read throughput
WRITE Current write throughput

Use -o / --output to select columns (comma-separated) or -x / --exclude to omit columns.

Options

Output format

Flag Description
-j, --json Print JSON instead of a table
-b, --bytes Print sizes and throughput as raw byte counts
-H, --si Use powers of 1000 (SI) instead of 1024 for sizes
-R, --full Do not truncate long values to terminal width
-o, --output Columns to include (default: all)
-x, --exclude Columns to omit

Filtering

Flag Description
filter_patterns … Show rows matching any pattern (regex)
-D, --match_devname_only Apply patterns to device names only
-v, --invert_match Invert pattern match
-F, -fo, --formated_only Only entries with a filesystem type
-M, -mo, --mounted_only Only mounted devices
-B, -bo, --best_only Shortest mount point per device
-A, -ao, --active_only Only devices with read/write activity
-P, --pseudo Include pseudo filesystems (tmpfs, nfs, cifs, …)
--show_zero_size_devices Include zero-size devices

Runtime

Flag Description
-t, --timeout Subprocess timeout in seconds (default: 2)
--sudo Run external commands via sudo (needed for SMART on many systems)
--debug Print suppressed exceptions to stderr
-V, --version Show version and exit

Watch mode

Pass a refresh interval as the last positional argument (seconds):

statblk 5          # update every 5 seconds
statblk sda 3      # filter to sda, refresh every 3 seconds

After the first refresh, --active_only is enabled automatically so only busy devices are shown.

If a filter pattern looks like a number, append 0 so it is not treated as the refresh interval:

statblk nvme0 0    # match nvme0, single run (no watch)

Platform notes

Linux

Uses sysfs, /proc/self/mountinfo, lsblk, and optionally smartctl.

  • SMART requires smartctl (smartmontools). Use --sudo if permission is denied.
  • READ / WRITE throughput comes from /sys/class/block/*/stat.

macOS

Uses diskutil and mount. Throughput columns are always zero (no per-device sysfs stats).

Development

Run embedded doctests:

python -m doctest statblk.py -v
python statblk.py --doctest

License

GPLv3+ — Yufei Pan (pan@zopyr.us)

Project home: github.com/yufei-pan/statblk

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

statblk-1.41.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

statblk-1.41-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file statblk-1.41.tar.gz.

File metadata

  • Download URL: statblk-1.41.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for statblk-1.41.tar.gz
Algorithm Hash digest
SHA256 5db1698f7c70e388cae1be2c1d986025e4dd5337855241befaa81e746b8416ac
MD5 e88d3b41dc19b552451da734d11e3002
BLAKE2b-256 d7f59390484cc7c76f21c89f4c01a3b35f2ff49585809db847f924233543feb7

See more details on using hashes here.

File details

Details for the file statblk-1.41-py3-none-any.whl.

File metadata

  • Download URL: statblk-1.41-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for statblk-1.41-py3-none-any.whl
Algorithm Hash digest
SHA256 7a33038ba31fdf5742f11448b1e5714e027b49af8177405ddb0004fc1832323c
MD5 833dcdc49a05e121934b9166f50c8582
BLAKE2b-256 8964d9753dd46e4baf406a2fc505767eb01c51c465dae775603d674a406037b6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page