I wrote about that a bit in this answer, but the short version of it is that Nelson knew the French fleet were headed to Egypt and that they would be most likely making for Alexandria, based on intelligence he'd gathered at Naples. He overhauled the French fleet in the dark and, when he got to Alexandria, found it empty; he turned north to scout the Anatolian coast and headed west back to Sicily. He refitted there and turned back toward the eastern Mediterranean, finally learning about the Battle of the Pyramids when watering in Greece, and found the French fleet at Aboukir Bay.