Skip to content

Instantly share code, notes, and snippets.

@davydany
Created May 23, 2017 20:09
Show Gist options
  • Select an option

  • Save davydany/8f4dd4622aedfa9552e7db1a057274c8 to your computer and use it in GitHub Desktop.

Select an option

Save davydany/8f4dd4622aedfa9552e7db1a057274c8 to your computer and use it in GitHub Desktop.
Destroy all running VirtualBox VMs
# Runs perfectly on CentOS 7
# Read all pids for "VBoxHeadless" process, and kill (-9) them.
while read -r pid; do
echo "Killing VirtualBox Process '${pid}'..."
kill -9 ${pid}
echo " OK Done."
done < <(pgrep VBoxHeadless)
# Read all VirtualBox VMs, and unregister, then delete them
while read -r name; do
echo "Unregistering VM '$(echo $name |awk '{print$2}' |sed -e 's/.*{\([^}]\+\)}.*/\1/g')'..."
VBoxManage unregistervm "$(echo $name |awk '{print$2}' |sed -e 's/.*{\([^}]\+\)}.*/\1/g')" --delete &> /dev/null
done < <(VBoxManage list vms)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment