Copy to the Clipboard from the Terminal (xclip / wl-copy)

Pipe any text into xclip -selection clipboard on X11 or wl-copy on Wayland to place it on the clipboard.

LinuxxclipwaylandTerminalclipboardLow risk
Run `echo "text" | xclip -selection clipboard` on X11, or `echo "text" | wl-copy` on Wayland, to copy text to the clipboard.

01Command

Command
$ echo "text to copy" | xclip -selection clipboard

02What it does

Common uses: `xclip -selection clipboard < file.txt` copies a whole file, and `cat ~/.ssh/id_ed25519.pub | xclip -sel clip` copies your SSH key. The `-selection clipboard` flag matters — without it xclip targets the middle-click PRIMARY selection, which feels like it 'didn't work'. Read the clipboard back with `xclip -o -selection clipboard` (or `wl-paste`).

03Risk

RiskLow risk
RequirementsX11: xclip (or xsel). Wayland: wl-clipboard (`wl-copy` / `wl-paste`). Select with `xclip -o -selection clipboard` to read back.
!Warning: xclip needs a running X display; piping into it over SSH fails unless you forward X. On Wayland sessions use wl-copy instead — xclip only sees XWayland apps' clipboard.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • xclip(1) - Linux manual page
    Ubuntu Manpages · technical · 2026-09-17
    Evidence: xclip reads from files or stdin and makes the data available as an X selection, with -selection clipboard for the CLIPBOARD and -o to output the selection.
  • wl-copy(1) — Arch manual page
    Arch Linux · technical · 2026-09-17
    Evidence: wl-copy copies text to the Wayland clipboard and wl-paste pastes it; they are the Wayland equivalents of xclip.

Last verified: 2026-09-18 · Category: System & Settings

06Related solutions