This animal behavior is called instinct.
Animal instinct is a form of primitive consciousness. Even without logical reasoning, animals are able to direct their attitudes in a natural way. This can be observed in all animals. For example, ducklings when they are born approach any nearby object because they think it's Mommy's duck. Most animals are already born with the instinct of survival, they know by instinct to determine a dangerous situation.
Men also have this instinct, but they also rely on intelligence to assist them in survival.