If you're looking to buy filters, lens caps, or hoods, you need to know the diameter of your lens. But you don't need to break out a ruler. You just need to know the code.
Lens Diameter vs Focal Length vs Aperture
The lens diameter isn't the same thing as saying a 50mm lens or a 70-200mm lens--that's the focal length. Nor does it have anything to do with aperture settings like f/1.8 or f/5.6.
Lens diameter is the physical measurement of the diameter of the front-most part of the lens. With DSLR lenses, it's often threaded to allow filters and lens hoods to screw in. On mirrorless and Micro Four Thirds lenses, some have threads for filters and some don't.
If you have a DSLR lens with a focal length of 50mm, it doesn't mean you'd use a 50mm filter--they're referring to two different measurements.
Some of the common sizes for the diameter of DSLR lenses are 49mm, 52mm, 58mm, 62mm, 72mm, and 77mm. A 77mm filter won't fit on a lens with a 72mm lens diameter (you can sometimes use an adapter, but that introduces other problems).
How to Find the Lens Diameter
But so long as you know what to look for, it's usually easy to find out because it's often printed right there on the lens. It might not be easy to spot, because on some lenses it's etched into the plastic or metal and not easy to see, but there's a good chance it's there. It's one of the few standards that camera manufacturers stick to. So whether it's a Nikon lens, a Canon lens, a Sigma lens, or so on, the lens diameter is marked the same way.
There's a code, but it's a simple one. And once you know what to look for, it's easy. What you're looking for is something using the geometric symbol for diameter: ø. So, for example, if you see ø52 the lens has a diameter of 52mm, so you'd look for a 52mm filter. Or if you see ø77 it's a 77mm diameter. And so on.
Lens Diameter Examples
Here are some examples of what you're looking for. In these cases, it's clearly marked in white text. Some manufacturers aren't quite so considerate though--sometimes you have to look for lightly etched numbers. Sometimes it's on the outside of the lens, and sometimes it's just inside the rim. Occasionally a lens won't have it marked, in which case your best bet is either trial and error or trying to track down a copy of the user manual or lens specs on the manufacturer's website.
This one takes 72mm filters.
And this one takes 58mm filters.
If Your Lens Doesn't Have the Lens Diameter Marked
Some lenses don't have the lens diameter marked on them. In those cases, it's time to break out a ruler with millimeters marked on it. Or, better yet, some calipers.
What you want to measure is the distance across the widest part of the lens (ie. going through the middle of the circle) starting from the inside rim of the threaded area on one side to the inside rim of the thread on the other side. That then provides the maximum diameter of a filter that will screw into that thread.
Because it's a rather imprecise way of doing it, here are some common diameters used in DSLR lenses (all are in millimeters):
37, 39, 40, 40.5, 43, 46, 49, 52, 55, 58, 60, 62, 67, 72, 77, 82, 86, 95.
Of those, the ones between 49mm and 77mm tend to be most common for DSLR lenses. If you end up with a measurement for a size that you can't find a filter for, chances are the measurement is a touch off. The major filter manufacturers don't make a 50mm filter size, for example, so in that case you're probably actually after a 49mm filter.
If Your Lens Doesn't Have a Filter Thread
Most DSLR lenses have filter threads, but not all of them. Some lenses, especially on the cheap end of the market, just aren't designed for them. But even very expensive specialty lenses can lack a filter thread. Some of them, like extreme wide-angles or fisheyes, often have a very curved front element that doesn't allow a flat filter. Others, like very long telephoto lenses might have a very large front element that makes a filter impractical. In some cases, they'll take filters on the other end of the lens at the mount point. If your lens doesn't have that option and you still want to use filters, something like the Cokin filter system is worth looking into.