I posted this as I have it in my notes, and it is a journal of what I thought about this question over several years.
The first three makkos, that involved the Nile and the sand of Egypt, were done by Aharon, not Moshe.
אמר אל אהרן: לפי שהגין היאור על משה כשנשלך לתוכו, לפיכך לא לקה על ידו לא בדם ולא בצפרדעים, ולקה על ידי אהרן:
The reason (Rashi in 7:19 from the Tanchuma 14) is because the Nile had protected Moshe when he was an infant,
אמר אל אהרן: לא היה העפר כדאי ללקות על ידי משה לפי שהגין עליו כשהרג את המצרי ויטמנהו בחול ולקה על ידי אהרן:
and the earth protected him by hiding the Mitzri that he had killed (Rashi 8:12 from the Tanchuma 14 and Medrash Rabba 10:7,) and therefore they did not "suffer" by his hand.
There is a similar idea expressed in the Gemara (BK 93b), "Don't throw mud into a well from which you've drunk."
אמר ליה רבא לרבה בר מרי מנא הא מילתא דאמרי אינשי בירא דשתית מיניה לא תשדי ביה קלא א"ל דכתיב (דברים כג) לא תתעב אדומי כי אחיך הוא ולא תתעב מצרי כי גר היית בארצו
It seems that this is expresses a gratitude, a sense of personal indebtedness, hakaras hatov, to these inanimate and insensate objects, which is difficult to understand. Many say that this is a mussar haskeil to us-if there is hakoras tov to objects, how much more so to people. This is fine, but does not explain why Moshe Rabbeinu felt this way toward the Nile and the dirt.
Of course, we can talk about how there was a dialogue between Moshe and the Yam by krias yam suf, or between Hashem and the yam when Hashem wanted the Yam to throw out the bodies of the Mitzrim, which shows that the Yam and other inanimates need to be convinced to do things. But I assume that is all allegorical, and would not explain hakoras tov. Maybe it helps to talk about the ‘Sar’ shel Yam or of the sand. Maybe we can use the idea of ‘ein kateigor ne’eso saneigor,’ although here it would be something like ‘ein saneigor ne’eso kateigor.’
My son Moshe sheyichyeh said (Jan 2000/5760) that the Nile and the sand were the way that Hashem manifested his Middas Harachamim, and so to Moshe they were the Yad Hashem. In other words, the object through which Hashem acts in the world is very similar to the way our own hands do our deeds. Thus, an object which Hashem used to do his will is like Hashem’s hand. So the Yam and the sand were, to Moshe, the hands of the Middas Harachamim.
If you want, you can say this a little differently. You can say that since Hashem had shown His Middas Harachamim through this object, the object is like a davar shebikdusha. An object that has been used for a mitzva or for kedusha gets chashivus of the mitzva or the kedusha and you have to be machshiv the object, the same is true when an object is used as a means of rachamim, it gets the chashivus of rachamim. This is similar to kavod Shabbos, for example. Since Hashem rested on Shabbos and was m’kadeish it, we have to be m’chabeid Shabbos. It is not Shabbos that we are being m’chabeid, it is the Ribbono Shel Olom that we are being m’chabeid.
When I spoke in Jan 24 ‘04/’64, this is how I said it:
This parsha teaches very interesting lessons about hakoras tov. First, we find that Moshe was not commanded to execute the first three makkos, because the yam and the sand had saved him, and he could not be the one to cause the to pervert their nature. How do we understand the idea of Hakoras Tov to an inanimate object? Second, we find that we cannot be ‘mesa’eiv’ Mitzrim, because they gave us a place to come to when we needed it. But they enslaved us afterwords, and tried to kill us!
We have to understand that gratitude, the feeling that I have to a person who has done good to me, that I hold him dear in my heart and look forward to an opportunity to return the favor, is logically identical with resentment and vengeance, where someone harms us and we hold resentment in our hearts and look forward to the opportunity to pay him back— with interest. But Hakoras Tov is a mitzvah, and a fundamental middah (to the extent that Chazal say that a person who is not makir tov will eventually be kofeir betovoso shel Hakodosh Boruch Hu), while the other is called ‘nekomo and netiroh’ and is an issur de’orayso. The Chinuch (451) explains why one should not take revenge:
משרשי המצוה שידע האדם ויתן אל לבו כי כל אשר יקרהו מטוב ועד רע הוא סיבה שתבוא אליו מאת הש"י, ומיד האדם מיד איש אחיו לא יהיה דבר בלתי רצונו ב"ה, על כן כשיצערהו או יכאיבהו אדם ידע בנפשו כי עונותיו גרמו לו והש"י גזר עליו בכך ולא ישית מחשבותיו לנקום ממנו כי הוא אינו סיבת רעתו כי העון הוא המסבב וכמו שאמר דוד ע"ה הניחו לו ויקלל כי אמר לו ה', תלה הענין בחטאו ולא בשמעי בן גרא
that one should remember that whatever harm comes to him is by Hashem’s will, and the actor is merely a stick in Hashem’s hand, and it makes no sense to be angry at a mere stick. So what logic will support the the mitzva of gratitude to fellow humans that did good to you, but still preclude being angry and taking revenge from fellow humans that did bad to you?
A possible answer is that when we receive good, we do not say we deserve it, but rather we thank Hashem for an undeserved chessed. When we receive bad, we know that it is not arbitrary, but instead comes to be memareik for an aveirah. If so, we must appreciate chessed as a gift, but view harm as the earned result of our own behavior. Therefore, we thank a ba’al chessed and disregard the ba’al avlah.
Another teretz is that we must emulate Hashem’s middos (and hope that Hashem acts toward us with middah keneged middah), as explained in the Tomer Devorah: therefore, we look at the good that is done, and are ma’alim ayin from the bad.
When I spoke again in Jan ‘05/Teiveis ‘65, I assayed a possible approach.
I have wondered elsewhere what the difference is between nekama, which is assur, and hakaras tov, which is vital. But when you realize that Moshe was makir tov to inanimate objects, you realize that hakoras tov is not gratitude to the other person for choosing to do something good to you, because then it would make no sense here. It must be a way of expressing hakoras tov to Hashem by being makir tov to the instrument, something like Moshe said. Or as I added, the same way we are m’chabeid Shabbos because Hashem rested on that day and was m’kadeish it, we are m’chabeid a person or an object that was used by Hashem as a shli’ach of His rachamim. (Of course, it is only good people that will be used by Hashem to further His middas harachamim, because m’galgelim zchus ahl y’dei zakkai.) If that’s true, we understand the difference between nekama and hakaras tov.
When I repeated this to my mother Shetichyeh, she made a very nice observation. Mitzvos are to inculcate middos tovos and adinus. Hakaras tov is a middah tovah v’adinah, while nekama is the opposite. This explains why every opportunity to express hakaras tov is valuable, while we avoid nekama wherever possible. Where nekama is has meaningful significance, such as, perhaps, tzaar haguf, or go’eil hadom, or from a goy, the need to inculcate middos tovos is no longer a factor. Note that this is not the usual teretz people say, that Moshe’s hakaras tov was meaningless and it was just an exercise in habituation of hakaras hatov. My mother's vort is different and better, though it might take a moment to see the difference. Her vort is that this itself was a valuable exercise in creating a midda tova, while the other teretz is that this was an empty gesture used to inculcate the habit of hakaras tov.
In Jan ‘06/Teiveis ‘66, I spoke again, and the way I said it was:
First three makos– how is it shayich hakaras hatov to inanimate objects?
Another kasheh– why isn’t it ASSUR to be makir tov according to the Chinuch? The same way a man who hits his thumb with a hammer doesn’t curse the hammer, and anyone who attacks the person who harmed him is showing he thinks the person is the cause, when in truth the person is only an instrument, a person who benefits from a matonoh, for example, should remember that mezonosov shel odom k’tzuvim meirosh hashonnoh, and he got absolutely nothing from the apparent benefactor!
Answer on both questions begins with answer on first question. Hashem uses objects to effect His din of schar v’onesh, of rachamim and din. An object that is used for tashmishei kedushoh or for a mitzvoh is to’un genizah. This is because the object represents, and becomes imbued with, the kedushoh or the chashivus mitzvoh. So we have to be m’chabeid the object. Similarly, an object that has been used by Hashem to effect his rachamim is TASHMISHEI RACHAMIM. It therefore calls for honor and respect in its capacity as tashmish rachamim.
If a person benefits another person, the beneficiary must view the benefactor as the means through which Hashem was m’racheim on him, and he has to show gratitude and respect. The person who benefited him is Hashem’s tashmish rachamim. But if Hashem is ma’anish someone through the actions of a rasha, the person has to be m’kabeil with ahava, and the person who did the act, the rasha through whom judgment was exacted, is TASHMISHEI DIN. But there is a difference between being m’kabeil b’ahavoh and commemorating the event. I don’t think that the whip beis din uses needs geniza. You don’t celebrate yesurim, but you do celebrate rachamim and yeshu’a and the objects through which they came about.
So we understand why it is assur to take nekama, but it is a mitzva to be makir tov.
We also understand why even inanimate objects have to be respected if they were used to carry out Hashem’s middas Rachamim.
On June 23, 2006, my nephew, Avi Feinstein, was in Chicago, visiting a child he had taken care of at Camp Simcha the year beforelast year, a child of seven with a severe skin problem that caused intense and unremitting itching. His condition required that Avi shower him and put medicine on him four times a day, and which prevented him, and Avi, from getting any sleep. Avi decided to visit the child because he was off from Yeshiva for a few days before going to his counselor’s job at a different camp, and the boy had called him almost every day since having him at camp. I asked him how the parents were m’kabel panim, and he said they were endlessly grateful, and even had offered to pay his airfare, which he declined. They know about Avi’s brother’s trouble and the challenges Avi had gone through, and that he had to leave Chicago a day early because the camp told him (after he made the ticket) that he had to be there two days before camp started, and so had to pay two hundred dollars extra on the ticket. They asked him whether he resented how the camp behaved. He answered, without thinking about how to couch it in less surprising terms, that it wasn’t them who did it, it was Hashem. What he meant was that whatever we experience in life is what Hashem wants us to experience. The means of having that experience really are irrelevant, so why would he resent their behavior? He would have had to have the experience anyway. I thought this was an excellent application of the idea of “lo sikom.”
I asked him the kashe, that if he feels that way, why would he ever be makir tov to a person who did a chesed for him? He answered that by a bad experience, the main reaction is “this needed to happen, and I have to think about why Hashem wants me to experience this.” Thoughts of nekama against the actor contradict the primary feeling of introspection. But in the case of a chessed, the feeling you should have is one of gratitude to Hashem. In that case, feelings of gratitude to the baal chessed do not contradict the proper primary emotion, and so are they are not only appropriate, they reinforce the feeling you should be having.
Note:
There is a Rif that is relevant to this question, as follows.
The Shittah in BK 92b brings a story about the Rif that can be read to indicate that he, too, felt this sense of gratitude to a place or a thing:
וכתב תלמיד אחד מתלמידי ה״ר יוסף הלוי ז״ל אבן מיגש וז״ל מועתק מלשון ערבי: אמרו בסוף החובל
בירא דשתית מיניה לא תרמי ביה קלא, פירוש: הבור ששתית ממנו לא תשליך בו אבן או דבר אחר, כלומר לא
תזלזל בו ולא תגמול אותו רע אחר שנתהנית ממנו. וזה על דרך משל לשאר הדברים, שמי שבא לאדם ממנו איזו
תועלת או נהנה ממנו אין ראוי לו לעשות שום מעשה שיבא לו נזק ממנו, ובבר הביאו שם בגמרא על ענין זה
משלים ופסוקים מענין מכות מצרים וגלו הסבה שנעשו קצתם על ידי אהרן ע״ה, וסיפר רבינו ז״ל על רבו הריא״ף
ז״ל שאירע לו ענין זה עם איש אחד ולא רצה לדון אותו כלל כדי שלא ידון אותו במה שיבא לו היזק ממנו ונמנע זה מניעה גמורה, וזה שהוא ז״ל חלה ונכנס אצל אדם אחד במרחץ שהיה לו בביתו ונתהנה מהמרחץ הנזכר, אחר כך זימן אותו שישב אצלו עד שיבריא וכבד אותו הרבה ועשה עמו טובה והבריא, ובהמשך הזמן על האיש ההוא מטה ידו וירד מנכסיו ונשבר בערבונות וזולתם ונתחייב לתת ממון לבעלי חובות וירד עד שהוצרך למכור המרחץ הנזכר ולשום אותו לבעלי חובותיו, ואמר רבינו יצחק ז״ל ״לא אדון ולא אורה במרחץ הזה לא במכר ולא בשומא ולא בשום דבר המתיחד בו לפי שנתהניתי ממנו״.
ואם היה זה בדומם שאין לו הרגשה, כל שכן וקל וחומר בני אדם המרגישים בהיזק ובתועלת שיהיה זה שנוי לעשותו
והעושהו יוצא משורת המוסר ודרך ארץ. ואמר, ואפשר לפרש במה שאמרו לא לידון איניש לא למאן דרחים ליה
ולא למאן דסני ליה, שיהיה סיבת מניעתם ז״ל לדון למאן דרחים לשתי סיבות. האחד שלא יטה לזכותו והשנית שאם
אפשר שיציל את נפשו וידון אותו כפי שורת הדין — היה בזה משלם רעה תחת טובה. ואם היה זה במי שקבל הנאה מבשר ודם — כל שכן וקל וחומר באלוה ית׳, שממנו נשפע הטוב הגמור, שראוי להודות לו הודאה גמורה ולא יעשה מה שיקניטנו ולא מה שהוא שנוי לו. עד כאן לשונו
The reason I read it as if the Rif was showing hakaras hatov to the merchatz is because Reb Moshe in a teshuva rejects the idea that the Rif was showing hakaras hatov to the owner of the merchatz. He says that it is not hakaras hatov to refuse to judge him in a case of monetary liability. On the contrary, you're doing him a favor by divesting him of money that he shouldn't have. Igros CM 10:
הטעם שכתב מטעם בירא דשתית מיניה לא נכון כלל דלחייב למי שתייב ממון ע״פ דין אין זה שום רעה להאדם אלא אדרבה טובה גדולה כמפורש בסנהדרין ז׳ דאזיל מבי דינא שקל גלימא ליזמר וליזיל באורחא, ולעיל מזה בברייתא (דף ו׳) שרבי אמר על ויהי דוד עושה משפט וצדקה אע״פ שלא שילם מתוך ביתו זהו משפט וצדקה משפט לזה שהחזיר לו ממונו
וצדקה לזה שהוציא גזילה מתה״י׳ ואיך יאמר שהוא כשדיית קלא בבירא דשתי מיניה, אך אולי מדין שוחד החמיר שהוא רק ממדת חסידות וכוי׳ ואין אצלי הספר לעיין בו אבל כפ״מ שהבאת דבריו לא נכון כלל עכ״ל
הטעם שכתב מטעם בירא דשתית מיניה לא נכון כלל דלחייב למי שתייב ממון ע״פ דין אין זה שום רעה להאדם אלא אדרבה טובה גדולה כמפורש בסנהדרין ז׳ דאזיל מבי דינא שקל גלימא ליזמר וליזיל באורחא, ולעיל מזה בברייתא (דף ו׳) שרבי אמר על ויהי דוד עושה משפט וצדקה אע״פ שלא שילם מתוך ביתו זהו משפט וצדקה משפט לזה שהחזיר לו ממונו
וצדקה לזה שהוציא גזילה מתה״י׳ ואיך יאמר שהוא כשדיית קלא בבירא דשתי מיניה, אך אולי מדין שוחד החמיר שהוא רק ממדת חסידות וכוי׳ ואין אצלי הספר לעיין בו אבל כפ״מ שהבאת דבריו לא נכון כלל עכ״ל