A process that is carried out at the cellular level which results in the assembly, arrangement of constituent parts, or disassembly of a pilus, a short filamentous structure on a bacterial cell, flagella-like in structure and generally present in many copies.