
How to Use the `just` Command (with Examples)
The just command is a powerful utility that allows users to save and run project-specific commands efficiently using a simple file called justfile. It functions primarily as a command runner, concentrating on project-specific recipes, which are essentially commands or sets of commands tailored to your development needs. This allows for faster development processes, reduced human error, and greater consistency across different environments.
Run a Recipe Specified in the Justfile
Code:
just recipe
Motivation:
The primary motivation for using this example is to streamline repetitive tasks within a project. By defining recipes in a justfile, developers can execute complex or multi-step operations with a single command. This not only saves time but also ensures that tasks are executed in a consistent manner across different team members and environments.
Explanation:
just: The base command,just, is used to execute any of the recipes defined in thejustfile.recipe: This argument specifies the name of the recipe you wish to run. A “recipe” is essentially a pre-defined command or set of commands stored within thejustfile.
Example Output:
Running the specified commands...
Task completed successfully.
Initialize New Justfile in Project Root
Code:
just --init
Motivation:
Initiating a new justfile is often the first step in organizing and managing project-specific commands smoothly. This is beneficial when setting up a new project or when starting to adopt just as your command management tool. It facilitates creating a set foundational framework to work from and evolve.
Explanation:
just: The main command utility.--init: This flag is used to create an emptyjustfilein the project’s root directory. Creating an emptyjustfileserves as a blank canvas for users to script their commands and recipes.
Example Output:
Created an empty `justfile` in the current directory.
Edit Justfile in the Default Editor
Code:
just -e
Motivation:
Editing the justfile directly from the CLI using your default editor saves time and is efficient, especially when you need to modify or add new commands quickly. Instead of navigating through directories to manually open the file, this command simplifies the process.
Explanation:
just: The main command utility.-e: This flag is a shorthand that instructsjustto open thejustfilein your computer’s default text editor. This helps in making seamless alterations to existing recipes or adding new ones without leaving the command line interface.
Example Output:
Opening justfile in the default editor...
List Available Recipes in the Justfile
Code:
just -l
Motivation:
Listing all available recipes within the justfile provides a quick overview of the commands or tasks that have been predefined. This is particularly useful for large projects with numerous recipes, helping team members to know exactly the tasks they can run without going through the justfile manually.
Explanation:
just: The core command utility.-l: This flag means “list,” and it shows all the recipes defined within the currentjustfile.
Example Output:
Available recipes:
build
test
start-server
Print Justfile
Code:
just --dump
Motivation:
Printing the contents of the justfile allows developers to see all the configurations and logic penned into the justfile without opening a separate text editor. This can be used for code review purposes, sharing with others, or simply verifying what’s currently scripted.
Explanation:
just: The primary command utility.--dump: This argument tellsjustto output the content of thejustfiledirectly to the terminal.
Example Output:
# Contents of Justfile
recipe1:
echo "Executing Recipe 1"
recipe2:
echo "Executing Recipe 2"
Conclusion:
The just command provides an intuitive and efficient way to handle project-specific tasks by using a justfile. Whether you’re setting up a new project, managing existing commands, or reviewing recipes, just facilitates increased productivity and consistency among development teams. By leveraging its various functionalities, developers can focus more on building software rather than managing complex command sequences.


