Looking for the name of this optical sensor detecting beam interruption
To add to what Olin said, the sensors are also known as "photointerrupters" when searching some of the distributors.

There are at least two major types of these sensors: Logic output and transistor output. Logic being the type that drives it's own output signal, and the transistor type acting more like a switch. 



As for:


  I have a box moving on rails and it has 5 positions; the range is about 1m, precision about 0.5cm. Are these sensors the best way to go?


I don't see how you're going to use these sensors to detect a box's position if you want a "small" sensor. The beams are between two appendages about 1cm apart. So unless your box will fit in a 1cm space, you may want a different approach.

Note that you can use the same concept over a larger area, you just need separated emitters and "receivers". The kind used in the floppy disk drives combine the two into a small package. Instead, you'll probably want an emitter on one side of the box, and the receiver on the other.