
Photo by
1177aoi
Arch Linuxのターミナルでコピペを使う方法
Arch Linuxのターミナルを使っていて、コマンドの実行結果をマウスで選択してコピーしてターミナル以外に貼り付けたい。
・右クリックでコピーできない。
・Ctrl + cといったキーボードのショートカットキーでもコピーできない。
・macOSで使っていたpbcopyコマンドも使えない。
Arch Linuxでコピペする方法を調べました。
手順
コピーしたいターミナルの文字をマウスで選択
コピーした文字が選択された状態で下記のコマンドを実行
$ xclip -o | xclip -selection clipboard -i
上記コマンドによって、ターミナル上で選択した文字がクリップボードに保存されます。あとは、Ctrl + vで好きなところに貼り付けできます。
noteなどのウェブブラウザで記事を書いたりする際にも、ターミナルの文字をペーストできるのでめっちゃ便利です。
コマンド処理の流れ
xclip -oで選択した文字を標準出力へプリントアウト→|パイプで左記の結果をクリップボードに保存(X selectionという選択オプションで保存先をclipboardに指定している)
xclipとは
Arch Linuxでコピペを行うには、xclipというコマンドを使います。デスクトップ環境のためにxorgを使っている環境ではデフォルトでインストールされているようです。
下記は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
-rmlastnl remove the last newline charater if present
-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>