The pictures of collapsed buildings after earthquakes are scary but the chance of an individual building collapsing are quite low, you're at far greater risk if you're outside near buildings because broken glass or similar could fall on you.
The standard advice is good advice for a reason: stay inside, under sturdy furniture, on your elbows and knees, covering your head. You can learn more here: https://sf-fire.org/disaster-preparedness-information-resour...