LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

systemd-ac-power

Check AC power connection status

TLDR

Check AC power status
$ systemd-ac-power
copy
Check with verbose output
$ systemd-ac-power -v
copy

SYNOPSIS

systemd-ac-power [OPTIONS]

DESCRIPTION

systemd-ac-power reports whether the computer is connected to an external power source (AC mains). It returns exit code 0 when on AC power and non-zero when on battery.This is useful in scripts and systemd unit conditions to change behavior based on power state.

PARAMETERS

-v, --verbose

Print "yes" or "no" to stdout in addition to exit code
-h, --help
Display help

EXIT STATUS

0 - Running on AC powernon-zero - Running on battery or unable to determine

INSTALL

sudo apt install systemd
copy
sudo dnf install systemd
copy
sudo pacman -S systemd
copy
sudo zypper install systemd
copy
brew install systemd
copy
nix profile install nixpkgs#systemd
copy

CAVEATS

Requires proper power supply detection by the kernel. Some desktop systems without batteries always report AC power. Virtual machines may report power state incorrectly.

HISTORY

systemd-ac-power provides a simple, scriptable interface to power supply status, enabling power-aware behavior in systemd units and shell scripts.

SEE ALSO

systemctl(1), upower(1)

Copied to clipboard
Kai