Imam Hasan al-Basri (may Allah have mercy on him) said: People sought knowledge even though, by means of it, they did not intend Allah nor what is with Allah. He said: They continued to acquire knowledge until their intention became sincere, and they intended Allah and what is with Allah.
Hadith Referenceسنن دارمي / مقدمه / 371
Hadith Gradingتحقیق (حسین سلیم أسد الدارانی):حسان بن مسلم ما وجدت له ترجمة وباقي رجاله ثقات. وما وجدته مسندا في غير هذا الموضع، [مكتبه الشامله نمبر: 372]
Hadith Takhrijاس روایت میں حسان بن مسلم کے بارے میں معلوم نہ ہو سکا کہ وہ کون ہیں، باقی رواة معروفين وثقات ہیں۔ دیکھئے: [جامع بيان العلم 1383 ذكره بدون سند]
Brief Explanation
(Commentary on Hadiths 368 to 371) From these narrations, it is established that even if, in the beginning, there is no particular objective or intention for acquiring knowledge, the light of knowledge itself creates sincerity and devotion to Allah (ikhlas wa lillahiyyat). It should be clear that by "knowledge" here is meant the knowledge of the Book and the Sunnah.