I'm running ubuntu on my notebook and I need a way to check (from the command line) if the power cable is connected. Is there any system file that keeps log of this? or is there a bash command that will help me?

I need this for a script that will behave differently depending on whether the power cord is plugged in or not.

$ cat /proc/acpi/ac_adapter/ACAD/state
state:                   on-line

or somthing similar depending on your architecture. There are many exports of machine state hiding in the /proc psuedo-directory.

| improve this answer | |
  • Works exactly like that. Only it was /proc/acpi/ac_adapter/AC/state in my case. – Malabarba Jun 10 '10 at 1:51
$ cat /sys/class/power_supply/ADP1/online 
 [pull power]
$ cat /sys/class/power_supply/ADP1/online 

The value to put in place of ADP1 may vary.

| improve this answer | |
  • Works exactly like that as well, only with "/sys/class/power_supply/AC/online" for me. I marked the other answer as accepted 'cause it was first, but both worked equally well. – Malabarba Jun 10 '10 at 1:53
  • I only have a BAT0 directory in /sys/class/power_supply. Any idea why? – user1575682 May 2 '19 at 0:21

I use something similar to:

acpi -a | grep AC | cut -d: -f2

in order to display the battery status on the wmii status bar.

| improve this answer | |
  • This one didn't work with me because the acpi command wasn't installed. I didn't install it because the other methods were more practical, but it probably works fine as well. – Malabarba Jun 10 '10 at 1:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.