In Bashes/Shells it is usually pretty easy to perform commands in one folder but have it apply to another folder. For example, with ls
you can do ls -l /some/folder
or ls /some/folder -l
, and both list all files/directories in the /some/folder
directory as well as permissions, owners, etc.
Is there any way to do this with the command-line VM managing program Vagrant? When I tried, from the C: directory (/c
) with Git Bash (msysgit), vagrant init some/vagrant/folder
, the created files & folders still got put in the folder I was in, /c
, instead of the folder I specified, /c/some/vagrant/folder
, and when I did vagrant some/vagrant/folder init
, it threw an error.
Is there any way to have vagrant
commands apply to a folder you're not in, or do I just have to cd
every time I want to initialize a VM?
The documentation says that vagrant init
intializes the current directory. So vagrant itself won't allow what you want. However, bash can help:
(cd some/vagrant/folder; vagrant init)
What this does is start a subshell in which you first immediately change directory and then issue the vagrant init
command. Running it in a subshell prevents the cd
from messing up the current working directory of your interactive session.