Introduction to Selectors

Use
Selectors are used in almost every command. They tell the game who to apply the command to. This page will teach you basic know-how on how they are used and what for.

Placement
In most commands, a Selector is used as the second, or sometimes third, word in the command. For example, in The Tell Command, one might write :

/tell RandomGuy_123 Hello, How Are You Today?

As you may notice, RandomGuy_123, which is a player's name, is the second word in the command. This tells Minecraft who the player is /telling the message to.

Different Selectors
PlayerNames are not the only type of valid selector. When writing a command, the player has access to 5 different basic Selectors: These can all be used in place of the "RandomGuy_123" Example Player's name. They're pretty self-explanatory, if they just "Select"(Hence the name) an entity based on their properties which are listed after their names on the list.
 * 1) PlayerNames
 * @p, or "Nearest Player"
 * @e, or "All Entities(Moving Things)"
 * @a, or "All Players"
 * 1) and finally @r, or "Randomly Selected Player".

Specifications and Brackets
Now, I'm only going to go over this lightly, but along with the Selector, you can add Specifications, which specify even closer which entities to select when applying the command. To do this, change your command so it looks like this:

(I'm going to use /tell as an example) /tell @p[] Hello, How Are You Today?

In place of the , you can put many, things, but I'll go over the two simplest. These both do pretty useful things, starting with the r=Number command. I'll use the value 5 as an example here. Doing '''/tell @p[r=5] Hello! '''would tell the nearest player within a radius of only 5 blocks outward your message. If there was no one, two things would happen: #1, you would get an error message saying that no player could be found, and 2, you would feel sad because you have no friends. The type=EntityType command would select only the nearest player, but only if they were a certain type of Entity, like a Silverfish. In this case, nothing would happen, because last time I checked, you are not a silverfish. When using @e[type=Silverfish], though, you could target only silverfish.
 * 1) r=
 * 2) type=