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.
01Command
$ echo "text to copy" | xclip -selection clipboard02What 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
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- xclip(1) - Linux manual pageEvidence: 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 pageEvidence: 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
Refresh the package index from all configured repositories, then install newer versions of every upgradable package.
Find every occurrence of a pattern across all files in a tree, printed as file:line:number matches.
Unpack a gzipped tarball into the current directory while printing each file as it is extracted.