The Messenger of Allah ﷺ shaved his head, and a group of his companions also shaved their heads, while others shortened their hair. Ibn Umar said that the Messenger of Allah ﷺ said, "May Allah have mercy on those who shave their heads," once or twice, then he added, "and on those who shorten their hair."
حدثنا قتيبة حدثنا الليث عن نافع
حلق رسول الله ﷺ وحلق طائفة من أصحابه وقصر بعضهم قال ابن عمر إن رسول الله ﷺ قال رحم الله المحلقين مرة أو مرتين ثم قال والمقصرين
Agreed upon by both, and Muslim narrated it in the Hajj chapter, "the section on the superiority of shaving the head over trimming and the permissibility of trimming," hadith no. 1301, from Qutayba, and Bukhari in the Hajj chapter, "the section on shaving and trimming at the time of leaving the state of ihram," hadith no. 1727, from the hadith of Layth bin Saad, with the same wording.This subject is also reported from Ibn Abbas [Ibn Majah, hadith no. 3045], Umm Husayn [Muslim, hadith no. 1303], Marib [Ahmad 6:393 and Humaydi, hadith no. 931], Abu Saeed [Ahmad 3:20, 89], Abu Maryam (Malik bin Rabia) [Ahmad 4:177], Habashi bin Junada [Ahmad 4:165], and Abu Hurairah [Bukhari, hadith no. 1728, and Muslim, hadith no. 1302].