In the overgrown Beirut marshalling yards, the tracks are still visible, maintaining a ghostly continuum with the past
With a spare hour on my hands before lunch in Lebanon this week, I revisited the joys of my childhood, crunched my way across the old Beirut marshalling yards and climbed aboard a wonderful 19th-century rack-and- pinion railway locomotive. Although scarred by bullets, the green paint on the wonderful old Swiss loco still reflects the glories of steam and of the Ottoman empire.

For it was the Ottomans who decided to adorn their jewel of Beirut with the latest state-of-the-art locomotive, a train which once carried the German Kaiser up the mountains above the city where, at a small station called Sofar, the Christian community begged for his protection from the Muslims. "We are a minority," they cried, to which the Kaiser bellowed: "Then become Muslims!"

But that is another story. The locos went on chuffing up the mountains until 1975 when the Lebanese civil war destroyed many of the trains and much of the permanent way. Up in the Lebanese port of Tripoli, there are some far bigger 0-8-0s (the configuration of steam locomotive wheels), engines which were installed to pull trains between the Lebanese seaport and the Syrian city of Hama. They, too, are perforated by bullets - they had formed part of the Palestinian front line against Syrian troops in 1983 - and their oil is still bleeding from their gaskets.

When first I discovered them, I was in contact with that renowned expert on Middle East steam, Rabbi Walter Rothschild of Leeds, who immediately told me their story. They had originally belonged to the pre-First World War Reichbahn and had been handed over to the French as part of post- war Versailles reparations. The French Middle East mandate had just been created and Paris sent their German gifts to operate out of Lebanon. So these great steam behemoths, which once pulled the middle classes of Germany from Berlin to Danzig, ended up in a north Lebanese railway junkyard.

All my life, I have been fascinated by trains. My mother used to take me down to Maidstone East station in Kent to watch the tank engines pull their local trains in from Ashford or the old Second World War Super Austerity class steamers - big, ugly beasts with a firebox the shape of a squashed toilet roll - with a mile of rusting trucks in tow.

Sometimes, she would take me one station down the line to Bearsted where my father would be playing golf, the compartment - we travelled first class - filling with smoke in the tunnel beneath Maidstone prison, the old black-out curtains banging against the windows. For days, I would stand on the platform of Tonbridge station and watch the Battle of Britain class locos and the Merchant Navy class and the Schools class (from which, I would later note, my own minor public school, Sutton Valence, was rigorously excluded) as they pummelled through with boat trains to Victoria or Dover.

The Golden Arrow, in those pre-Eurostar days, was the joy of every loco- spotter, its cream and gold carriages hauled by an engine with the British and French flags snapping from the boiler. We all held that train lovers' bible in our hands, Ian Allen's loco-spotter's guide to engine numbers.

I used to think all this was a fetish until I realised how deeply the railway system had permeated art. Turner was obsessed with trains. Tolstoy's Anna Karenina falls in love on a train journey, decides to leave her husband on a railway platform and commits suicide by throwing herself in front of a goods train. "And exactly at the moment when the space between the wheels drew level with her ... and with a light movement, as though she would rise again at once, sank on to her knees ... something huge and relentless struck her on the head and dragged her down on her back. `God forgive me everything!' she murmured." Tolstoy even died in a railway station.

Part of Doctor Zhivago revolves around his flight from Moscow by rail, his sight of Strelnikov's revolutionary locomotive and his subsequent trek back to Lara down a partially snow-covered track. The film's treatment of this is not as good as the book's, where a female barber warns Zhivago that he risks arrest with "all this talk of special trains".

The point, of course, was that all trains were "special". My mother took early colour film of 10-year-old Robert watching the big cream and red "Trans Europe Express" - a diesel-hauled all-first-class train - sliding into Freiburg station in Germany in 1956. But equally special was a wind- up model steam loco which my father brought me back from Germany where he had been aiding the post-war reconstruction of Hamburg. Being German, it was so powerful that it once flew off its English Hornby tracks, raced across the front hall carpet, jumped the front door step of our home and struck out across the drive, coming to rest under my father's car.

When the Lebanese authorities briefly restored the coastal line from east Beirut to the Crusader port of Byblos, I travelled its length in the driving cab of a big Polish diesel. It pulled just one wooden carriage - an import from the British empire's Indian empire after the 1914-18 war - and travelled at no more than 15 miles per hour because the Lebanese, being Lebanese, insisted on parking their cars on the track when they went swimming.

Despite the great liners of the world and the growth of air power, leaders - especially dictators - loved trains. Hitler had his own luxurious train, complete with mobile flak batteries. So did Goering, and so did Himmler. And Tito. Soviet commissars loved trains. And trains, of course, became accessories to murder. Turkish railways carried thousands of Armenians to their places of massacre. European trains carried millions of Jews and gypsies to their annihilation. The steam train whistle which permeates D H Lawrence's Sons and Lovers had a quite different connotation as it drifted over the snowfields around Auschwitz.

Somehow, airports never captured the magic of railway stations. Name me an air version of Saint Pancras or the Gare du Nord or Grand Central. But it was years before I grasped - I think - just what the fascination of trains involves. It's about the track, the rails, the permanent way as much as the locomotives. At Edinburgh Waverley, you can look at the twin rails and know that, with points and unwelded track and occasional changes of width, those minutely shaped ramrods of iron stretch unbroken from Scotland via the Channel Tunnel to Turkey or Saint Petersburg or Vladivostok or - save for the Iraqi insurgents who keep blowing up the permanent way - to Baghdad.

I suspect this sense of continuity appeals to us. An airliner might fly a route but never through the same stretch of air. Nor does a ship pass through exactly the same waters each voyage. But the train will always travel - to an inch - along precisely the same journey as it took yesterday or a hundred years ago, the same journey which it will take next week and in a hundred years.

In the overgrown Beirut marshalling yards, the tracks are still visible, maintaining a ghostly continuum with the past, reminding us of the permanence of history and power and - in its worst performance of industrialised murder - of death. Which is why, I suppose, trains capture our imagination and fear from childhood to old age.