Definitely what you have heard about Linux and Ubuntu is right. But you cannot say that Linux, Ubuntu and other Unix based operating system are completely free from virus attack.
Virus, Malware, Spyware, Trojan etc. are created to threat the large number of population. As you might be knowing that Windows Operating Systems are most easier and popular among users. Largest population choose Microsoft Windows Operating System as these are easy to use.
Therefore, creators of Virus, Malware, Spyware and Trojan etc. gets more client to attack in case of Windows based operating system. But if they create Virus for Linux and Ubuntu, then they will get comparatively less client to attack.
Obviously, You will also choose more beneficial way.
Thus, you can say that Virus, Malware, Spyware and Trojan etc. are mostly created for Windows based Operating System while keeping eye to target a large number of users.