Minecraft target selectors explained

Selectors pick which players or mobs a command affects. They work in almost every command that has a target argument.

The selectors

SelectorSelects
@pThe nearest player.
@rA random player (Java: a random online player).
@aEvery player.
@eEvery entity, including mobs, items and players.
@sThe entity running the command (you, in chat).
@nThe nearest entity of any type (Java).

Selector arguments (Java Edition)

Put arguments in square brackets, separated by commas: @e[type=cow,distance=..20].

ArgumentMeaning
type=zombieOnly entities of this type; type=!player excludes players.
name=SteveOnly entities with this name.
distance=..10Within 10 blocks. Use ranges like 5..20.
limit=3,sort=nearestAt most 3, nearest first. sort can be nearest, furthest, random or arbitrary.
tag=bossOnly entities that have this tag (see /tag).
scores={kills=5..}Only entities whose score matches the range.
team=redOnly members of this team.
level=10..Players with experience level 10 or more.
gamemode=survivalPlayers in this game mode.
x=0,y=64,z=0,dx=10,dy=5,dz=10Inside a box from a corner.
nbt={OnGround:1b}Entities whose data matches.
predicate=my:pack/testEntities that pass a data pack predicate.

Try them