This Minecraft tutorial explains how to use the /execute command with screenshots and step-by-step instructions.

The /execute command is one of most complex commands in Minecraft. In most cases, you will chain multiple /execute commands together making the command a bit more difficult to understand. Let’s explore how to use this cheat (game command).

Requirements

To run game commands in Minecraft, you have to turn cheats on in your world.

Execute Command

Execute Command in Minecraft Java Edition (PC/Mac)

In Minecraft Java Edition (PC/Mac) 1.14, 1.15, 1.16, 1.17, 1.18, 1.19 and 1.20, there are different syntaxes for the /execute command.

To align the block grid based on the specified axes and then run a second /execute command based on the aligned position:

/execute align <axes> <secondExecuteCommand>

To anchor the local coordinate origin to either the eyes or the feet of the entity running the command and then run a second /execute command:

/execute anchored <eyes¦feet> <secondExecuteCommand>

To run a second /execute command on behalf of an entity:

/execute as <targets> <secondExecuteCommand>

To run a second /execute command using the position, dimension (ie: Overworld, Nether, End) and rotation of the target entity (without changing the entity that is running the command):

/execute at <targets> <secondExecuteCommand>

To run a second /execute command that uses an execution point that faces the target entity’s eyes or feet:

/execute facing entity <targets> <eyes¦feet> <secondExecuteCommand>

To run a second /execute command that uses an execution point that faces a specific coordinate:

/execute facing <pos> <secondExecuteCommand>

To run a second /execute command if a block at specified coordinate matches the given Minecraft ID name:

/execute if block <pos> <blockID> <secondExecuteCommand>

To run a second /execute command if the blocks in the region from <start> to <end> matches the <destination>:

/execute if blocks <start> <end> <destination> <all¦masked> <secondExecuteCommand>

To run a second /execute command if a block at a specific coordinate has data for the NBT tag specified by <path>:

/execute if data block <pos> <path> <secondExecuteCommand>

To run a second /execute command if a targeted entity has data for the NBT tag specified by <path>:

/execute if data entity <target> <path> <secondExecuteCommand>

To run a second /execute command if a targeted entity exists:

/execute if entity <targets> <secondExecuteCommand>

To run a second /execute command if a targeted entity has a score (for a targeted objective) that matches a range:

/execute if score <target> <targetObjective> matches <range> <secondExecuteCommand>

To run a second /execute command if a targeted entity has a score (for a targeted objective) that meets a criteria when comparing to a source objective. The comparison of the two objectives can be based on: less than (<), less than equals (<=), equals (=), greater than (>), or greater than equals (>=):

/execute if score <target> <targetObjective> (<¦<=¦=¦>¦>=) <source> <sourceObjective> <secondExecuteCommand>

To run a second /execute command as if the entity running the command is in the specified dimension:

/execute in <minecraft:overworld¦minecraft:the_end¦minecraft:the_nether> <secondExecuteCommand>

To run a second /execute command using the target’s position as the current position:

/execute positioned as <targets> <secondExecuteCommand>

To run a second /execute command using a specified coordinate as the current position:

/execute positioned <pos> <secondExecuteCommand>

To run a second /execute command using the rotation of the target:

/execute rotated as <targets> <secondExecuteCommand>

To run any game command (such as /give, /summon, /particle commands):

/execute run <gameCommand>

To store the result/success of a second /execute command in a block at a specified coordinate:

/execute store <result¦success> block <pos> <path> <byte¦double¦float¦int¦long¦short> <scale> <secondExecuteCommand>

To store the result/success of a second /execute command in a bossbar:

/execute store <result¦success> bossbar <id> <max¦value> <secondExecuteCommand>

To store the result/success of a second /execute command in a target entity’s NBT tag as specified by <path>:

/execute store <result¦success> entity <target> <path> <byte¦double¦float¦int¦long¦short> <scale> <secondExecuteCommand>

To store the result/success of a second /execute command in the score of a target entity’s objective:

/execute store <result¦success> score <target> <objective> <secondExecuteCommand>

To store the result/success of a second /execute command in the score of a target entity’s objective:

/execute store <result¦success> score <target> <objective> <secondExecuteCommand>

To run a second /execute command unless a block at specified coordinate matches the given Minecraft ID name:

/execute unless block <pos> <blockID> <secondExecuteCommand>

To run a second /execute command unless the blocks in the region from <start> to <end> matches the <destination>:

/execute unless blocks <start> <end> <destination> <all¦masked> <secondExecuteCommand>

To run a second /execute command unless a block at a specific coordinate has data for the NBT tag specified by <path>:

/execute unless data block <pos> <path> <secondExecuteCommand>

To run a second /execute command unless a targeted entity has data for the NBT tag specified by <path>:

/execute unless data entity <target> <path> <secondExecuteCommand>

To run a second /execute command unless a targeted entity exists:

/execute unless entity <targets> <secondExecuteCommand>

To run a second /execute command unless a targeted entity has a score (for a targeted objective) that matches a range:

/execute unless score <target> <targetObjective> matches <range> <secondExecuteCommand>

To run a second /execute command unless a targeted entity has a score (for a targeted objective) that meets a criteria when comparing to a source objective. The comparison of the two objectives can be based on: less than (<), less than equals (<=), equals (=), greater than (>), or greater than equals (>=):

/execute unless score <target> <targetObjective> (<¦<=¦=¦>¦>=) <source> <sourceObjective> <secondExecuteCommand>

 

In Minecraft Java Edition (PC/Mac) 1.11 and 1.12, there are 2 syntaxes for the /execute command.

To execute a command on behalf of an entity:

/execute <entity> <x> <y> <z> <command>

