As a conjunction
But, as a conjunction, is used to join contrasting ideas.
- Their front door was open, but nobody was at home.
- The rope was thin but it was strong.
- He is hardworking, but not clever.
As a preposition
But, as a preposition, can mean except after all, none, every, any, no etc.
- They are all wrong but me! (= — except me.)
- All but you loved me for money. (= All except you loved me for money.)
- Everybody came but John. (= Everybody came except John.)
The expression but for is used to express the idea of if something had not existed/happened.
- We should have enjoyed the journey but for the rain.
- He would have helped us but for having no money himself. (—except that he had no money.)
After but we usually use object pronouns. Subject pronouns are also possible in a formal style.
- Nobody but him would do a thing like that. (More formal: Nobody but he —)
Cannot but + infinitive
Cannot but + infinitive or cannot help but + infinitive is often used with the meaning of can’t help -ing.
- I cannot but admire your courage (= I cannot help admiring your courage.)
But meaning only
But, as an adverb, can mean only. This is very unusual in modern English.
- We can but try. (= We can only try.)
- He is but a boy. (= He is only a boy.)