Bacteria use type IV pili to walk upright and detach from surfaces.
Bacterial biofilms are structured multicellular communities involved in a broad range of infections. Knowing how free-swimming bacteria adapt their motility mechanisms near surfaces is crucial for understanding the transition between planktonic and biofilm phenotypes. By translating microscopy movies into searchable databases of bacterial behavior, we identified fundamental type IV pili-driven mechanisms for Pseudomonas aeruginosa surface motility involved in distinct foraging strategies. Bacteria stood upright and "walked" with trajectories optimized for two-dimensional surface exploration. Vertical orientation facilitated surface detachment and could influence biofilm morphology.