Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
darimi:389al-Ḥakam b. Nāfiʿ > Shuʿayb b. Abū Ḥamzah > Ibn Abū Ḥusayn > Shahr b. Ḥawshab > Balaghanī

[Machine] Luqman the wise used to say to his son, "Oh my son, do not seek knowledge in order to show off to the scholars, to challenge the foolish, or to impress people in gatherings. And do not abandon knowledge out of arrogance and desire for ignorance. Oh my son, choose your companions wisely. If you see a group of people remembering God, then sit with them, for if you are knowledgeable, your knowledge will benefit you, and if you are ignorant, they will teach you. Perhaps Allah will bless you with His mercy through them and grant you their righteousness. But if you see a group of people who do not remember God, then do not sit with them, for if you are knowledgeable, your knowledge will not benefit you, and if you are ignorant, they will increase you in ignorance. Perhaps Allah will expose them to punishment, and you will befall the same fate."  

الدارمي:٣٨٩أَخْبَرَنَا الْحَكَمُ بْنُ نَافِعٍ أَخْبَرَنَا شُعَيْبُ بْنُ أَبِي حَمْزَةَ عَنِ ابْنِ أَبِي حُسَيْنٍ عَنْ شَهْرِ بْنِ حَوْشَبٍ قَالَ بَلَغَنِي

أَنَّ لُقْمَانَ الْحَكِيمَ كَانَ يَقُولُ لِابْنِهِ «يَا بُنَيَّ لَا تَعَلَّمِ الْعِلْمَ لِتُبَاهِيَ بِهِ الْعُلَمَاءَ أَوْ لِتُمَارِيَ بِهِ السُّفَهَاءَ أَوْ تُرَائِيَ بِهِ فِي الْمَجَالِسِ وَلَا تَتْرُكِ الْعِلْمَ زُهْدًا فِيهِ وَرَغْبَةً فِي الْجَهَالَةِ يَا بُنَيَّ اخْتَرِ الْمَجَالِسَ عَلَى عَيْنِكَ وَإِذَا رَأَيْتَ قَوْمًا يَذْكُرُونَ اللَّهَ فَاجْلِسْ مَعَهُمْ فَإِنَّكَ إِنْ تَكُنْ عَالِمًا يَنْفَعْكَ عِلْمُكَ وَإِنْ تَكُنْ جَاهِلًا يُعَلِّمُوكَ وَلَعَلَّ اللَّهَ أَنْ يَطَّلِعَ عَلَيْهِمْ بِرَحْمَتِهِ فَيُصِيبَكَ بِهَا مَعَهُمْ وَإِذَا رَأَيْتَ قَوْمًا لَا يَذْكُرُونَ اللَّهَ فَلَا تَجْلِسْ مَعَهُمْ فَإِنَّكَ إِنْ تَكُنْ عَالِمًا لَا يَنْفَعْكَ عِلْمُكَ وَإِنْ تَكُنْ جَاهِلًا زَادُوكَ غَيًّا وَلَعَلَّ اللَّهَ أَنْ يَطَّلِعَ عَلَيْهِمْ بِعَذَابٍ فَيُصِيبَكَ مَعَهُمْ»  


See similar narrations below:

Collected by Dārimī
darimi:393Muḥammad b. Aḥmad > Sufyān > Dāwud b. Shābūr > Shahr b. Ḥawshab

[Machine] "Luqman said to his son: 'O my son, do not seek knowledge to boast to the scholars, argue with the ignorant, show off in gatherings, or abandon knowledge in arrogance and desire for ignorance. And when you see people who do not remember Allah, sit with them, for if you are knowledgeable, your knowledge will benefit you, and if you are ignorant, they will teach you. Perhaps Allah will guide them through His mercy and you will be blessed with it too. And when you see people who do not remember Allah, do not sit with them. If you are knowledgeable, your knowledge will not benefit you, and if you are ignorant, they will increase you in deviation and heedlessness. Perhaps Allah will reveal His displeasure upon them and you will be affected with them.'"  

الدارمي:٣٩٣أَخْبَرَنَا مُحَمَّدُ بْنُ أَحْمَدَ حَدَّثَنَا سُفْيَانُ عَنْ دَاوُدَ بْنِ شَابُورَ سَمِعَ شَهْرَ بْنَ حَوْشَبٍ يَقُولُ قَالَ

لُقْمَانُ لِابْنِهِ «يَا بُنَيَّ لَا تَعَلَّمِ الْعِلْمَ لِتُبَاهِيَ بِهِ الْعُلَمَاءَ وتُمَارِيَ بِهِ السُّفَهَاءَ وَتُرَائِيَ بِهِ فِي الْمَجَالِسِ وَلَا تَتْرُكِ الْعِلْمَ زَهَادَةً فِيهِ وَرَغْبَةً فِي الْجَهَالَةِ وَإِذَا رَأَيْتَ قَوْمًا لا يَذْكُرُونَ اللَّهَ فَاجْلِسْ مَعَهُمْ إِنْ تَكُ عَالِمًا يَنْفَعْكَ عِلْمُكَ وَإِنْ تَكُ جَاهِلًا عَلَّمُوكَ وَلَعَلَّ اللَّهَ أَنْ يَطَّلِعَ عَلَيْهِمْ بِرَحْمَتِهِ فَيُصِيبَكَ بِهَا مَعَهُمْ وَإِذَا رَأَيْتَ قَوْمًا لَا يَذْكُرُونَ اللَّهَ فَلَا تَجْلِسْ مَعَهُمْ إِنْ تَكُ عَالِمًا لَمْ يَنْفَعْكَ عِلْمُكَ وَإِنْ تَكُ جَاهِلًا زَادُوكَ غَيًّا أَوْ عِيًّا وَلَعَلَّ اللَّهَ أَنْ يَطَّلِعَ عَلَيْهِمْ بِسَخَطٍ فَيُصِيبَكَ بِهِ مَعَهُمْ»