With regards to the virtue of seeking knowledge with a pure intention, the Shaykh Muhammad ibn Saalih al ‘Uthaymeen rahimahullaah comments:
Rather some of the scholars say that seeking knowledge with a pure and sincere intention is more excellent than fighting in the Path of Allaah because fighting in the Path of Allaah contains only blocking the enemies and fighting against them such that there is no fitnah and that the Religion is entirely for Allaah.
However seeking knowledge is something that the whole ummah (Muslim nation) is in need of, such that they can worship Allaah upon clear-sightedness; and (even) the people who fight (in the Path of Allaah) are in need of it such that they know how they should fight and how they deal with the war booty and how they advance and how they retreat.
So the ummah is in need of knowledge, in every situation and at every moment.
Therefore I urge you, O young people, to turn towards and have diligence upon seeking Sharee’ah knowledge, and to have purity and sincerity of intention in that – in that you intend by it seeking closeness to Allaah, the Perfect and Most High, by obeying His command; and that you intend protection of the Islaamic Sharee’ah and defending it and spreading it among the servants (of Allaah).
Then you attest to the truthfulness of this intention through your actions, in worship and manners and dealings (with other people).
Quoted in Wasaayaa wa tawjeehaat li tullaab il ‘ilm pages 341, translated by Nasser ibn Najam
So if someone says to you: How does ikhlaas in seeking knowledge come about? It comes about through a (number) of matters:
1 – It is that in doing that (seeking of knowledge), you have as your intention that you are complying with Allaah’s command because Allaah, the Most High, commanded with that (seeking of knowledge). So He said: “Have knowledge that none has the right to be worshipped except Allaah. And seek forgiveness for your sin.” (Soorah Muhammad (47) aayah 19) And he – sall Allaahu ‘alaihi wa sallam – encouraged [us] upon knowledge; and encouraging upon a matter necessitates loving it and being pleased with it and commanding with it.
2 – It is that in doing that, you intend to preserve the Sharee’ah (Islamic legislation) of Allaah, because preserving the Sharee’ah of Allaah occurs through learning, and it comes about through preserving [it] in the chests [of people], and it comes about through writing down, writing down the books.
3 – It is that in doing that, you intend to protect the Sharee’ah and defend it, because were it not for the people of knowledge, then the Sharee’ah would not have been protected and no one would have defended it. And therefore you find, for example, Shaykh ul Islaam ibn Taymiyyah and other than him from the people of knowledge who resisted and blocked the people of innovation and clarified the false and futile nature of their innovations, we see that they (these people of knowledge) attained a great deal of good.
4 – It is that in doing that, your intention is to be following the Sharee’ah of Muhammad – sall Allaahu ‘alaihi wa sallam – because you are not able to follow his Sharee’ah until you have knowledge of this Sharee’ah.
(From The Explanation of the Etiquette of Seeking Knowledge of Shaykh al Uthaymeen, p14, translator Nasser ibn Najam)