From the comments:
- Bacteria excrete all sorts of chemical signals to the surround environment. The white blood cells (WBC) can sense these chemoattractants and go in the direction where the highest concentration of them can be found.
- It doesn’t really “know” that it wants to capture it, all of this is pure chemical reactions. Receptors on the WBC help detect the chemoattractants and make the WBC go towards the the bacterium. Once the WBC physically touches the bacterium another set of receptors tell the WBC to engulf the bacteria via endocytosis.
- It may or may not “know”. Depending on what kind of bacteria it is, it may be immobile depending on whether it has flagella (cellular propellers) or not. If the bacteria is immobile, it’s simply just getting pushed around. If it does have flagella, its movement might be just random, towards a chemoattractant or away from a chemorepellant.