Linux: How To Copy and Paste From the Command Line

Q. How do I copy and paste text or output from a shell prompt? How do I copy text from one terminal window and paste it on diffrent server window using mouse?

A. You can easily copy and paste between multiple shell prompts or the terminals using nothing but your mouse only. This is useful to transfer configuration lines from one terminal to another all opened over ssh session.

Most Linux distros are configured the click of a middle mouse button as paste operation. All you have to do is select text, move your most to another window and hit the middle mouse button. If you have a scroll wheel, just press on it to past the text. If you see only two buttons, just hit both button simultaneously i.e. you can emulate a third, “middle” button by pressing both mouse buttons simultaneously.

Optional: Linux Mouse configuration

Usually you can reconfigure mouse by editing /etc/X11/xorg.conf file or your distributions mouse configuration tool. You can also use xmodmap utility for modifying keymaps and mouse pointer button mappings in X. Here is my sample PS2 wheel Mouse entry:

Section "InputDevice"
         Identifier      "Configured Mouse"
         Driver          "mouse"
         Option          "CorePointer"
         Option          "Device"        "/dev/input/mice"
         Option          "Protocol"      "ImPS/2"
         Option          "ZAxisMapping"  "4 5"

Further readings:

  • man pages xorg, xmodmap, xsetpointer etc

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 14 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
14 comments… add one
  • shakaran Aug 13, 2008 @ 11:53

    With keyboard:
    Copy: Ctrl+Shift+C
    Paste: Ctrl+Shift+V

    • Q Nov 1, 2012 @ 14:24

      Only works in gnome, not in kde or another gui.

      • rebeka Apr 6, 2015 @ 8:53

        That’s not correct ! I don’t use Gnome and in here it works the way shakaran described. rxvt-unicode’s configuration makes it possible, just to give an example :)

  • Aaron Aug 14, 2008 @ 3:53

    …the real answer I’ve always wanted is how to cat the contents of a file to the clipboard. For example:

    cat myfile | x-clipboard

    That would occasionally save me a lot of selecting and copying.

  • mike Aug 24, 2008 @ 19:46


    Apparently, this is a rather challenging thing to do. I’m there with you though – I will love to pipe into the clipboard. I’ve looked for a way to do it, but have never found such a way. Someday…

  • Aaron Aug 25, 2008 @ 5:17

    Mike–I found the answer a few days after I read the article.

    Do this:

    uptime | xclip

    In your favorite X application (like gedit) middle-click. It should toss your uptime into gedit.

    Unfortunately (at least with Ubuntu) there appears to be different clipboards. The X clipboard pastes when you middle-click, but there is another clipboard for when you actually click copy/cut/paste from a menu or use the Control+C/V/X

  • mike Aug 25, 2008 @ 6:33

    Hmmm…I can’t get this to work cause I don’t have middle click emulation on. I could play with that, but I like it off anyway. I’m in waiting until the right solution comes along.

    This is a good start though, thanks.

  • Aaron Aug 27, 2008 @ 20:14

    Mike–I have some additional info for you.

    I tried:
    echo Hello | xclip -i -selection clipboard

    From all my applications, I could hit CTRL+V or middle-click to paste, but the “Paste” menu showed up in grey for all those applications. Strange.

    Doing some digging turns up that X has multiple clipboards called Primary, Secondary, and Clipboard.

    More info in it here:

  • mike Aug 29, 2008 @ 3:44

    Hey, that seems to work. Incredible. Time to make an alias to that combo.

    I saw that bit about multiple clipboards, but it’s so baffling that I didn’t want to figure it out.

    Why in the &*(% is it done this way? Eek.

  • murugesh Feb 21, 2012 @ 11:32


    i could not able to copy/paste by clicking right and left mouse button in my terminal, what need to be configured? this will save lots of time

    now i am right clicking and selecting the copy and paste option to do this. pls help

  • Birendra Singh May 27, 2012 @ 14:53

    Yes this is working fine.

  • Nar Feb 23, 2013 @ 2:54

    Hello Everyone.
    I need to know how can I copy from Linux and paste into a world document.

  • ocj Sep 13, 2014 @ 12:43

    Thank you for this article, it helped me a lot.

  • mike2008and2008 Nov 3, 2015 @ 18:59

    How To Copy and Paste From the Command Line is misleading and should be “Use Mouse to copy and paste in console”. I was looking the command line args to copy and paste and this has not one thing to do with that but it sounds like it does.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum