Actually it was super easy, barely an inconvenience.
At least, that's what our main source tells us. Herodotos compresses the deeds of the Athenians between the naval battles of Artemision and Salamis in a few quick sentences. After the Spartans were dislodged from Thermopylai, the Greek fleet saw there was no longer any point in defending the straits at Artemision, so they withdrew south to Salamis. The Athenians expected to find the entire Peloponnesian army waiting to help them defend Athens, but found instead that Sparta was once again dragging its feet. Realising that it would be futile to defend the city against the full might of Xerxes, the Athenians evacuated their lands:
While the others put in at Salamis, the Athenians landed in their own country. When they arrived, they made a proclamation that every Athenian should save his children and servants as he best could. Thereupon most of them sent the members of their households to Troizen, and some to Aigina and Salamis.
-- Hdt. 8.41.1
This is more or less all that Herodotos has to say about it. His later account suggests that most of the Athenian population was actually on Salamis, where Athens had established its temporary Council and Assembly so that it could continue to function more or less as a polis should (Hdt. 9.4-6). An extremely controversial inscription known as the Decree of Themistokles - sometimes seen as a genuine document, but probably a fourth-century fake - states that the entire population was evacuated to Troizen instead, with only the elderly being moved to Salamis. Troizen, a town on the opposite shore of the Saronic Gulf, was friendly to Athens.
These sources don't tell us how the evacuation was achieved, and we have to rely on informed speculation. The main problem is that the polis of Athens was not just a city, but a sprawling territory the size of modern Luxembourg, with many smaller towns and villages several days' journey from the main urban centre. Drawing all those people to the harbours of Peiraieus and Phaleron would take time. The process would be dramatically slower if people were trying to save their belongings and valuables - as they most likely were. Unless we assume that only the city proper was evacuated, the process would have taken many days to complete. First, messengers would have to be sent to the far corners of the country to announce the measure; then, people would have to make what preparations they could and make the journey to the ports south of Athens; then they would have to be assigned a ship and a destination.
But they probably had the time to do it. Xerxes' army was very large and moved slowly. Most reconstructions of the timeline in Herodotos put the battle of Artemision in early September 480 BC and the battle of Salamis later the same month. Since the Persians had to cross and subdue all of Phokis and Boiotia first, they may have taken weeks to make it into Attika and threaten the Athenian population. They may not have expected the entire community to up and leave; but even if they did, it was difficult for the Persian army to move faster without losing cohesion and provoking further resistance. In the first year of his campaign, Xerxes still relied primarily on overawing his opponents, and that required keeping his army together.
Meanwhile, the Athenians had their entire fleet ready, and also commandeered their allies to help (Hdt. 8.40.1). They would have had over 300 triremes at their disposal, along with every trader, cargo ship and fishing boat that happened to be docked in the harbour. The fleet that ferried the Athenians out of their territory was massive, and it is likely that the process indeed didn't take long if it could all be reasonably well coordinated. Thankfully most Athenians seem to have been on board with the plan to rely on the fleet (pun very much intended), with only a few stragglers staying behind in a vainglorious attempt to defend the Akropolis. Well before the Persian fleet rounded the cape at Sounion, the Greek fleet would have finished ferrying Athenians and returned to its battle station in the straits of Salamis.
After the battle and the Persians' withdrawal north to winter quarters, the Athenians allegedly returned to Attika, only to evacuate again when the Persians returned during the campaign season of 479 BC (Hdt. 9.6). This either strains credulity or it proves that the evacuation was really rather easily accomplished - whether you choose to believe Herodotos is up to you. It is certain that the Athenians ferried over their people a final time when the Peloponnesians gathered at Eleusis for the decisive campaign that ended at the battle of Plataia (Hdt. 9.19.2).