The blessing over an earthquake:
Upon [feeling] an earthquake one is required to recite a blessing. [This applies to an earthquake of any magnitude, so long as it is felt. The reason the Sages established a blessing is because earthquakes are frightening events which convey a powerful message to the worlds inhabitants regarding G-d’s power and control of earth. Hashem created these events to shake people up from their current state of affairs and begin to fear Him. The Talmud accords various causes to earthquakes, including: 1) Hashem drops two tears into the sea when he sees the pain of his children in exile and the sound causes the earth to shake.; 2) Hashem claps His hands to relieve his anger and the sound causes the earth to shake. 3) Hashem lets out a groan of anger and the sound causes the earth to shake. 4) Hashem kicks the heavens to wake up the inhabitants. 5) Hashem presses His feet under the Kisei Hakavod and this causes the earth to shake.]
Which blessing: One is required to recite the following blessing: “Baruch Ata Hashem Elokeinu Melech Haolam Oseh Maaseh Bereishis.” Alternatively, if one chooses, he may recite the blessing of “Baruch Ata Hashem Elokeinu Melech Haolam Shekocho Ugvuraso Malei Olam.”
Within how much time of the earthquake must the blessing be recited? The blessing over the earthquake must be said while it is taking place, or within Kdei Dibbur of feeling it [which is the amount of time it takes to say the three words of “Shalom Alecha Rebbe”, which is a mere 2-3 seconds]. If the earthquake has already ended and one did not say the blessing within that time, then he is not to say a blessing on the past. However, other Poskim argue [and rule the blessing may be said even later on]. Practically, one is to say the blessing without saying Hashem’s name [i.e. Baruch Shekocho Ugivuraso Malei Olam]. Accordingly, if one was unable to say the blessing immediately after feeling the earthquake, such as he was using the bathroom upon hearing/seeing it, then he is to recite the blessing later on without Hashem’s name.
Immediately after feeling an earthquake, one is to say the blessing of “Baruch Ata Hashem Elokeinu Melech Haolam Oseh Maaseh Bereishis” or “Shekocho Ugvuraso Malei Olam.” If the blessing was not said within 2-3 seconds, it is to be said without Hashem’s name, as follows: Baruch Shekocho Ugivuraso Malei Olam.
How often is the blessing over an earthquake to be said?
Often, earthquakes come with before and aftershocks, thus causing a series of earthquakes within the span of a day or a number of days. Each time a new earthquake occurs, a new blessing is to be recited, [even on the very same day] if one removed his mind from the previous earthquake. Meaning, if an earthquake occurred that day and a blessing was recited and after some time passed another earthquake occurred, a new blessing is to be said if one removed his mind from the previous earthquake event. If, however, one’s mind was still thinking about it [such as would occur if the earthquake caused personal damage, or widescale devastation], then a new blessing is not recited.
A Segula to stop earthquakes:
There is a great secret that can be learned from the prophet Yeshayah who prior to describing the shaking [of the doorposts of the Heichal], stated the verse “Vekara Zeh El Zeh Veamar.” This is coming to teach us that whenever one feels an earthquake he is to recite the following verse three times “Vekara Zeh El Zeh Veamar Kadosh Kadosh Kadosh Hashem Tzevaos Malei Kol Haretz Kevodo.” By doing so, the earthquake will cease!
There exists a tradition recorded in Sefarim and Poskim that Jerusalem residents will never be harmed of an earthquake. In the year 5687/1927 on the 11th of Tamuz a great earthquake occurred in Jerusalem and its surrounding areas. There were many miracles and wonders that occurred. While walls and buildings collapsed, no one in Yerushalyim was injured. However the surrounding gentile villages did not share the same fate, as they suffered from many casualties. Everyone saw the great miracle Hashem made for the Jewish people, and it caused many to believe in G-d and Divine providence.
Famously, the city of Tzefas suffered from a deadly earthquake on January 1st 1837, in which the city was completely destroyed and devastated. Estimates asses that the earthquake was approximately 6.8 on the Richter scale. The earthquake killed approximately four thousand Jews r”l in Tzefas, and another 700 in Tiberius. The Chasam Sofer in his Sefer Toras Moshe attributed the earthquake to the fact the Jews at the time shunned living in Jerusalem, the holiest city of G-d, and chose rather to live in Tzefas. Certainly, today however, the great development of the city of Jerusalem and the tremendous amounts of Torah and Chesed that exist in both cities will stand to protect both cities from any such events reoccurring Heaven Forefend.
Learn the science behind earthquakes:
A fun children’s video, good for adults as well: https://613tube.com/watch/?v=dJpIU1rSOFY
 Seder 13:15 “On the Zevaos which is a Reidat Adama/earthquake”; Luach 12:24; Michaber 227:1; Haeshkol 1:23; Tosafus Rid and Riaz; Rokeaich 227; Mishneh Brachos 54a “Zevaos” and Gemara Brachos 59a “Goa” and Rashi ibid “It means an Earthquake” [See Halacha Berurah 227 Birur Halacha 6 for all the opinions on this matter]; Yerushalmi Brachos 9:2; See Piskeiy Teshuvos 227:2; Halacha Berura 227:5
 One must actually feel the earthquake. Simply hearing about it does not suffice.
 Shevet Hakehasi 5:46; Piskeiy Teshuvos ibid; Halacha Berura ibid in name of his father in Chazon Ovadia
