I always see images of simple experiment with iron filings and a bar magnet where the iron filing conform to the magnetic field to visualize the field lines. I do not understand why, under the influence of magnetic field, not all iron filing just move the sticks to the North pole? If it is because of friction, then why would the iron filings managed to overcome the friction in the first place to align itself to the magnetic field?
It's a fair question. A particle in a magnetic field becomes magnetized, and experiences two forces: a torque due to the face that its (induced) dipole moment is not aligned with the magnetic field, and a force due to the gradient of the magnetic field.
Now on a macroscopic level, the gradient is strongest near the poles of the magnet, and you will see a considerable quantity of filings pile up there; but as you get further from the poles, the gradient becomes very weak (roughly as the fourth power of the distance).
The induced dipole itself is proportional to the strength of the field, and the force is the product of dipole and gradient. This means that the gradient effect becomes much weaker with distance: for a bar magnet, field falls roughly with distance cubed (at sufficiently large distance), so gradient falls with fourth power and the attractive force with the seventh power of distance. By contrast, the torque that aligns the particles goes as the sixth power. That sounds really bad as well, until you realize that a metal filing will act as a local "field amplifier": it "pulls the field lines towards it", leading to a concentration of field lines at the tip - and a strong (but very localized) gradient. This gradient means that nearby filing particles will strongly attract each other, and align into the characteristic pattern you are familiar with. But there is no such amplification at a distance - so the particles won't move on a large scale, as there are no large scale gradients to push them.
When an iron filing finds itself in a magnetic field it becomes magnetised. The magnetic field is concentrated at the poles.
The external magnetic field may exert a torque of the iron filing so that it rotates towards the direction of the external magnetic field.
Subsequent iron filings will be attracted more to the poles of the magnetised iron filings and so will line up with them. So you get a line of iron filings approximately following the external magnetic field line.
A standard way of improving the visibility of the iron filing pattern is to tap the paper on which they reside to help them with the alignment process.
If you shake the iron filings too much they do indeed accumulate at the poles of the magnet(s) producing the magnetic field.
Electric field can also be made "visible" in a similar way but instead of iron filings short lengths of paint brush bristles or semolina are used immersed in an organic liquid which is an insulator..
The points on the end of the bristles have a larger concentration of induced charges and align themselves in much the same way as the iron filings.