LinuxCommandLibrary

lxc-ls

List existing LXC containers

TLDR

List all containers

$ sudo lxc-ls
copy

List active containers (including frozen and running)
$ sudo lxc-ls --active
copy

List only frozen containers
$ sudo lxc-ls --frozen
copy

List only stopped containers
$ sudo lxc-ls --stopped
copy

List containers in a fancy, column-based output
$ sudo lxc-ls [[-f|--fancy]]
copy

Display help
$ lxc-ls [[-?|--help]]
copy

SYNOPSIS

lxc-ls [OPTIONS]

PARAMETERS

-f
    Show detailed information for each container, including their current state, IP addresses (if any), and PID (if running).

-1
    Output one container name per line.

-h
    Display help message.

-v
    Show version.

DESCRIPTION

The `lxc-ls` command is a fundamental tool for managing LXC (Linux Containers). It provides a simple and effective way to list all defined LXC containers on a system, along with their current state. This state includes information such as whether the container is running, stopped, frozen, or defined but not yet created.

Without any options, `lxc-ls` simply displays a newline-separated list of container names to standard output. The command is usually the starting point for any LXC administration task, as it allows the user to quickly identify the containers they want to manage. For example, before stopping or starting a container, one would typically use `lxc-ls` to ensure the container's name is correct. It provides a quick and easy way to get an overview of your container environment, making it easier to start, stop, or otherwise interact with your containers effectively and efficiently. In larger environments with many containers, the `lxc-ls` helps maintain awareness and organization.

It does not require root privileges to simply list the names, but may do so to retrieve container information which is otherwise unavailable to a non-privileged user.

CAVEATS

The output of `lxc-ls` might not be consistent if containers are being created or destroyed while the command is running. It reflects the LXC configuration at the time of execution.

EXIT STATUS

The command returns 0 on success and a non-zero value on failure.

OUTPUT FORMAT

When used without `-f`, output is a simple list of container names separated by spaces. When `-f` is used the format is defined by `lxc-info`.

HISTORY

The `lxc-ls` command has been a core component of the LXC toolset since its initial development. It's a basic command but has been consistently maintained and updated along with the LXC project's evolution to ensure compatibility with new features and kernel versions.

SEE ALSO

Copied to clipboard