Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have multiple inactive domains in libvirt and I want to delete them all:

# virsh list --inactive
 Id Name                 State
  - instance-0000000c    shut off
  - instance-0000000f    shut off
  - instance-00000010    shut off

Is there a simple way to tell libvirt to delete all inactive domains, or do I have to manually do:

# virsh undefine instance-0000000c
# virsh undefine ...
share|improve this question
up vote 1 down vote accepted

Something like this should work:

$ virsh list --inactive | grep instance | cut -d " " -f 4 | xargs -n 1 virsh undefine

If you want to review that list before killing them:

$ virsh list --inactive | grep instance | cut -d " " -f 4 > inactive_domains
$ vi inactive_domains

Then if everything looks good:

$ cat inactive_domains | xargs -n 1 virsh undefine
share|improve this answer
I don't think you can pass multiple arguments to virsh undefine. – Lorin Hochstein Feb 24 '12 at 19:54
@LorinHochstein - fixed. – EEAA Feb 24 '12 at 20:42

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.