In Unix, can I run make
in a directory without cd
'ing to that directory first?
Use cd ./dir && make && pwd inside Makefile . The && was exactly what I needed to change a directory and execute a command there, then drop back to the main folder to finish the build.
Let us say you wanted to go to the directory Downloads. You don't need to type "cd Downloads" every time to go that directory. Instead, just type "Downloads" in the Terminal.
To navigate to your home directory, use "cd" or "cd ~" To navigate up one directory level, use "cd .." To navigate to the previous directory (or back), use "cd -" To navigate through multiple levels of directory at once, specify the full directory path that you want to go to.
make -C /path/to/dir
As noted in other answers, make(1) has a -C
option for this; several commands have similar options (e.g. tar). It is useful to note that for other commands which lack such options the following can be used:
(cd /dir/path && command-to-run)
This runs the command in a sub-shell which first has its working directory changed (while leaving the working directory of the parent shell alone). Here &&
is used instead of ;
to catch error cases where the directory can not be changed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With