Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers

up vote 5 down vote accepted
$ 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.

share|improve this answer
Works exactly like that. Only it was /proc/acpi/ac_adapter/AC/state in my case. –  Bruce Connor Jun 10 '10 at 1:51
add comment
$ 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.

share|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. –  Bruce Connor Jun 10 '10 at 1:53
add comment

I use something similar to:

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

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

share|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. –  Bruce Connor Jun 10 '10 at 1:55
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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