edo1z blog

プログラミングなどに関するブログです

Ubuntu - クリップボードコピー

今私はubuntu18.04をメインPCとして使っています。もともとWindows10をデュアルブートにしてたのですが、たしか16から18にアップデートしようとしてたらゴチャゴチャしてしまい、めんどくさくなってwindowsを消してubuntu18.04オンリーのPCにしてしまいました。Linux用のアプリがないやつを使いたいときに、後悔の念にさいなまれます。

xclipコマンド

クリップボードへのコピーは、xclipというコマンドが使えます。

インストール

$ sudo apt-get install xclip

ヘルプ

$ xclip -h
Usage: xclip [OPTION] [FILE]...
Access an X server selection for reading or writing.

  -i, -in          read text into X selection from standard input or files
                   (default)
  -o, -out         prints the selection to standard out (generally for
                   piping to a file or program)
  -l, -loops       number of selection requests to wait for before exiting
  -d, -display     X display to connect to (eg localhost:0")
  -h, -help        usage information
      -selection   selection to access ("primary", "secondary", "clipboard" or "buffer-cut")
      -noutf8      don't treat text as utf-8, use old unicode
      -target      use the given target atom
      -version     version information
      -silent      errors only, run in background (default)
      -quiet       run in foreground, show what's happening
      -verbose     running commentary

Report bugs to <astrand@lysator.liu.se>

xclipの使い方

下記で、123をコピーします。

$ echo 123 | xclip

下記で貼り付けします。

$ xclip -o

ただ、これだと ctrl + c のクリップボードにはコピーされません。下記のようにするとクリップボードにコピーされて、 ctrl + v や、ターミナルであれば、 ctrl + shift + v でペーストできます。

$ echo 123 | xclip -selection c

ファイルの内容をコピー

$ xclip -selection c hoge.txt