Many sources (1, 2, 3) state that Linux operating systems have generally a smaller chance of getting infected/compromised by malware or spyware, and have some reasoning behind their claim. On the other hand, some sources (1, 2) say that Linux being safer against viruses is just a myth, and also have some reasoning behind their claim:
An article on quora.com states that Linux is safer:
Viruses that affect Linux computers are less common but they do exist. There's a partial list in this Wikipedia page: Linux malware
[...]
But the reality is that more people use Windows than Linux. Hackers who write viruses want to create the most mischief, so they focus their efforts on the operating system used by the most people. It's the popularity of Windows that makes it a more attractive target.
[...]
On the other hand, an article on sophos.com literally says that Linux security is rubbish:
We are well into the 21st century, but it is astonishing how people can still believe that Linux-based operating systems are completely secure. Indeed, “Linux” and “security” are two words that you rarely see together.
Just as some people believe Macs are immune to viruses, some Linux users have the same misconception – and who can blame them? After all, vendors have been telling them that for years. Only recently, Red Hat also decided to (finally) remove the label “virus-free” from the feature overview of Fedora Linux. Linux users are not OS X users, although when it comes to security, many of them have the same misconception that the latter had a few years ago.
[...]
I doubt that the latter mentioned article uses valid reasoning. Which stance is true - is Linux really better than Windows when it comes to frequency of malware/spyware, and possibly even other types of virus infections (and attacks)?