The most important thing that for a Napoleonic recruit to learn was how to move in formation. While things like marksmanship are taught as well as basic combat knowledge, moving in formation is the most important thing for a French soldier to learn. This is due to the emphasis on maneuver warfare that started in the pre-Revolutionary period as concept and proven in the Revolution.
For this discussion, the majority of the conversation will focus on the smallest tactical unit on the battlefield, the battalion. While companies and squads do exist, neither were capable of independent command. So, when a Battalion is flanked, generally the battalion commander (could be a captain or a major depending on losses and promotion) would pivot his battalion on one edge (where a soldier stands still and turns while the rest of the battalion moves forward and backward while staying in line.
Another option would be to pull back from the field in order to no longer be flanked in order to no longer be flanked. However, if the line is being flanked, things are very bad as cavalry is not protecting the flanks.
There are a few different ways to to move a battalion to face a flanking enemy. Wheeling on the left or right company would be the simplest way. Imagine the battalion as an opening door.
To wheel the battalion to the left, the light company on the left would at as the pivot. Companies 1-8 and the grenadier company would swing out and around the light company. Company 8(closest to the light company) would march slower while the grenadiers(farthest from LC) would have to march the quickest in order to maintain the battalion's cohesion.
There are other ways to face an enemy outlined in Dundas' Rules and Regulations for the Movements of His Majesty's Infantry. Often simple wheeling right or left would not align the battalion to the enemy's attack. Wheeling the entire battalion, then wheeling the individual companies would turn the battalion into column formation. It could then march perpendicular to the enemy's attack allowing the battalion to align itself. You can see this is Dundas' 4th Manoeuvre - the line wheels back into an open column of companies; then moves to take up a new position at an oblique angel to that originally occupied.