First, we will target a mob:
/execute @a Targets all players.
/execute @e Targets all entities, including item frames, armor stands and items.
To be more specific use:
Or if you want to target names mobs only then use:
Ok, now onto the actual command:
The ~ symbols show where the command will take place based on the location of the entity [XYZ]. For example,
/execute @e[type=TargetEntityHere,name=MobName] ~0 ~1 ~0 CommandHere
So if you want to summon lightning at a pig named Bob, you would use:
/execute @e[type=Pig,name=Bob] ~0 ~0 ~0 summon LightningBolt
You can also use /execute commands in /execute commands!~
/execute @e[type=TargetEntityHere,name=MobName] ~ ~ ~ execute @e[type=TargetEntityHere,name=MobName] ~ ~ ~ kill @e[type=Player,name=Herobrine]
You could do awesome stuff with this, like give players particle trails and summon TNT to create bat bombers!
Hope you learned something!