# libtmux.Server.cmd

- **Module:** libtmux
- **Package:** libtmux
- **Language:** Python
- **Kind:** method
- **Source:** https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/server.py#L337
- **Page:** https://libtmux.org/en/py/stable/reference/libtmux-server-cmd/

```
libtmux.Server.cmd(
    self,
    cmd: str,
    args: t.Any,
    target: str | int | None = None,
) -> tmux_cmd
```

Execute tmux command respective of socket name and file, return output.

## Examples

```python
>>> server.cmd('display-message', 'hi')
<libtmux.common.tmux_cmd object at ...>
```

New session:

```python
>>> server.cmd('new-session', '-d', '-P', '-F#{session_id}').stdout[0]
'$2'
```

```python
>>> session.cmd('new-window', '-P').stdout[0]
'libtmux...:2.0'
```

Output of `tmux -L ... new-window -P -F#{window_id}` to a `Window` object:

```python
>>> Window.from_window_id(window_id=session.cmd(
... 'new-window', '-P', '-F#{window_id}').stdout[0], server=session.server)
Window(@4 3:..., Session($1 libtmux_...))
```

Create a pane from a window:

```python
>>> window.cmd('split-window', '-P', '-F#{pane_id}').stdout[0]
'%5'
```

Output of `tmux -L ... split-window -P -F#{pane_id}` to a `Pane` object:

```python
>>> Pane.from_pane_id(pane_id=window.cmd(
... 'split-window', '-P', '-F#{pane_id}').stdout[0], server=window.server)
Pane(%... Window(@... ...:..., Session($1 libtmux_...)))
```

## Changed

0.8 — Renamed from ``.tmux`` to ``.cmd``.

## Parameters

- `cmd` (`str`)
- `args` (`t.Any`)
- `target` (`str | int | None`): Optional custom target.

## Returns

:class:`common.tmux_cmd`

## In other ports

### Run a tmux command this port does not model

- Ruby: [`LibTmux::Server#run`](/en/ruby/latest/reference/libtmux-server-run/) (method)
- Lua: [`libtmux.Server:command`](/en/lua/latest/reference/libtmux-server-command/) (method)
- TypeScript: [`server.Server.cmd`](/en/ts/latest/reference/server-server-cmd/) (method)
- Rust: [`server.Server.cmd`](/en/rs/latest/reference/server-server-cmd/) (method)
- Go: [`tmux.Server.Cmd`](/en/go/latest/reference/tmux-server-cmd/) (method)
- Java: [`io.github.libtmux.Server.Server.cmd`](/en/java/latest/reference/io-github-libtmux-server-server-cmd/) (method)
