There are numerous ways in which you can be safe during an earthquake.
What to do if you're indoors during an earthquake
Go under a table or desk and hide under them until the shaking stops.
Stay away from exterior walls, glass, heavy doors, heavy furniture, fireplaces and kitchen appliances. Do not use the elevator.
If you cannot find any tables or desks to hide underneath them, then cover your face and head with your arms and stay inside a corner space in the building.
If you're on the bed, stay there and cover your face with a pillow, else move to a nearest safe place till the earthquake stops.
Stay away from electric wiring's.
Do not step out of the house until it stops.
What to do if you are outdoors
Stay away from buildings,street lights, power-lines, and such.
Stay out in the open.
If you're in a moving vehicle, stop as quickly as possible and do not park under trees or buildings. Stop in open area.
If you’re in a crowded public place, avoid panicking and do not rush for the exit. Stay low and cover your head and neck with your hands and arms.