To execute a command on behalf of the entity, only if a specific block is detected at <x1> <y1> <z1>:

/execute <entity> <x> <y> <z> detect <x1> <y1> <z1> <block> <data> <command>

Definitions

  • secondExecuteCommand is an /execute command that is chained onto the current command without specifying the /execute keyword.
  • axes are the axes to align. It can be any combination of xyz such as x, y, z, xz, xy, yz, xyz.
  • target or targets is the name of the player (or a target selector).
  • entity is the name of a player (or a target selector) who will run the command.
  • x y z is the position to run the command. If a relative value (~) is provided, then the position is relative to the entity.
  • x1 y1 z1 is the position to detect the block.
  • block is name of the block to detect at position x1 y1 z1. If detected, then the command will be executed. (See Minecraft Item Names)
  • data is the data value of the block to detect at position x1 y1 z1. If detected, then the command will be executed. (See Minecraft Data Values)
  • command or gameCommand is any Minecraft command that you want the entity to execute such as summon, give, fill, clone, setblock, tp, xp, kill, etc.

TIP: Read our tutorial called Understanding the Coordinate System to learn about the XYZ coordinates in Minecraft and how to find your current coordinates.

Examples

Example in Java Edition (PC/Mac) 1.14, 1.15, 1.16, 1.17, 1.18, 1.19 and 1.20

To first align the current xyz position in the block grid and then summon a cat if the entity running the command is within 5 blocks of the coordinate (229,70,92):

/execute align xyz if entity @s[x=229,y=70,z=92,distance=..5] run summon cat

To anchor to eye level and then display the flame particle that is 1 block in front of the entity executing the command:

/execute anchored eyes run particle minecraft:flame ^ ^ ^1 0 0 0 0 10

To give all players 8 golden apples:

/execute as @a run give @p golden_apple 8

To summon a lightning bolt at all creepers:

/execute at @e[type=creeper] run summon lightning_bolt

To teleport all players to the coordinates (8, 64, 22):

/execute as @a run tp @p 8 64 22

Example in Java Edition (PC/Mac) 1.11 and 1.12

To give a golden apple to all players in Java Edition (PC/Mac) 1.11 and 1.12:

/execute @a ~ ~ ~ /give @p golden_apple

To give 64 golden apples to all players:

/execute @a ~ ~ ~ /give @p golden_apple 64

To teleport all players to the coordinates (8, 64, 22):

/execute @a ~ ~ ~ /tp @p 8 64 22

To summon a lightning bolt at all creepers:

/execute @e[type=creeper] ~ ~ ~ /summon lightning_bolt

Example in Java Edition (PC/Mac) 1.10

To summon a lightning bolt at all creepers in Java Edition (PC/Mac) 1.10:

/execute @e[type=Creeper] ~ ~ ~ /summon LightningBolt

How to Enter the Command

1. Open the Chat Window

The easiest way to run a command in Minecraft is within the chat window. The game control to open the chat window depends on the version of Minecraft:

  • For Java Edition (PC/Mac), press the T key to open the chat window.
  • For Pocket Edition (PE), tap on the chat button  at the top of the screen.
  • For Xbox One, press the D-Pad (right)  on the controller.
  • For PS4, press the D-Pad (right)  on the controller.
  • For Nintendo Switch, press the right arrow button  on the controller.
  • For Windows 10 Edition, press the T key to open the chat window.
  • For Education Edition, press the T key to open the chat window.

2. Type the Command

We will cover examples of how to use the /execute command that chain multiple execute commands together.

Summon a Cat if within 5 blocks of a Specific Coordinate

In this example, we are going to first align the current xyz position in the block grid and then summon a cat if the entity running the command is within 5 blocks of the coordinate (229,70,92) with the following command:

/execute align xyz if entity @s[x=229,y=70,z=92,distance=..5] run summon cat

Type the command in the chat window. As you are typing, you will see the command appear in the lower left corner of the game window. Press the Enter key to run the command.

Once the cheat has been entered, the cat will be summoned ONLY IF you are within 5 blocks of the xyz coordinate (229,70,92).

You will see the message “Summoned new Cat” appear in the lower left corner to indicate that the summon was successfully summoned. If the player was NOT within 5 blocks of the coordinate (229,70,92), the /execute command would do nothing and NOT summon a cat.

Display a Particle directly in front of an Entity at Eye Level

In this example, we are going to anchor to eye level and then display the flame particle that is 1 block in front of the entity executing the command with the following command:

/execute anchored eyes run particle minecraft:flame ^ ^ ^1 0 0 0 0 10

Type the command in the chat window and press the Enter key to run the command.

Once the cheat has been entered, the flame particle will appear directly 1 block in front of the entity running the command.

You will see the message “Displaying particle minecraft:flame” appear in the lower left corner of the game window to indicate that the flame particle has been displayed. With this command, no matter where the entity is looking, the flame particle will appear directly in front of the entity at eye-level.

Give all players 8 Golden Apples

In this example, we are going to give all players 8 golden apples with the following command:

/execute as @a run give @p golden_apple 8

Type the command in the chat window and press the Enter key to run the command.

Once the cheat has been entered, 8 golden apples will be given to each player.

You will see the message “Gave 8 [Golden Apple] to 9Minecraft” appear in the lower left corner of the game window to indicate that the golden apples were given to the players. Since we are running the /execute command on behalf of @a, all players will be given 8 golden apples.

As you can see, the possibilities for the /execute command are endless. Give it a try and see what amazing commands you can create.

Congratulations, you have learned how to use the /execute command in Minecraft.

Click to rate this post!
[Total: 2 Average: 5]