Molecular ions fragment and break apart into pieces because they are unstable. Usually its the weakest bonds in molecules that break first. In general the different functional groups fragment in different ways.
Alcohols undergo two common primary fragmentation reactions; α-cleavage and dehydration.
For example in the following mass spectrum of 3-hexanol an m/z=59 and m/z=73 were observed.
Alcohols will also undergo dehydration expelling water and forming cation radicals. The 3-butanol example above shows a low abundance peak at m/z=84 from loss of water.
Ethers undergo alpha cleavage much like alcohols.
Nitrogen containing compounds will have a odd mass molecular ion peak if they have an odd number of N atoms and even mass if they have an even number of N atoms.
Amines undergo α-cleavage to form iminium ions (protonated imines).
The primary fragmentation of carbonyl containing compounds is α-cleavage and McLafferty rearrangement.