You can not. Pin 2 of the Raspberry Pi expansion connector connects directly to a USB power source - it is not controlled by the processor.
Do not try to connect the fan directly to the GPIO output; they not only fail to produce the correct voltage, but they cannot drain enough current to start the fan. Trying to do this is very likely to destroy the pin driver, and may also damage other parts of the BCM2835.
If you need to turn the 5V fan on and off, you will need some auxiliary equipment to control it (for example, field transit).
source share