Count Players and Entities with Testfor
The /testfor command counts entities like players, mobs, and items that match specific conditions you set. It tells you if a certain target exists in your loaded world right now.
Players and map makers use this command to check if someone is online, count how many monsters are in an arena, or detect dropped items. To use it, you must have cheats enabled and hold Game Directors permissions.
/testfor <victim: target>Test for
| Argument | Type | What it means |
|---|---|---|
victim | target | A name `string` or `target selector` to identify who or what is being counted. |
/testfor SteveChecks if a player named Steve is currently in the world.
/testfor @aCounts every player who is currently online in the game.
/testfor @pFinds and verifies the single closest player to the spot where the command is run.
/testfor @rTests for one random player currently in the world.
/testfor @e[type=zombie]Counts all zombie mobs that are currently loaded in the world.
/testfor @e[type=item]Counts all dropped item entities floating on the ground.
/testfor @a[r=15]Counts all players within a 15-block radius of where the command runs.
/testfor @e[type=cow,c=3]Checks for up to 3 of the nearest cow mobs.
Minecraft Java Edition does not have a command named /testfor, as it is only available in Bedrock Edition.
It counts players, mobs, items, and other entities in the world that match the name or target selector you enter.
This command requires cheats to be enabled in your world and you must have the Game Directors permission level to run it.
No, Java Edition has no command with this name; it is only used in Bedrock Edition.
/dialogue/execute/function/packstack/reload/reloadpacketlimitconfig/schedule/scoreboard/scriptevent/sendshowstoreoffer/tag/testforblock/testforblocks/toggledownfall