/execute
The Swiss-army command - run other commands as anyone, anywhere, if a condition is met.
Overview
What is the /execute command?
The /execute command is the most powerful command in Minecraft. It doesn't do one thing โ it changes the context of another command: who runs it, where, facing which way, and only if certain conditions are met. Subcommands like as, at, positioned, facing, if, unless and store chain together to express complex logic in a single line.
Nearly every advanced datapack, redstone-free machine and map mechanic is built on /execute. Mastering it is the gateway from casual commands to real command engineering.
When to use it: Use /execute to run a command as or at another entity, conditionally, or with a changed position/rotation โ the heart of advanced command logic.
At a glance
Syntax
/execute as <target> at <anchor> run <command>See it
What it does
Anatomy
Every part, explained
- 1
CommandRequired/executeSets up context for another command to run inside.
- 2
AsOptionalas <target>Whose 'self' (@s) the inner command runs as.
- 3
AtOptionalat <anchor>Where the inner command runs from.
- 4
RunRequiredrun <command>The actual command to execute. Always comes last.
Your turn
Try it yourself
Copy & paste
Examples
/execute as @a at @s run tp ~ ~5 ~Bounce every player 5 blocks up.
/execute as @e[type=cow] run effect give @s glowingMake all cows glow.
/execute if entity @e[type=creeper] run say Boom incoming!Only say it if a creeper exists.
Avoid these
Common mistakes
/execute as @a run @s tp ~ ~5 ~/execute as @a at @s run tp ~ ~5 ~After 'run' you write a plain command - no extra target.
/execute run say hi as @a/execute as @a run say hi'run' must be last - everything after it is the command.
Good to know
Frequently asked questions
- What does /execute do in Minecraft?
- It runs another command in a modified context โ as a different entity, at a different position, facing a direction, or only if a condition is true.
- How do you run a command for every player?
- Use /execute as @a run <command>; it executes the command once per matching player.
- What's the difference between 'as' and 'at'?
- 'as' changes who runs the command (the executor); 'at' changes where it runs from (the position). They're often combined: execute as @a at @s ...
Keep going