83

I'm coping file to xclip

cat file.txt | xclip

I'm pasting without problem with

xclip -o

When I want to paste it to Firefox with Ctrl+V it pastes old text (that shouldn't already be in the clipboard).

When I go back to terminal and run xclip -o it pastes the correct text.

Why is there a problem with pasting to Firefox?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
xralf
  • 16,149
  • 29
  • 101
  • 149

4 Answers4

98

X11 has several available clipboards. By default, xclip places data in the primary selection buffer. To paste it, you use middle-click.

If you want to use Ctrl+v, use xclip -selection clipboard. See man xclip for more information.

There is good information about the different clipboards on freedesktop.org.

Shawn J. Goff
  • 45,338
  • 25
  • 134
  • 145
  • 2
    On a side note: I just noticed that xclip's option `-f, -filter` is a built in `tee` . It writes to the clipboard and to stdout at the same time. That could come in handy (for something). – Peter.O Oct 13 '11 at 07:34
  • It can be useful to add the file's mimetype: `-t $(file -b --mime-type "$1")` – Raphael Jan 30 '19 at 08:31
  • 9
    `xclip -selection clipboard` can be shortened to `xclip -se c`. – Victor Yarema Mar 28 '20 at 18:19
55

Copy to your clipboard with:

xclip -sel clip < ~/path/to/file.txt

and then paste CTRL + V wherever you wish to.

  • 4
    Note that the shorthand `xclip -se c < myfile` would also do, since xclip admits abbreviations provided they don't conflict with valid options and keywords (`-silent` and `-selection`, for example) – XavierStuvw Jul 16 '18 at 08:34
5

Add this to to your ~/.bashrc

# now `cclip' can be used when you it to be available to `ctrl-[vxc]'
alias cclip='xclip -selection clipboard'

alternatively, run this:

echo 'alias cclip='"'"'xclip -selection clipboard'"'" >> ~/.bashrc
user3276552
  • 1,333
  • 10
  • 8
1
$ cat file.txt | xclip -i

xclip will read from stdin with option -i. If you want to copy to clipboard, run command:

$ xclip -o | xclip -sel clip
AdminBee
  • 21,637
  • 21
  • 47
  • 71