How do molecules know how to behave when a disturbance occurs in an equilibrium?
The molecules don't know, they aren't alive in any way for that matter!

Here's an easy way to see it (note that I'm avoiding a mathematical approach to give an intuitive reason):

Consider a hypothetical reaction where $\ce{A}$ and $\ce{B}$ combine and gives $\ce{C}$:

$$\ce{A + B &lt;=&gt; C}$$

Let's say initially, there's an equilibrium. The rate of combination of $\ce{A}$ with $\ce{B}$ is the same as the rate of dissociation of $\ce{C}$. Let's say we added an excess of $\ce{B}$. If there's lots of $\ce{B}$ around, molecules of $\ce{A}$ have more chances of bumping into molecules of $\ce{B}$. This pushes the equilibrium forward, until there's enough $\ce{C}$ to counteract the amount of $\ce{A}$ and $\ce{B}$ present. A similar argument can be given if $\ce{A}$ was in excess than in $\ce{B}$.

You could now think about what happens if we removed some amount of $\ce{C}$. In such a case, the rate dissociation of the limited amount of $\ce{C}$ in the vessel would not balance with the rate of combination of $\ce{A}$ and $\ce{B}$, and thus equilibrium would again flow towards the products.

Now, lets see what happens if you add an inert gas $\ce{D}$ to that mixture. In such a case, $\ce{C}$ will continue to dissociate in it's usual rate, but $\ce{A}$ and $\ce{B}$ cannot combine with each other as fast because they may bump into $\ce{D}$ instead of each other. Thus equilibrium shifts towards the reactants. 

I hope this makes sense. Leave a comment if you're not understanding any part of this.