Lxc list [containername] (only list one container, not [containername]*)

Hello Everyone,
how can I list only one container with lxc list if I have others with the same string in the beginning? I want to only show one specific container addresses by the exact name.

Example:
I dont want to list others that beginn with the same substring… If I have ‘wordpress’ and ‘wordpress-live’ and ‘wordpress-stage’ - how can I only list that one, with the name ‘wordpress’?

You can use regex to filter out other names, so to do what you want you could do lxc list wordpress$ and it would only display that container

ex without regex

$ lxc list u1
±---------±--------±----------------------±----------------------------------------------±----------±----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
±---------±--------±----------------------±----------------------------------------------±----------±----------+
| u1 | RUNNING | 10.141.245.237 (eth0) | | CONTAINER | 0 |
±---------±--------±----------------------±----------------------------------------------±----------±----------+
| u1-live | RUNNING | 10.141.245.174 (eth0) | | CONTAINER | 0 |
±---------±--------±----------------------±----------------------------------------------±----------±----------+
| u1-stage | RUNNING | 10.141.245.56 (eth0) | | CONTAINER | 0 |
±---------±--------±----------------------±----------------------------------------------±----------±----------+

With the regex

$ lxc list u1$
±-----±--------±----------------------±----------------------------------------------±----------±----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
±-----±--------±----------------------±----------------------------------------------±----------±----------+
| u1 | RUNNING | 10.141.245.237 (eth0) | | CONTAINER | 0 |
±-----±--------±----------------------±----------------------------------------------±----------±----------+

3 Likes

Oh. Great. Thank you @zac.fuller ! Nice community here.

For completeness and robust reusability in other environments, it is worth mentioning that to have exact and complete matching, you also need to mark the beginning ^ in the regexp as follows:

lxc list ^u1$

This should ensure only one instance name is returned as the OP requested. The original solution would still return *[containername].

1 Like