Duck, Drop, Cover and Hold. Sounds kind of like the name of a law firm but it's what you do if you're inside when the quake hits.
Duck under a strong piece of furniture, if at all possible. Most earthquake injuries are the result of being hit by something falling on you.
Drop to the floor to avoid falling or being thrown down. Once the earth starts moving it's hard to keep your balance.
Cover yourself with anything that may protect you from flying glass and debris. Use clothing, blankets, cushions, or furniture.
Hold on to whatever you're using for cover, the ground motion may be violent. Get away from glass, book cases or anything heavy that could fall over on you. Doorways used to be recommended but most experts now say stay away form them. Doors can slam shut with bone crushing force. Anyway, the experts say that in modern construction a doorway is no stronger than any other location along the wall.
Resist the urge to run outside. While the ground is moving and immediately afterward, the greatest danger is of being injured by taking a fall or by being hit by a falling piece of building as you exit. If you smell gas or when the shaking stops, calmly, carefully make your way out and get clear of the building. Before you leave get shoes on, you will be walking on broken glass. If you're in a crowd stay put, stay calm, and take what cover you can where you are. In a crowd the greatest dangers are panic and the rush for an exit.
If you're outside stay there. Stay away from buildings, bridges, power lines, telephone poles, anything that can fall on you. If you're in a parking lot do not stand between parked cars. Ground motion can bounce the cars together.