Does anyone remember the science fiction story
"Strange Exodus", a short story by Robert Abernathy; first published in Planet Stories, Fall 1950, available at the Internet Archive; reprinted in the
1974 anthology Space Odysseys edited by Brian W. Aldiss, which has appeared in several different editions.
Gigantic, mindless, the monsters had come out of interstellar space to devour Earth. They gnawed at her soil, drank deep of her seas. Where, on this gutted cosmic carcass, could humanity flee?
in which giant slug-like monsters devour all life on earth,
"There are so many of them, and we've destroyed so few—and to kill those few took our mightiest weapons. Examination of the ones that have been killed discloses the reason why ordinary projectiles and bombs and poisons are ineffective against them—apart, that is, from the chief reason of sheer size. The creatures are so loosely organized that a local injury hardly affects the whole. In a sense, each one of them is a single cell—like the slime molds, the Earthly life forms that most resemble them.
"That striking resemblance, together with the fact that they chose Earth to attack out of all the planets of the Solar System, shows they must have originated on a world much like this. But while on Earth the slime molds are the highest reticular organisms, and the dominant life is all multicellular, on the monsters' home world conditions must have favored unicellular growth. Probably as a result of this of this unspecialized structure, the monsters have attained their great size and perhaps for the same reason they have achieved what even intelligent cellular life so far hasn't—liberation from existence bound to one world's surface, the conquest of space. They accomplished it not by invention but by adaptation, as brainless life once crawled out of the sea to conquer the dry land.
"The monsters who have descended on Earth must represent the end result of a long evolution completed in space itself. They are evidently deep-space beings, able to propel themselves from planet to planet and from star to star in search of food, guided by instinct to suns and worlds like ours. Descending on such a planet, they move across the surface systematically ingesting all edible material—all life not mobile enough to avoid their march. They are like caterpillars that overrun a planet and strip it of its leaves, before moving on to the next.
"Man is a highly mobile species, so our direct casualties of this invasion have been very light and will continue to be. But when the monsters have finished with Earth, there will be no vegetation left for man's food, no houses, no cities, none of the fixed installations of civilization, and the end will be far more terrible than if we we were all devoured by the monsters."
and at the end of the story, the protagonist climbs on top of one of the monsters
For a moment he knew despair. The way back was impassable, and the way ahead was blocked by the titanic enemy.
Then the impersonal will that had driven him implacably two days and nights without stopping came to his rescue. Westover plodded forward, pressed his shrinking body against the slimy, faintly warm surface of the monster's foot, and sought above him with upstretched hands—found holds, and began to climb with a strength he had not known was left in him.
and either hacks his way inside it or finds an existing hole, and inside there is a small group of other survivors who live by eating the creature's flesh?
"Down here, into the belly of Leviathan," said the old man solemnly, and Westover nodded this time with alacrity.
The crawling descent through the twisting, Stygian burrow had much that ought to belong to a journey into Hell. . . . More than that, no demonologist's imagination could have conceived without experiencing the sheer horror of the yielding beslimed walls that seemed every moment squeezing in to trap them unspeakably. The air was warm and rank with the familiar heavy, sweetish odor of the monster's colorless blood. . . .
Then, as he knew it must, a light glimmered ahead, the sinus widened, and Westover climbed to his feet and stood, weak-kneed still, staring at a chamber carved in the veritable belly of Leviathan. The floor underfoot was firm, as was the wall his shaking fingers tested. Dazzled, he saw tools leaning against the walls, spades, crowbars, axes, and a half-dozen people, men and women in rough, grimy clothing, who stood watching him with lively interest.
All this happens right before the monsters lift off into space again, taking the remnants of humanity with them.
His voice was drowned in a vast hissing roar. An irresistable pressure distorted the walls of the chamber and scythed its occupants from their feet. Sutton staggered drunkenly almost erect, fought his way across the tilting floor to make sure of his precious apparatus. He turned back toward the others, bracing himself and shouting something; then, knowing his words lost in the thunder, gestured toward the Earth they were leaving, a half-regretful, half-triumphant farewell.