I visited Appomattox Courthouse over the Summer and had a fantastic tour guide. He mentioned that a slave girl was killed by cannon fire prior to the Confederate surrender. It made me wonder why she was even there when the town was surrounded by Union and Confederate soldiers? Did civilians attempt to stay and "protect" their belongings even though a battle was about to be fought? Were the civilians so out of the loop that they had no idea these conflicts would occur until soldiers were seen in the distance?
Well, like most things during the American Civil War (ACW), this all depends on the region and the time period we're talking about. In general, though: yes, if civilians knew that a battle was about to take place near their home, farm, or city, they usually fled to a safe distance to wait it out. City-wise, we see this in Fredericksburg where the Confederate-sympathetic townsfolk largely fled from the advancing Union army, which did indeed requisition or otherwise occupy whatever and wherever they wanted during the battle (which took place just outside of town, but still saw the Union army in the city-proper for much of the battle). Gettysburg likewise saw a lot of the town's population fleeing during the hottest part of the three days of battle (though some did stay behind).
If it was just a person's house or farm, if it was going to be in the line of fire, or in a strategically important part of the field, these houses or barns (etc) were usually taken over by force by whatever army controlled that part of the field. You'll read a lot of stories about people's houses being converted into temporary headquarters for a general and his staff, or barns and other houses being converted into make-shift hospitals. If a person had sand enough to wait it out and stay behind in these situations, they were often forcibly removed or very sternly "asked" to vacate the premises for their own safety until hostilities concluded. This was because most of the time in the ACW, if you take a battle like Shiloh, Antietam, the Wilderness Campaign, or even Chickamauga: these battles took place pretty well outside of the nearest town, so whatever scattered houses or farms nearby were quickly converted into command headquarters or hospitals whether the residents agreed to it or not. So it was kind of a moot point, for the residents; after all, what are you going to do, tell 20,000 armed people that they CAN'T stay?
Still, earlier in the war, the Union was a lot more sheepish about disrupting property or citizens. Lincoln gave strict order early in the war to avoid any unnecessary destruction or disruption of civilian property. The idea was that the war would be over in short order, and you didn't want to anger citizens who might already be inclined towards rebellion. As a result, if it was possible, Union forces tried to avoid damaging civilian property or otherwise bothering civilians. This didn't last beyond 1862, however, and the turning point might be argued to have been when Lincoln agreed to allow the Union army to take in escaped slaves as "contraband of war." Before this decision, the army was instructed to return runaway slaves to the citizens of the Confederacy, but it was successfully argued by Gen. Benjamin Butler that these slaves represented a valuable wartime commodity for the Confederates, and returning them would be akin to returning rifles or munitions.
Sorry to get a bit off-topic, but to answer OP's question, yes, civilians did generally flee if they knew that a battle was imminent. Staying behind in an attempt to protect your house or belongings in the middle of a pitched battle would have been akin to suicide during a major engagement. Although citizens did stay behind in siege situations (most famously in Vicksburg), there was practically no instances of civilians trying to (realistically) fend off or defend their property from an imminent battle. If they knew a battle was coming, they loaded up their mule, horse, or wagon with all the provisions or valuables they could carry, and hoped/prayed that they had a home left when they returned. During the second half of 1864 thru the end of the war, when the North began its total war campaign, this was even more the case in the South, where citizens began to understand that the Union army would destroy anything of military value (including crops and livestock) in their path.
[Sources: Bruce Catton, 'Grant Takes Command' & 'Glory Road'; Jay Winik, 'April, 1865'; James McPherson, 'Battle Cry of Freedom']