$linuxjunkies
>

Linux Clipboards Explained (+ Clipboard Managers)

Learn the difference between Linux's PRIMARY and CLIPBOARD selections, use xclip, xsel, and wl-clipboard from the terminal, and manage history with GPaste or Klipper.

BeginnerUbuntuDebianFedoraArch7 min readUpdated June 7, 2026

Before you start

  • A running graphical desktop session (X11 or Wayland)
  • sudo privileges for package installation
  • GNOME Shell (for GPaste) or KDE Plasma (for Klipper)

Linux has not one but two independent clipboards, and that surprises almost every user coming from Windows or macOS. Once you understand how they work — and add a clipboard manager — copy-paste becomes genuinely powerful instead of frustrating. This guide covers the theory, the command-line tools, and two solid clipboard managers for both X11 and Wayland.

PRIMARY vs CLIPBOARD: The Two Selections

X11 defines multiple selection buffers. Two matter in day-to-day use:

  • PRIMARY — Filled automatically whenever you highlight text with the mouse. Paste it anywhere by clicking the middle mouse button. No Ctrl+C involved.
  • CLIPBOARD — Filled explicitly when you press Ctrl+C (or Edit → Copy). Paste with Ctrl+V. This is the Windows-style clipboard most people think of.

They are completely independent. Copying with Ctrl+C does not overwrite what you selected with the mouse, and vice versa. A common gotcha: you select some text (PRIMARY is set), then accidentally select different text before middle-clicking, and your original selection is gone.

A subtlety worth knowing: PRIMARY is owned by the application holding the selection. If you close that application before pasting, the content vanishes — unless a clipboard manager is running (more on that below).

What About Wayland?

Wayland implements PRIMARY and CLIPBOARD through the wl-data-device protocol, so both selections still exist. The tools and some application behaviour differ, but the conceptual model is the same. Native Wayland apps handle this correctly; XWayland apps may behave slightly differently depending on the compositor.

Command-Line Clipboard Tools

These tools let scripts and terminal workflows read from and write to either selection.

xclip and xsel (X11)

Install on Debian/Ubuntu:

sudo apt install xclip xsel

Install on Fedora/RHEL family:

sudo dnf install xclip xsel

Install on Arch:

sudo pacman -S xclip xsel

Copy a string to CLIPBOARD with xclip:

echo "hello" | xclip -selection clipboard

Paste (print) from CLIPBOARD:

xclip -selection clipboard -o

Copy a file's contents to CLIPBOARD:

xclip -selection clipboard < /etc/hostname

Work with PRIMARY instead (just change the flag):

xclip -selection primary -o

xsel uses slightly different flags but does the same job:

# Copy to CLIPBOARD
echo "hello" | xsel --clipboard --input

# Paste from CLIPBOARD
xsel --clipboard --output

# Copy to PRIMARY
echo "hello" | xsel --primary --input

Both tools require a running X display ($DISPLAY must be set). They will not work in a raw TTY.

wl-clipboard (Wayland)

wl-clipboard provides wl-copy and wl-paste, the Wayland equivalents.

Install on Debian/Ubuntu:

sudo apt install wl-clipboard

Install on Fedora/RHEL family:

sudo dnf install wl-clipboard

Install on Arch:

sudo pacman -S wl-clipboard

Usage mirrors xclip's intent:

# Copy to CLIPBOARD
echo "hello" | wl-copy

# Paste from CLIPBOARD
wl-paste

# Copy to PRIMARY
echo "hello" | wl-copy --primary

# Paste from PRIMARY
wl-paste --primary

A useful trick: pipe command output straight to the clipboard without printing it:

cat ~/.ssh/id_ed25519.pub | wl-copy

On a system running both XWayland and native Wayland sessions, set $WAYLAND_DISPLAY if wl-copy complains about no compositor connection.

Clipboard Managers

A clipboard manager solves two real problems: it preserves clipboard content after the source application closes, and it keeps a history so you can paste something you copied several steps ago.

GPaste (GNOME, Wayland-native)

GPaste integrates tightly with GNOME Shell via an extension and works under Wayland natively. It stores a searchable history and exposes a keyboard shortcut to browse it.

Install on Debian/Ubuntu (GNOME):

