This morning I was reading letters exchanged between generals Grant and Lee just prior to Lee's surrender. In one letter Lee offers to meet Grant between the picket lines of the two armies at 10am the next day to discuss terms. This got me thinking about the kind of arrangements that must go into having such large opposing armies so close to each other for such large periods of time. So a few specific questions...
Thank you!
Tl; dr: Scouts/signals when not in direct contact, field entrenchments when in direct contact.
So, it's important to note that most of the time, the armies were not actually in heavy contact with one another. Much of the war in the east was spent with the two large armies glaring at one another across the Rappohannock or the Rapidan Rivers. Both armies were heavily entrenched, meaning that neither was going to try and attack the other directly (until Grant, of course). During this earlier period of the war, most offensive campaigns involved some form of misdirection or attempt to "steal a march" on the other guys. Sometimes it worked (Maryland Campaign), other times it didn't (Fredricksburg).
That said, as the war progressed the armies in the East became MUCH more heavily engaged, especially after Grant took over. Grant's Overland Campaign kept the Army of the Potomac and the Lee's Army of N.Virginia in close combat for something like 2 straight months, culminating in out-and-out trench warfare at Petersburg. During this time, both sides relied on entrenchment and fieldworks to defend themselves from attack. Entrenchments usually consisted of a trench/breastwork as well as some form of slashing or abatis to slow attacking troops (a similar role to that of barbed wire in the first world war)
The Confederates became especially good at creating very defensible fortifications in a very short time--you'll see examples of these kinds of entrenchments at N. Anna, Spotlysvania Court House, and Cold Harbor. Of course, once Grant had Lee's army pinned at Petersburg (Lee couldn't abandon the city without sacrificing the Confederate capitol at Richmond) he didn't really need to worry about losing contact, but still used pickets and cavalry to keep tabs on the Army of N. Virginia to ensure that it doesn't attempt to slip out of the fortifications.
In the West, the armies were often much further apart than in the East, simply because of the vast space that they for maneuvering, so scouting and picketing became even more important. I'm sure that the telegraph also played an important role, but I can't think of any examples off the top of my head.
Raiding was a common practice both while encamped and on the move. The usual goal of a raid was to disrupt enemy supplies, communication, or to generally harass and confuse the opposing armies. JEB Stuart's cavalry famously rode a complete circle around an entire Union army in 1962--and then did it again later the same year.
As for etiquette, I'm afraid I can't really speak to that, except to say that there was a lot of fraternization at Petersburg, usually between pickets hiding out in no man's land. Exchanging gossip, trading newspapers, that sort of thing.
further reading/sources
Hess, Earl J. "Trench Warfare under grant and lee"
Hess, Earl J. "In the Trenches at Petersburg"
Foote, Shelby. "The Civil War: A narrative" (vols 1-3)