Step 1: Use the shape rule.
The shape of a molecule depends on how many bond pairs and lone pairs are around the central atom. This idea is called VSEPR theory. A linear shape means the atoms lie in one straight line.
Step 2: A linear shape needs two regions only.
For a straight line shape, the central atom should have only two regions of electrons and no lone pairs pushing it out of line.
Step 3: Look at carbon dioxide.
In $\text{CO}_2$ the carbon is in the middle. It makes two double bonds, one to each oxygen, and has no lone pairs. So the two oxygens sit on opposite sides in a straight line. This is linear.
Step 4: Look at water.
In $\text{H}_2\text{O}$ the oxygen has two bonds and two lone pairs. The lone pairs push the hydrogens down, so the shape is bent, not straight.
Step 5: Look at the other two.
In $\text{SO}_2$ the sulphur has one lone pair, so it is bent. In $\text{NH}_3$ the nitrogen has one lone pair and three bonds, so it is pyramid shaped. None of these are straight.
Step 6: Final choice.
Only carbon dioxide has two regions and no lone pairs, so it is the linear molecule.\[ \boxed{\text{CO}_2} \]