The /execute Command in Minecraft — Complete Guide
The /execute command runs another command with a modified executor, position, or condition. Its core structure is: /execute <clauses> run <command>. Common clauses are: as @e[type=zombie] (change who runs the command), at @s (change the position to the executor's location), if entity @p[distance=..5] (only run if a condition is true), and positioned x y z (move to an absolute position). Chain multiple clauses before run to combine conditions.
What /execute is for
Most commands run from a fixed position with a fixed executor. /execute lets you change both before running the command, and adds conditions so the command only fires when something is true.
Practical examples: - Run a command for every zombie on the map simultaneously - Kill a player only if they are standing inside a specific area - Give an item only to players who have a certain score - Summon lightning at the exact position of an entity - Check whether a block exists before placing another block
Basic structure
The minimal /execute command has at least one clause and ends with run:
/execute as @a run say Hello
This runs /say Hello as every player. Clauses stack left to right:
/execute as @e[type=zombie] at @s run summon lightning_bolt ~ ~ ~
as @e[type=zombie] — iterate over every zombie at @s — move execution position to each zombie's location run summon lightning_bolt ~ ~ ~ — summon lightning there
Result: lightning strikes every loaded zombie simultaneously.
as vs at — a common point of confusion
as changes the executor (@s) but does not change the execution position. at changes the position to match an entity's location but does not change the executor.
To both run as the zombie and at its position:
/execute as @e[type=zombie] at @s run ...
This is the most common pattern in practical /execute usage.
Conditional execution: if and unless
if and unless make /execute conditional.
if entity — check if an entity exists: /execute if entity @p[distance=..5] run say A player is nearby
if block — check if a block is at a position: /execute if block 0 64 0 minecraft:diamond_block run say Found it
unless inverts the check: /execute unless entity @e[type=zombie] run say No zombies loaded
if score — compare a scoreboard value: /execute if score @p kills >= @p threshold run give @p minecraft:diamond 1
Multiple if clauses are ANDed together — all must be true.
positioned: move execution to a fixed point
positioned lets you move the execution context to an absolute coordinate:
/execute positioned 0 64 0 run setblock ~ ~ ~ minecraft:stone
This places stone at 0 64 0. ~ ~ ~ is evaluated from that position.
positioned is most useful when operating on a fixed grid coordinate regardless of where the command block is.
store: save a result to a scoreboard
store captures the result of a command into a scoreboard objective or NBT:
/execute store result score @p health run data get entity @p Health
This reads the entity's Health NBT and stores it in the "health" objective for the nearest player.
store success captures 1 if the command succeeded and 0 if it failed — useful for conditional branching.
Bedrock Edition differences
Bedrock Edition supports most /execute clauses but:
if score and store are not available in all Bedrock versions.
Bedrock does not support data get or data modify.
if block and if entity work on Bedrock and are the most reliable conditional tools.
The pattern as @e at @s run <command> works identically on both editions.
Frequently asked questions
Can I chain /execute commands inside each other?
You cannot nest /execute in another /execute's run clause directly. Use a function file (/function) to call a group of commands, then call that function from within /execute run.
What does ~ ~ ~ mean inside /execute run?
Tilde notation is relative to the current execution position. After as @e at @s, the execution position is the entity's feet. So ~ ~1 ~ is one block above the entity.
How do I run a command only once even if /execute iterates over many entities?
Add [limit=1] to your target selector, or add a scoreboard check so the command only fires for entities with a specific score.
What is the difference between /execute if block and /testforblock?
/testforblock was removed in Java 1.13. /execute if block is the modern replacement. On Bedrock, both still work.
Can /execute run multiple commands at once?
The run clause only accepts one command. Put multiple commands in a function file and call it with /execute ... run function namespace:name.