The chemical reactions and pathways involving nitriles, an organic compound containing trivalent nitrogen attached to one carbon atom. The nitriles are named with reference to the acids produced by their decomposition; for example, hydrocyanic acid is formic nitrile, and methyl cyanide is acetic nitrile.