Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Unix, can I run 'make' in a directory without cd'ing to that directory first?

In Unix, can I run make in a directory without cd'ing to that directory first?

like image 986
user46795 Avatar asked Oct 21 '22 07:10

user46795


People also ask

How do I run a Makefile in a different directory?

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.

How can I change directory without cd?

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.

How do you go to a specific directory in Unix?

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.


2 Answers

make -C /path/to/dir

like image 384
bmotmans Avatar answered Oct 23 '22 21:10

bmotmans


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.

like image 105
Dave C Avatar answered Oct 23 '22 21:10

Dave C