How can my wheel gear and slider run
The main trick with many rigidbody constraints is getting the constraint's empty aligned the way you want. Though before aligning anything, me must first create something to align:

Create a constraint


If you haven't already, add rigid body physics to your objects via 3D view > Tool Shelf (N) > Physics. Active objects will move, Passive objects won't.
Create a constraint between the objects by selecting them and clicking 3D view > Tool Shelf (T) > Physics > Constraints > Connect. This will create an empty with a rigid body constraint connecting the selected objects (for more advanced applications, this can be used on more than two objects at once). 
In the redo menu, select Motor as the constraint type.
Select the newly created empty, and rotate it so its local X axis is aligned with the axis you want the motor to rotate around.
Enable Angular Motor in Properties > Physics




Now our the gear should rotate when we play the simulation:



Well, it did rotate, but it also fell down. To prevent that, we'll have to use a second constraint to actually attach it to the cylinder.

Use multiple constraints together

Add a second constraint by again following the steps above, but this time pick Hinge for the constraint type and rotate the hinge empty so that its local Z axis is aligned with the axis of rotation.
don't ask me why one is X and one is Z..

Once you get the correct empties oriented the right ways, your gear should now behave like this:



Apply the same process for a slider

The process for a motorized slider is very similar, but this time you'll want a Motor constraint set to Linear Motor instead of Angular Motor, and a Slider constraint instead of a Hinge constraint. This time both constraint empties should have their local X axes aligned with the axis along which the cube should slide.

Once you have this set up, try enabling and adjusting the Lower Upper limits on the hinge constraint. These control how far the cube is allowed to slide (in blender units).

If you want the cube to slide back and forth (or do anything besides move in one direction at a constant rate), you can drive or animate the Target Velocity of the linear motor constraint: