I cut the bash command line text using Ctrl+K. The line was cut as expected. Next, I ran sudo su to become the root user.

I tried to paste the command that I cut as the non-sudo user using Ctrl+Y. It is no longer available.

How can I use cut, copy and paste in bash shell across user sessions?

  • Take a look at files like .bashrc or .inputrc inside /root to see whether they are set correctly. – Hongxu Chen Jun 28 '15 at 8:21
  • 1
    This is not related to your question, but there's never any point in running sudo su. Just run sudo -i or su if you have enabled the root account. – terdon Jun 28 '15 at 8:27
  • 1
    When you switch user, you are getting a new interactive process. The buffer that your command Yanks to is in the memory of, and hence local to the shell that you were using. – bsd Jun 28 '15 at 9:29

Control+K saves text in the Readline's buffer.
Control+Y extracts text from that buffer.
Each Bash instance has own buffer.

I suppose that you want to run a previous command as root. Try sudo !!. Details in Understanding the exclamation mark (!) in bash

Use tmux for a complex copypasting across sessions/shells etc:

tmux # Start tmux session
echo some-text
bash # Start new bash

Hm, I want to copy echo output from the outer session.
Control+b,[ - Enter copy mode to copy text or view the history
Control+r, some, Enter - Search some
Control+Space - Start selection
Control+e - Select to the end of line
Esc+w - Copy selection
Control+b,] - Paste the most recently copied buffer of text

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.