The environmental topology of complex structures is used by Escherichia coli to create traveling waves of high cell density, a prelude to quorum sensing. When cells are grown to a moderate density within a confining microenvironment, these traveling waves of cell density allow the cells to find and collapse into confining topologies, which are unstable to population fluctuations above a critical threshold. This was first observed in mazes designed to mimic complex environments, then more clearly in a simpler geometry consisting of a large open area surrounding a square (250 x 250 mum) with a narrow opening of 10-30 mum. Our results thus show that under nutrient-deprived conditions bacteria search out each other in a collective manner and that the bacteria can dynamically confine themselves to highly enclosed spaces.