Linux make Command with Examples
Last Updated :
05 Jun, 2024
The make command for Linux is a very useful utility in the automation of software development and performing tasks in a Linux environment. It simply reads a special file, which is called a Makefile and this file describes how one's program is compiled and linked with another file or another program action. This includes information on what files depend on each other and the particular commands needed to build the project.
What is the make Command?
Make is a command line tools that help developers to save time and it enables developers to automate some of the more boring and time-consuming tasks associated with the build process and ensures that only the parts of the project that have actually changed are recompiled. Not only does this save a lot of time, but it also reduces the potential for any kind of error. Make is an ideal utility to handle large projects composed of multiple components and keeps their build process efficient and consistent.
In current development practice, make is often integrated into Continuous Integration and Continuous Deployment pipelines to ensure that changes are automatically built, tested, and deployed to maintain the reliability and quality of the software. It is perfect for handling large projects with a lot of components because it ensures an efficient and consistent build process. More than just a tool for making programs, make is an integral part of any software development workflow in a Unix-like environment.
Common Make Command Examples
make commands can be use with various options for performing various tasks related to Software development and running tasks automatically.
Following is the table of some important options with the make command.
Command | Description |
---|
make
| It runs the default target in a Linux-unix environment and usually, the first target is the Makefile
|
make all
| This command runs the all targets, which can typically compile the entire project for performing tasks.
|
make clean
| It runs the clean target, which removes compiled files and also it cleans up the build directory.
|
make -f gfg
| This command uses the custom file for making an operation. here we are using our gfg custom file for making operations.
|
make -jN
| This command runs the build with N parallel jobs and it is used for speeding up the build process on multi-core systems.
|
make -k
| This command tells the system to keep going as much as possible after an error occurs.
|
make -B
| this command forces make to consider all targets without any condition.
|
make --version
| It displays the version of make.
|
make --help
| This command displays helpful information about making commands and available options.
|
How to Use make Command
For understanding in better way lets see the use of make command with example. Here we are using Kali Linux , you can use any Linux based operating system for executing the command or performing your task.
Step 1: Open your linux terminal , it will look like this.

Step 2: Now first we are creating a python file as named as name.py and writing the below program. you can write whatever you want in your output.
print("GeeksforGeeks: A Learning Platform")

Step 3: Now again we are creating one another file named as ten.py which prints first ten natural numbers.
for i in range(1,11):
print(i)

After saving these both files name.py and ten.py , now we will create a Makefile for understand the behaviour and working of make command . the make command in linux by default execute Makefile , that is why here we are creating it as Makefile. If you create it with another name then you have to write the option of file '-f' followed by file name when you are executing make file.
Step 4: In the below command first we are writing the the target followed by colon ':' and dependencies and commands. following is syntax of make command , we have to write in the given syntax.
all: name ten
name:
python name.py
ten:
python ten.py

Step 5: Now after writing the make file and saving it we can execute our created make file . Here for executing the both python files we only need to write make command and we can see our both file executed successfully. This process can save our time when we are working on large project

Step 6: We can also execute our make file using our created target. As we have created our target in Makefile named as all , which fires another two targets name and ten for executing the python files .Now we can execute this target using following command.

Step 7: We can also execute our targets separately. Following is command for executing our created name target and we can see our command executed successfully and it is giving our desired result.

Using the above way we can create as many as our commands and targets for automating the process and we can also save our time using various options which are available in make commands.
Conclusion
In our conclusion what we have did we can say make commands are a must-have tool during the development of software because they provide a well-organized and efficient way to handle the process of building anything. These will help in automating the linking and compilation steps of the program, ensuring that dependencies are handled correctly, and only those files are recompiled which are in need. This not only saves our time but also saves our errors by maintaining consistency across builds process. Make commands are highly configurable which are allowing developers to define complex build rules and workflows for performing there project tasks. Finally we can say make command make much easier to develop software and automate task and saves our time during complex project task.
Similar Reads
more command in Linux with Examples
The 'more' command in Linux is a useful tool for viewing text files in the command prompt, particularly when dealing with large files like log files. It displays the content one screen at a time, allowing users to scroll through the text easily. This command is especially handy for reviewing long ou
4 min read
time command in Linux with examples
'time' command in Linux is used to execute a command and prints a summary of real-time, user CPU time and system CPU time spent by executing a command when it terminates. 'real' time is the time elapsed wall clock time taken by a command to get executed, while 'user' and 'sys' time are the number of
6 min read
mapfile Command in Linux With Examples
The 'mapfile' command, also known as 'readarray', is a powerful built-in feature of the Bash shell used for reading input lines into an array variable. Unlike using a loop with read, mapfile reads lines directly from standard input or command substitution (< <(command)) rather than from a pipe
2 min read
uname command in Linux with Examples
Linux, renowned for its open-source flexibility and powerful performance, offers a range of commands that reveal the inner workings of your system. Among these, the 'uname' command stands out as a versatile tool that provides key details about your Linux machine. Here, we will learn the basics of th
4 min read
mailq Command in Linux with Examples
mailq i.e. "mail-queue", this command in Linux prints the mail queue i.e. the list of messages that are there in the mail queue. You should have a mail-server setup on your Linux machine, to use this command, there are ways i.e MTA's(Mail Transfer agent) you can use like sendmail which uses the serv
3 min read
rev command in Linux with Examples
rev command in Linux is used to reverse the lines characterwise. This utility reverses the order of the characters in each line by copying the specified files to the standard output. If no files are specified, then the standard input will be read. Here, we will explore the syntax, examples, and opti
3 min read
seq command in Linux with Examples
The 'seq' command in Linux is a powerful utility used to generate a sequence of numbers. It is particularly useful in scenarios where you need to create a list of numbers within loops, such as while, for, or until loops. With 'seq', you can quickly generate numbers from a starting value (FIRST) to a
4 min read
type command in Linux with Examples
The type command in Linux is a useful utility for identifying how the shell will interpret a given command. It provides information on whether a command is a shell built-in, external binary, function, or alias, helping users understand the source of the command and its behavior. The command is parti
3 min read
read command in Linux with Examples
read command in the Linux system is used to read from a file descriptor. This command reads up the total number of bytes from the specified file descriptor into the buffer. If the number or count is zero, this command may detect errors. But on success, it returns the number of bytes read. Zero indic
3 min read
ncal Command in Linux with Examples
ncal is a command-line tool to view a calendar on the terminal in Linux. It is similar to the cal command in Linux. The major difference between both the commands is the output they display. It shows the current month calendar of the current year with the date highlighted. But with command options,
2 min read