Families separated at the border with Mexico under President Donald Trump's "zero tolerance" policy will be reunited within 30 days, a US judge has ruled.

For children under five, reunification must take place within two weeks of the order issued Tuesday by US District Judge Dana Sabraw in San Diego.

Sabraw made the sternly worded decision in response to a suit filed by the American Civil Liberties Union on behalf of a seven-year-old girl who was separated from her Congolese mother and a 14-year-old boy who was separated from his Brazilian mother.

The judge also issued an injunction against any more family separations, which was part of a policy under which anyone crossing the border illegally is detained and referred for criminal prosecution.

US federal authorities have 10 days to allow parents to call their children if they are not already in touch with them, the judge said.

Trump last week signed an executive order halting his government's practice of taking children away from parents who cross the border without papers, even to seek asylum. Many are destitute people fleeing gang violence and other turmoil in Central America.