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?


4 Answers 4


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.

  • 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, 2011 at 7:34
  • It can be useful to add the file's mimetype: -t $(file -b --mime-type "$1")
    – Raphael
    Jan 30, 2019 at 8:31
  • 9
    xclip -selection clipboard can be shortened to xclip -se c. Mar 28, 2020 at 18:19

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) Jul 16, 2018 at 8:34

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
$ 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .