The bacterial diet is literally elemental. Nitrogen is popular, plucked from the air, water, or soil.
Nitrogen-fixing bacteria are essential to the survival of many plants. Nitrogen-fixers have welcome homes in these plants.
Soil-based Pseudomonas carboxydovorans are on a carbon monoxide diet. Thermophilic Thiobacillus suck sulfur. Gallionella eat iron, add oxygen, and expel rust (iron oxide), staining their habitat brown.
Many of the ancients who arose when oxygen was scarce are literally stick-in-the-muds. Heliobacteria, who shun O2, are exemplary. They can be found flourishing in flooded rice paddies, where oxygen levels are low.
Many bacteria share food with others. Some do so directly, building flexible straws (nanotubules) that let them exchange munchies.