He knew how to shave because he'd been doing it for a while, but I'm sure someone taught him, too, and someone originally taught that person, and someone taught that person, and so on up the line.
Shaving with a modern razor isn't the sort of thing you pick up by trial and error; you'd just slice yourself by accident and decide that the tool is worse than useless. You need a teacher. The teacher didn't recite lessons from their own teacher -- they recount what they do every day or so -- but they were once taught too. The lessons are probably not very similar down the line from teacher to daily use to student, but perhaps there is some trace of it.
This lineage is difficult to investigate, as I discovered this morning. People seldom mention who taught them to shave, and it seldom gets written down anywhere. You need elaborate and dangerous machinery, and no one will teach you how to use it.
You go back far enough, and you discover that the razor makers originally had to teach their customers how to shave. You go back one step further and you'll discover that the razor makers were spawned by giants, and then the razor-makers rose up and destroyed these primordial beings and kept the secret of shaving. You go back further and find that the giants learned it from the sea foam, and the sea foam learned it from the stars, and the stars stole the knowledge from the first tree and escaped to the sky to avoid punishment. You go back further, and find that the first tree learned it from the birds that comb its surface, and the birds learned it from clay and the clay learned it from the lava and the lava learned it from the Original Mathematical Assumptions.
Then go one step further.