Sometimes they are the same: I
just/only need five more minutes to finish this.
Sometimes you can't substitute "only" for "just." Just do it! (Sports equipment slogan) "Can't we all just get along?" - Rodney King (A synonym for "just" in these two expressions could be "simply."
"What did you just give me?" "Just" = "a very short time ago." You can't say, "What did you only give me?" But you can say "Just/Only a moment ago I felt okay."
Edit. Kooyeen "just" used the preferred expression: "when 'only' means
'as recently as' ." (
I found out about his death only yesterday.) "Just" and "only" are interchangeable here.
Note that "recently" is relative here, as to the length of time passed. I'm thinking of Billy Strayhorn's lyrics,
Life is lonely again, and only last year everything seemed so sure. - (Lush Life)