1590s, in reference to the horizontal and vertical lines of soldiers marching in formation, from rank (n.) in the military sense of "number of soldiers drawn up in a line abreast" (1570s) + file (n.1). Thence generalized to "common soldiers" (1796) and "common people, general body" of any group (1860).
also bobby socks, 1943, from diminutive of bob (n.2) + sox. So called because they are "shortened" compared to knee-socks. Derivative bobby-soxer "adolescent girl," especially with reference to fans of popular crooners, first attested 1944.
Months ago colored bobby sox folded at the top were decreed, not by anyone or any group but, as usual, by a sudden mysterious and universal acceptance of the new idea. Now no teen-ager dares wear anything but pure white socks without a fold. [Life magazine, Dec. 11, 1944]