TRIPOLI/GENEVA (Reuters) - They trekked through the Sahara in hope of crossing the Mediterranean to a better life in Europe - but instead ended up in squalid detention centers and are now engulfed by war.

Members of Libyan internationally recognised pro-government forces are seen in military vehicles on the outskirts of Tripoli, Libya April 10, 2019. REUTERS/Hani Amara

Thousands of African and Syrian migrants and refugees are trapped in Tripoli as a battle for the city draws closer.

The United Nations wants to move them urgently to safety, but this week only managed to relocate 150 to a protected facility with proper shelter, food and space for children.

So desperate is the situation that one detention center manager said he flung open the doors as fighting drew near.

“They can hear the clashes. And many are really scared,” UNHCR spokesman Babar Baloch said of the migrants.

They are crammed into disused warehouses, hangars and prisons where armed groups with no experience of handling refugees guard them, say witnesses and rights reports.

On the northern edge of Africa with a long Mediterranean coastline, Libya hosts more than 700,000 people who have fled their homelands, often trekking through desert in pursuit of their dream of crossing to a better life in Europe.

About 7,000 of them are in detention centers - mostly in Tripoli - where conditions were awful even before they began hearing gunfire and shells as eastern forces approached a week ago.

Sleeping shoulder-to-shoulder, sometimes under steel rooves in baking heat and without proper food, water or medical assistance, the detainees wait for a visit by international organizations or the chance of a laboring job, according to visitors, rights groups and U.N. officials.

They are seldom allowed out for fresh air, and sometimes given just one meal a day, of pasta or bread, the sources said.

Many of the detainees were captured on arrival through the Sahara, or forcibly returned by patrols stopping their flimsy vessels in the Mediterranean.

“TERRIBLE DEPRIVATIONS”

Repeatedly warning of their plight, the U.N. refugee agency UNCHR took more than 150 Somali, Ethiopian, Eritrean and Syrian refugees from the Ain Zara detention center in south Tripoli on Tuesday to its own facility in a nearby “safe zone”.

“Many refugees and migrants in Libya endure terrible deprivations. They are now at grave additional risk,” said Matthew Brook, UNHCR deputy chief of mission in Libya.

At Ain Zara, the manager, who asked not to be named, told Reuters he opened the doors on Wednesday to let another 150 terrified migrants into the streets as gunfire drew close.

“I let them go for their safety,” he said.

Qasr ben Gashir, Gharyan and Abu Salim detention centers are others closest to the front lines, as the eastern Libyan National Army (LNA) forces of Khalifa Haftar take southern suburbs of Tripoli.

According to U.N. figures, there are an estimated 660,000 migrants in Libya, and a further 58,000 classed as refugees or asylum-seekers fleeing home because of violence or persecution.

The U.N. human rights office has expressed fears the warring parties may use migrants as human shields of forcibly recruit them. It cites unconfirmed reports that some were coerced last year into fighting in Tajoura, just east of Tripoli, which is controlled by pro-Islamist armed groups.

Haftar’s forces accuse the Tripoli-based government of using migrants and criminals as human shields and fighters - though they have not provided evidence or given details.

“After the end of the battles, we will show this to the world,” spokesman Ahmad Mesmari told Reuters in Benghazi.

Spokespeople for the Tripoli government of Prime Minister Fayez al-Serraj and its allied forces, which control the detention centers, did not respond to repeated requests by Reuters for comment on the migrants’ situation.

In past meetings with U.N. officials, however, they have insisted they are providing adequate conditions.

According to one U.N. report last December, migrants and refugees in Libya suffer a “terrible litany of violations” by a combination of state officials, armed groups and traffickers. “These include unlawful killings, torture, arbitrary detention, gang rape, slavery, forced labor and extortion,” it said.

A study last month by the Women’s Refugee Commission, a U.S.-based charity, said refugees and migrants trying to reach Italy through Libya were victims of horrific sexual violence.

The abuse was commonplace along routes through North Africa: at border crossings and check points, during random stops by armed groups, and when migrants were kidnapped and held for ransom, said the report, titled “More Than One Million Pains”.