Can you replicate a gun slide?

If you look at a semi-automatic gun or any other pistol for that matter, you can see that when you fire it, the slider slid back and forth quickly. I wonder if there is a hassle-free way of setting up a constraint so that it’ll slid along only one axis and a certain amount unit? Thanks!

make that part the child of the rest of the gun

make it so the axis moved along is one of the global axes

animate, and tweak the ipo to your liking

then make the parent of the gun some hand or something

you don’t really need a constraint if the axes were set up right and you have a parent of that object being the gun