On the approximately 5 different models of Shimano disc brakes I've dealt with over the years, the caliper fixing bolts are M6 x 18.7mm, and they are socket head cap screws in non- bicycle parlance. This length of fixing bolt would be if you were using 160mm rotors in a post mount set-up. For systems using 180 or 203mm rotors, you'll need about 40mm of length on your caliper fixing bolts to get thru the caliper and the associated adapter.
At farm, home, or hardware stores in their bolt bins you will find in their metric section, "socket head cap" screws (they will have the blunt end like a bolt, but they are screws because they are used by screwing them into existing threads, not with an associated nut. That's then a bolt.) The closest length you'll get is 20mm, though some places may have 18mm M6 socket heads in stock. They'll also have 30 and 40mm lengths typically.
While you're there, purchase some blue Loctite 242 (aka, threadlocker blue) and follow the instructions for that using it on the caliper fixing bolts (well, they're screws, but Shimano calls em bolts) when you go to mount your caliper. And tighten to the recommended torque value range of 6-8 Newton-meters (50-73 inch-pounds).
Properly torqued fasteners with threadlocker will not "come loose" without mechanically assisted human effort. It's still a good idea to check the fastness of your calipers before every ride and recheck with a torque wrench every so often, especially after the first ride or two after install.