You can tell by the pronoun that's used. :D "du" is a subject pronoun meaning you, whereas "deg" is an object pronoun. If "deg" is used, that means "you" is receiving some sort of action, or it might come after a preposition. If "du" is used, on the other than, that means that "you" is the subject—it's doing the action.
- Hvem liker du? = Who do you like?
- Hvem liker deg? = Who likes you?
Hopefully this helps! ^_^
Du is used when «you» is the subject of a sentence. E.g. - you are a man :: du er en mann.
Deg is used when «you» is the object of w sentence. E.g. - the cat likes you :: katten liker deg.
Both 'du' and 'deg' are used in singular instances. 'Dere' is used for the plural variants. E.g. - hey, you guyS :: hei dere.