If a compressive force is applied, the bar will only experience compressive forces. If a tensile force is applied, the bar will only experience tensile force. They can only occur simultaneously on the same bar if the bar is subjected to bending.
The picture you have shared, it can be one of these cases. 1) Either you are pulling (tensile) or pushing (compressive) both the ends of the bars 2) You are fixing one end and pulling or pushing the other end 3) You are making an imaginary perpendicular cut somewhere in the bar and then observing this picture.
Lets consider case 1 now; both of your hands need to be putting a force in opposite direction to push or pull the bar. In case 2, the fixed end is doing the same thing as your other hand was doing in case 1. In case 3, you still observe the cutted cross section of the bar having an equal but opposite force (as compare to what you are applying to it). This can also be thought of as Newton's third law analogy for simplicity.
It should be noted that the top two pictures that you have shared will only be possible when the bar is static and not in a rigid body motion. Since you haven't shown any reaction forces in the bottom two pictures, it might do a rigid body motion (assuming the contact with the ground is frictionless).