A bar magnet has a North pole and a South pole. so if it is freely suspended and allowed to align in any direction after the disturbunce it will align along North-South direction. Because the earth is like a magnet with north and south poles. So the bar magnet aligns with the magnetic lines of the earth. This is also right in the case of a freely suspendd fre to move electromagnet.