`multipass exec` command

See also: multipass exec and shells, How to use instance command aliases

The multipass exec command executes the given commands inside the instance. The first argument is the instance to run the commands on, -- optionally separates the multipass options from the rest - the command to run itself:

$ multipass exec primary -- uname -r
4.15.0-48-generic

You can pipe standard input and output to/from the command:

$ multipass exec primary -- lsb_release -a | grep ^Codename:
No LSB modules are available.
Codename:       bionic

The -- separator is required if you want to pass options to the command being run. Options to the exec command itself must be specified before --.

[since 1.10.0]

Since Multipass version 1.10.0, it is possible to specify on which instance directory the command must be executed. For that, there are three options. The first one is --working-directory <dir>, which tells Multipass that the command must be executed in the folder <dir>. For example,

$ multipass exec arriving-pipefish --working-directory /home -- ls -a
.  ..  ubuntu

The ls -la command showed the contents of the /home directory, because it was executed from there.

The second option to specify the working directory is to look through the mounted folders first. In case we are executing the alias on the host from a directory which is mounted on the instance, the command will be executed on the instance from there. If the working directory is not mounted on the instance, the command will be executed on the default directory on the instance. This is the default behaviour in versions 1.10.0 and higher, and no parameter must be specified for this mapping to happen.

The third option is to directly execute the command in the default directory in the instance (usually, it is /home/ubuntu. The parameter to force this behaviour is --no-map-working-directory. It must be noted that this is the default in versions before 1.10.0.


Last updated 1 year, 2 months ago.