How can I delete a Linode by name using the Linode CLI?
Linode
Linode Staff
Is it possible to delete a Linode by its name, and not by its numerical id, using linode-cli
?
1 Reply
tommydavidson
Linode Staff
Not directly, but you can write a script that accomplishes the same. The script I use to delete a Linode by name rather than ID number looks like this:
#!/usr/bin/env bash
linode-cli linodes delete $(linode-cli linodes list --text | grep "\b${1}\b" | awk '{print $1}')
The logic could be simplified by replacing the grep
command with further awk
logic, but this is the quick and dirty way I came up with. I used \b
with grep to enforce word boundaries, so that the command does not accidentally delete any other similarly-named Linodes. You can save the script as anything you'd like - for example, rmlinode.sh
, and call it like this:
./rmlinode.sh $LINODE_TO_DELETE
Just be sure to replace $LINODE_TO_DELETE
with the name of the Linode you're deleting.