A model of elastic magnetic filaments is developed, which allows investigating the dependence of filament dynamics on such physical parameters as magnetoelastic number (Cm), frequency of magnetic field, coefficient of friction, etc. By numerical simulation of the dynamics of filament shaping under the action of magnetic field it is shown that a characteristic U-like stable shape (hairpins) can form. Such a shape of filament can exist in the case of low-frequency rotating magnetic field. At the frequency increasing the U-like shape transforms to the S-like one. In the present work it is shown that in unsteady magnetic field a flexible magnetic filament “swims” in the direction of magnetic field.