So I was thinking about this and I could not come up with an answer on my own. How did soldiers, especially the ones on WWI and WWII knew the frontlines? Would they know if they went too far into enemy territory?( I know there is one on WWI with american soldiers who were lost in argonne forest). Also how did they know they had to retreat and to where? For example on WWII how did the germans know where to retreat and stuff on the eastern front? Considering it is a very big terrain.
I think you're thinking of frontlines in a more formalised way than they ever existed except perhaps in the most static forms of warfare like trench warfare. A frontline is a rough working reality, it is produced by soldiers not enforced by it. The frontline is where the soldiers advance or retreat to by definition. You advance as far as you must to achieve an objective or otherwise just as far as you can. You retreat as far as you are forced to or you must in order to prevent encirclement or being overrun. At various levels of conflict the positions you attempt to take up in advance or retreat are based on objectives at higher levels of combat and advantages gained based on your current level, assigned and intermediate goals.
If I've missinterpreted what you mean feel free to explain to me.
For my sources Im going to rely on three books; Guy Sajer’s Forgotten Soldier, a memoir of a German private in the Grossdeutschland division in the Eastern front; Lion Rampant, the memoir of a British platoon commander in the 15th Scottish Division in Northwest Europe, and Japan at War, an Oral History, which is a collection of interviews with a selection of Japanese people from WWII. So it should give a decent perspective.
In general soldiers did not have a clear idea of what was outside of their immediate area. The main concern of soldiers in WWII, and maybe all wars before, was food, drink, and immediate survival. Your question asks whether soldiers would know who was on their left or right and the answer is they wouldn’t, but if they were told everything was OK then they would have to believe it.
They had to believe it because they had to do as they were told. Guy Sajers book covers a thousand mile retreat across Russia and yet the author knows nothing of the strategic situation, except the names of rivers and cities, and also dismay that Germany is retreating.
The author of Lion Rampant spends New Year in a town divided by a canal with Germans on the other side. Both sides try to infiltrate across the canal. It wasn’t known who was to their left or right, only know that the Battalion was told to move to this place and to do this thing. Earlier in the book the soldiers get a sense of their place in the mission by recognising insignia, of either roadsigns and other soldiers, dead or alive.
Soldiers would know whether they were at the front or rear area because they were told. In both books the experience of rear and front is markedly different.
A semblance of direction is common amongst large groups. As the Japanese withdrew on the Kokoda trail, from one side of New Guinea, they ran out of food. And then water. And then military discipline broke down. Cannibalism became a last resort to many. And yet in such conditions, and with a total breakdown in military discipline, these men still knew which direction to go in. They had a vague sense that there were Australians behind them and food in front, so they kept going, walking barefoot without food or water on a 300 mile jungle track.
In summary soldiers understood their situation through a sense of soldierly intuition and also from their commanding officers.