The metallic core of the earth helps create the earth’s magnetic field with north and south poles. The compass reacts with the earth’s poles to point in the direction of the earth’s North Pole.
Rubbing the magnet against the needle in one direction caused the iron atoms in the object to line up and create a weak magnetic field, which made the needle behave like a magnet.
You had to rub in one direction to get the atoms to all line up in the same manner. If you had rubbed back and forth with the magnet, the atoms would not have lined up as well, and the magnetic field would probably not be as strong, if one was created at all.
How does this work:
When the needle is magnetized it will be positively charged, meaning it will be attracted to a negative and repulsed by positive magnetic fields.
The tip of the needle will be polarized and will point towards the strongest magnetic pole, meaning north in the Northern Hemisphere. From this initial bearing you should be able to determine the remaining cardinal bearings by drawing an imaginary line perpendicular to the needle bearing. Facing north east is on the right with west on your left.