I've seen how to do this on linux, however is there a way to do it in OSX?
I've accidentally ran chmod -R 777 /
Looking for how to undo this. Thank you
You won't be able to fix it for everything.
There's no way of "undoing" a chmod,sshort of going through a known-good installation and checking/reproducing permissions. The easiest way out for you is a complete re-install.
As Jason says, Disk Utility should get most of the OS's stuff. For the rest, perhaps you could assume defaults of 644 for files, 755 for directories, except in /Users where 600 and 700 might be more appropriate? This won't put everything exactly as it was, but it should keep most stuff working and you can fix up special cases as you find them.
The best order would probably be
I assume the Disk Utility will do things like making the contents of /bin executable.
This all off the top of my head and untested; I'd recommend testing the chmods on a small subtree before running them across the whole disk.
If you can reinstall that might be better for longterm peace of mind. I'd happily perform a kludge like this on one of my test boxes, but maybe not on my personal workstation.