A typical Civil War or Indian Wars cavalry regiment would have, on paper, one colonel, one lieutenant colonel, three majors, 12 captains, each commanding a company (troop after 1883), assisted by one first lieutenant and one second lieutenant (each commanding a platoon), one or two medical officers, and a regimental adjutant, probably assigned from among the company lieutenants, so, about 43 officers. Battalions (squadrons) were ad hoc groupings of companies during this period, commanded by the lieutenant colonel, one of the majors or a senior captain. Staff officers (in the modern sense), although appointed from the Line, were not in the chain of command leading to the commanding general of the army, but were responsible through their bureaus to the Secretary of War.
In practice, these units would be chronically short of officers because of detached service, staff appointments, wounds, replacement policies and other reasons, so that, especially in the case of Civil War regular army regiments, the senior captain might command the regiment.
After the Civil War ended, brigade, division, corps and army organizations ceased to exist, so that an officer aspiring to higher command would seek assignment to one of the geographic commands: a Military Division or one of its Departments or Districts, and command any troops assigned to that it.
And any officer might be assigned to serve in his brevet or temporary Civil War rank, usually a few grades higher than his actual rank.
After that, it gets complicated.