# LXC CLI Cheatsheet

## Container Management
- _Usage:_ Useful for day-to-day container management tasks like checking container status, executing commands inside containers, and getting detailed information.
- `lxc list -c n,s,4,image.description:image`  
  _Description:_ Lists containers with specific columns like name, state, IPv4 address, and image description.
- `lxc info <container-name>`  
  _Description:_ Displays detailed information about a specific container.  
  _Example:_ `lxc info mycontainer`
- `lxc exec <container-name> -- <command>`  
  _Description:_ Executes a command inside the specified container.  
  _Example:_ `lxc exec mycontainer -- bash`

## Image Management
- _Usage:_ Important for understanding what images are available and for selecting the right image for container deployment.
- `lxc image list`  
  _Description:_ Lists all available images.
- `lxc image alias list <repository>: <tag>`  
  _Description:_ Lists all aliases for an image in a repository.  
  _Example:_ `lxc image alias list ubuntu: '20.04'`

## Networking
- _Usage:_ Essential for setting up and troubleshooting container networking, ensuring containers can communicate with each other and the outside world.
- `lxc network list`  
  _Description:_ Lists all networks.
- `lxc network show <network-name>`  
  _Description:_ Shows detailed information about a specific network.  
  _Example:_ `lxc network show lxdbr0`

## Advanced Container Operations
- _Usage:_ Advanced features that allow for more complex container management, like cloning containers, and managing container states and backups.
- `lxc launch <image-name>`  
  _Description:_ Launches a new container from the specified image.  
  _Examples:_ `lxc launch ubuntu:20.04`, `lxc launch images:alpine/3.13`
- `lxc copy <source-container> <destination-container>`  
  _Description:_ Copies a container to a new container.
- `lxc snapshot <container-name>`  
  _Description:_ Creates a snapshot of a container.
- `lxc restore <container-name> <snapshot-name>`  
  _Description:_ Restores a container from a specified snapshot.

## File Management
- _Usage:_ Useful for deploying configuration files or scripts inside containers.
- `lxc file push <source-path> <container-name>/<destination-path>`  
  _Description:_ Pushes a file from the host to the container.

## Troubleshooting and Help
- _Usage:_ Crucial for diagnosing and resolving issues with containers and processes.
- `lxc --help`  
  _Description:_ Displays help for LXC commands.
- `ps -ef | grep <process-name>`  
  _Description:_ Finds processes related to a specific name, useful for troubleshooting.  
  _Example:_ `ps -ef | grep dnsmasq`

> **Note:** Replace placeholders like `<container-name>`, `<network-name>`, and `<image-name>` with actual names when using the commands.
