ABSTRACT We present a numerical study of the gravity-driven filamentary flow arising in the presence of elongated perturbations embedded in a globally gravitationally unstable medium. We perform idealized simulations of the gravitational collapse of a moderate filamentary perturbation with a central enhancement (a core) embedded in either a uniform or a stratified background. Both simulations maintain the filamentary structure during the collapse, developing a hierarchical accretion flow from the cloud to the filament, and from the filament to the core. Only the stratified simulation produces a flat central density profile of filaments, best matching the observed Plummer-like profiles, supporting suggestions that molecular clouds may be preferentially flattened. The flow changes direction smoothly from the cloud to the filament, with no density divergence nor a shock developing at the filament’s axis during the prestellar evolution. The drainage of material by the filament-to-core accretion slows down the growth of the filament, causing the ratio of the core’s central density to the filament’s axial density to increase in time, and to diverge at the time when a singularity (protostar) forms in the core. We argue that the system should evolve towards a stationary state in which the filament-to-core accretion balances the cloud-to-filament one, and search for it in the simulations, but find no unambiguous evidence. However, we find that, after a period of accelerated increase, the filament’s linear mass density reaches a linear growth rate. The stationary state may be approached during the protostellar stage.