Why are nozzles in space shaped like a cone and not like a tube ensuring all the exhaust is directed strait?
The maximum achievable flow rate of a compressible fluid in a constant-diameter tube is the speed of sound in that fluid. Once that point is reached, you can no longer affect the velocity of downstream portions by force applied through the upstream portions. If you put a tube nozzle at the throat of a rocket engine, the exhaust speed would never rise above the flow speed at the throat.
You need to apply force to the exhaust gases that are downstream to accelerate them further, which you can't do via fluid pressure due to the supersonic flow. You do this with the sloped sides of an expansion bell that redirect sideways expansion into further rearward expansion. In the process, as Newton's third law requires, you get additional thrust from the forward component of the pressure the expanding gas exerts against the expansion bell. Note that this would be impossible if the nozzle sides were not slanted to allow the gas to expand sideways.
A good nozzle is not shaped like a cone. The shape is called a De Laval nozzle.
The nozzle should expand the exhaust from chamber pressure to ambient pressure to maximize exhaust speed and efficiency.
A nozzle optimized for expansion to the space vacuum should be very long but would be too heavy.
For details see wikipedia.