This question already has an answer here:
Is there any way to copy current command (line typed in bash prompt) in terminal to X-clipboard without involving a mouse?
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Yes, first you have to install xclip.
Then to copy previous line:
To Paste: Middle click or
To copy Output of any command:
However, this may fail if the command has special characters.