I see that 但 means "only" besides its typical meaning "but". So what is the difference between 但 and 只 and when do you use 但 with the meaning "only"?
但 means 'but' ; 'only' ; 'just'
只 means 'only'; 'just'
The difference between the two when they are functioning as 'only/just':
但 is more literary/ classical; 只 is more colloquial/ contemporary
只看不買 (only look but not buy) - a normal contemporary sentence
但看不買 - it sounds awkward with a classical term mixed in a contemporary sentence
但說無妨 (It is fine, just say it)- a normal classical sentence
只說無妨 - it sounds awkward with a contemporary term mixed in a classical sentence
但 can be short for 但願, but 只 cannot
但得我一家平安 = only (wish) my family is safe -- 但 here is short for 但願 (only/ just wish)
只得我一家平安 = only my family is safe-- 只 here cannot be short for 只願 (only/ just wish)
In some context. they are interchangeable:
- 但求我一家平安 = 只求我一家平安 -- with the verb 求(wish), both 但求 and 只求 mean 'only/ just wish'
Let me just supplement Tang Ho's perfect answer with two other examples.
- 但願人長久，千里共嬋娟 from the Song poem 水調歌頭, 蘇軾
which means '(I) just wish him (author's brother) a long life, and that we look at the same beautiful moon despite being thousands of miles apart.'
- 但得有三餐足夠，為人樂觀好少掛憂 from the Cantonese song 杯酒當歌, 許冠傑
which means 'I just need 3 good meals a day and nothing more. I am optimistic and seldom worried.'