59

I am trying to copy from the terminal with xclip and paste it into the unity desktop environment into gedit text editor. I can copy and paste with xclip in terminal:

$ cat line-size.c | xclip
xclip -o > input5.txt
cat input5.txt
#include <stdio.h>
...

However, when I press control + v to paste into gedit, it only pastes the actual last thing I copied within unity desktop, such as something from firefox browser.

How can I paste in gui applications something I copied from terminal?

2 Answers 2

101

I think it is just a matter of understanding the different selection clipboards used by the xclip utility

   -selection
          specify  which X selection to use, options are "primary" to use
          XA_PRIMARY (default), "secondary" for  XA_SECONDARY  or  "clip‐
          board" for XA_CLIPBOARD

When you do cat line-size.c | xclip the default behaviour is to copy to the primary X selection buffer - to paste from that buffer, you need to use a mouse middle-click instead of the Ctrl+v combination.

To copy into the clipboard instead, so that you can paste with Ctrl+v, you would need to do

cat line-size.c | xclip -selection clipboard
5
  • 2
    It is equally as easy to paste by piping to xclip without additional arguments. Instead of Ctrl+v, just use middle mouse click. Mar 31, 2014 at 12:47
  • That can be changed to xclip < line-size.c -selection clipboard Jun 18, 2015 at 21:23
  • @SubhamoySengupta see my edit
    – kbtz
    Mar 26, 2016 at 5:33
  • 6
    The instruction cat line-size.c | xclip -sel clip has the same result that cat line-size.c | xclip -selection clipboard Jun 6, 2016 at 13:58
  • 2
    I can't imagine the default use-case for xclip was to interact with something besides the user's clipboard.
    – aaaaaa
    Jan 22, 2018 at 23:27
13

Just in case if someone is looking for a shortest version without using aliases. By using something|xclip -se c instead of just bare something|xclip you can press Ctrl+V/Ctrl+Shift+V and see a desirable result. Where something — cat somefile.txt for example.

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.