How did "but" mean "only"?

Both meanings are still in usage, and in fact are really the same meaning with slight variation. Consider the following two sentences:

He took all but one cookie.

and

I had but one cookie.

They could be rephrased as

He took all except one cookie.

and

I had nothing except one cookie. OR

I had only one cookie.

The difference is simply in the implied word 'nothing' in the second sentence.


I'm not a scholar of Old English, but I think you're wrong to assume that much changed semantically. The OED gives an example from an Anglo-Saxon calendar from the year 1000 of "but" being used as a preposition meaning "except for one thing."

Swylce ymb fyrst wucan butan anre niht
þætte yldum bringð sigelbeorhte dagas sumor to tune,

So around the first week, less one night,
sun-bright days bring to men summer to town

"The first week excepting for one night" means the first week [in May] excepting for time until one nightfall, or in other words, the first six days. The OED notes that in Old English, the inflections for case will tell whether the expression is to be understood as "Six days except one did bring" or "One day did not bring and six did." The different parsings were no longer available in similar sentences once English lost the inflections, but it's clear that the reference is to "only" one day out of the first week.