How animals know which is carnivorous and herbivorous?
They probably don't know and probably don't need to. They tend to run away from potential danger and predators in the same evolution environment because those who don't run away will have fewer offsprings that exhibit similar behaviors.

If an animal suddenly sees a predator that his ancestor has never seen before, then it may not run away from it, to its own detriment. Dodo Bird thought humans were harmless.