sudo apt install gpaste gnome-shell-extension-gpaste

Install on Fedora:

sudo dnf install gpaste

Install on Arch:

sudo pacman -S gpaste

Enable and start the daemon:

systemctl --user enable --now gpaste-daemon.service

Enable the GNOME Shell extension (required for the panel indicator and shortcut):

gnome-extensions enable [email protected]

After a shell restart (Alt+F2 → r on X11, or log out and back in on Wayland), a clipboard icon appears in the top bar. The default history shortcut is Super+Alt+H. You can also control GPaste from the terminal:

# List history
gpaste-client history

# Get the most recent item
gpaste-client get 0

# Empty the history
gpaste-client empty

Configure history size, ignore patterns, and password protection in Settings → GPaste (via the extension preferences).

Klipper (KDE Plasma)

Klipper ships with KDE Plasma and requires no separate installation. It runs automatically as part of the Plasma session. On a fresh Plasma install it is already active in the system tray.

If it somehow is not running:

klipper &

Or re-enable it through System Settings → Clipboard.

Key Klipper features worth knowing:

  • History accessed via Ctrl+Alt+V (default) or the tray icon.
  • Actions: define regex patterns so that copying a URL, phone number, or file path triggers an automatic context menu of actions (open browser, dial, open file manager).
  • Synchronise PRIMARY and CLIPBOARD optionally — useful if you want middle-click paste to always match Ctrl+V.
  • Set history length and enable "ignore selections" to avoid cluttering history with every mouse-drag highlight.

Klipper's config lives in ~/.config/klipperrc if you need to inspect or back it up.

Verification

Confirm both selections are working independently:

  1. Open a terminal. Run echo "from clipboard" | wl-copy (Wayland) or echo "from clipboard" | xclip -selection clipboard (X11).
  2. Select the word from in the command above with your mouse (sets PRIMARY).
  3. Open a text editor. Press Ctrl+V — you should see from clipboard. Middle-click — you should see from. They differ, confirming the two selections are independent.

Verify the GPaste daemon is running:

systemctl --user status gpaste-daemon.service

Output should show active (running).

Troubleshooting

xclip/xsel returns nothing in a Wayland session

These tools require $DISPLAY to be set. On a pure Wayland session without XWayland, they will fail. Use wl-copy/wl-paste instead, or enable XWayland in your compositor settings.

Clipboard content disappears when the source app closes

This is expected X11 behaviour — the owning application holds the data. A clipboard manager fixes it by reading and caching the content immediately. Ensure GPaste or Klipper is running before you close the source app.

GPaste daemon fails to start

Check the journal for details:

journalctl --user -u gpaste-daemon.service -n 30

A common cause on Wayland is a missing or outdated GNOME Shell extension version that does not match the installed shell version. Install the correct version from extensions.gnome.org or via your package manager.

Middle-click paste not working in some apps

Some Electron and Qt apps do not respect PRIMARY by default. There is no universal fix; check the application's own settings. In Klipper, enabling "Synchronise contents of the clipboard and the selection" is a workaround if you don't mind them staying in sync.

tested on:Ubuntu 24.04Fedora 40Arch rollingDebian 12

Frequently asked questions

Why does my clipboard content disappear when I close an application?
In X11 and Wayland the source application owns the clipboard data. When it exits, the data is gone unless a clipboard manager like GPaste or Klipper has already cached it.
Can I use xclip on a Wayland session?
Only if XWayland is running and $DISPLAY is set. On a pure Wayland session without XWayland, use wl-copy and wl-paste instead.
How do I stop GPaste from saving passwords I copy?
GPaste supports password-aware storage. In its preferences you can mark entries as passwords (they are stored obfuscated) or add application ignore rules so credentials from password managers are never saved.
Is it possible to sync PRIMARY and CLIPBOARD so they always match?
Klipper has an option to synchronise both selections. GPaste does not sync them by design. Syncing is convenient but means losing the ability to hold two different pieces of text at once.
Do these tools work over an SSH session?
xclip and xsel work over SSH only when X11 forwarding is enabled (ssh -X or ssh -Y) and a local X server is running. wl-clipboard requires a Wayland compositor and will not work over plain SSH.

Related guides