The statistics: Of the close to 1,000,000 earthquakes that occur each year throughout the world, only a small percentage can be felt [about 30,000, above 2.5 magnitude on the Richter scale], and an even smaller fraction causes damage [about 500, above 5.5 magnitude on the Richter scale]. See here for statistical details: http://www.geo.mtu.edu/UPSeis/magnitude.html
 Rabbeinu Manoach Brachos 10:14
 Abudarham Brachos Shaar Shemini; Elya Raba 227:4; Halachos Ketanos 1:38
 Brachos 59a
 Admur Seder ibid; Luach ibid; Michaber ibid; Rif Brachos 43; Rambam Brachos 10:14; Rava Brachos 59a as explains Tosafos
 Rava Brachos 59a as explains Tosafos that one may choose which blessing to recite; Kitzur SHU”A 60:2 only records this blessing; The Mefarshim explain the reason this blessing is to be said is because earthquakes are felt throughout the world, in a great distance from the epicenter. [Rashi Brachos ibid; Sefer Hamichtam 58b]
 Mishneh Brachos 54a writes that one is to recite this blessing
 Seder 13:17 regarding thunder and lightning; Birchas Habayis 30:1 regarding earthquakes; Piskeiy Teshuvos 227:2
 Admur 206:3; Kneses Hagedola 206; Olas Tamid 206:3; M”A 206:4; Elya Raba 206:5; Chesed Lealafim 206:3; Ben Ish Chaiy Balak 3; Kaf Hachaim 206:15; 582:9
Other Opinions: Some Poskim rule that it contains four words “Shalom Aleichem Rebbe Mori”. [Beis Yosef in name of Shivlei Haleket; Levush; Taz 206:3; P”M 487]
 1st opinion in Seder ibid; Luach ibid; Implication of Michaber 227:3; Ran Pesachim 4a based on Yerushalmi Brachos 9:2; Olas Tamid 227:2; Birchas Avraham 4:191; Elya Raba 227:6 in end that so is implication of Poskim; Nehar Shalom 227:4; Mamar Mordechai 227:5; Machatzis Hashekel 227:2; Chayeh Adam 63:9; M”B 227:12
 2nd opinion in Seder ibid; Luach ibid; Taz 227:2; Opinion of Elya Raba 227:6; See Admur 46:3 regarding Birchas Hashachar,
 So is the custom upon saying a blessing without Sheim Umalchus
 Admur in Seder and Luach ibid
The reason: As Safek Brachos Lihakel. [Admur Seder ibid]
 Admur ibid
 Maharam Chaviv 34; Yad Ahron on Tur 227:4; Birkeiy Yosef 227:6; Shaareiy Teshuvah 227:1; Chesed Lealafim 227:24; Kaf Hachaim 227:3; Piskeiy Teshuvos ibid; Halacha Berurah ibid; Halachos Ketanos 1:38 that it follows the same law as thunder; See regarding thunder and lightning: Seder 13:16; Luach 12:25; Michaber 227:2; Rosh Brachos 9:13; Rabbeinu Yona Brachos; Rif Brachos 43b; Yerushalmi Brachos 9:2; Ketzos Hashulchan 66:13; Piskeiy Teshuvos 227:7; Halacha Berura [Yosef] 227
 Implication of Shaareiy Teshuvah ibid; Piskeiy Teshuvos ibid
 Mor Uketzia 227 in name of Sefer Yuchsin; Piskeiy Teshuvos ibid
 Yeshayahu 6:3-4
 Peri Hadama 4:6; Kaf Hachaim 576:26; Avos Derebbe Nasan
 Kaf Hachaim ibid
 Toras Moshe Hesped p. 59