copyfile is a small Bash CLI that copies the contents of a file to the system clipboard on Linux desktops and WSL.
It is safe by default:
- Running
./copyfilewith no arguments only checks your environment and prints help. - It does not install dependencies unless you explicitly run
./copyfile --install-deps. - It does not install itself systemwide unless you explicitly run
./copyfile --install-systemwide.
copyfile chooses the clipboard backend from the active session type, not just the desktop environment name. This matters because GNOME, KDE Plasma, and other desktops can run under either Wayland or X11.
| Environment | Backend used | Required command | Package usually needed | Support status |
|---|---|---|---|---|
| Wayland desktops/compositors | Wayland clipboard | wl-copy |
wl-clipboard |
Supported |
| X11/Xorg desktops | X11 clipboard | xclip, fallback xsel |
xclip or xsel |
Supported |
| WSL/WSL2 | Windows clipboard | clip.exe |
none | Supported when Windows interop is enabled |
Common supported desktop environments include:
- GNOME on Wayland or X11
- KDE Plasma on Wayland or X11
- Xfce on X11
- Cinnamon on X11
- MATE on X11
- LXQt/LXDE on X11
- Sway, Hyprland, River, and other Wayland compositors using
wl-clipboard
Not guaranteed:
- Headless TTY-only systems
- Remote SSH sessions without a forwarded graphical clipboard
- Containers without access to the host display server
- macOS
- BSD systems
- NixOS, Guix System, and immutable/atomic Linux variants unless the required backend command is already installed or installed by your normal system method
- Nonstandard clipboard managers or restricted desktop sessions
--install-deps has built-in package-manager support for the following Linux families.
| Distribution family | Package manager detected | Wayland package | X11 package | Support status |
|---|---|---|---|---|
| Debian, Ubuntu, Linux Mint, Pop!_OS, Kali | apt-get |
wl-clipboard |
xclip |
Supported |
| Fedora | dnf |
wl-clipboard |
xclip |
Supported |
| RHEL, CentOS Stream, Rocky Linux, AlmaLinux | dnf/yum |
wl-clipboard where available |
xclip |
Supported, repository availability may vary |
| Arch Linux, Manjaro, EndeavourOS | pacman |
wl-clipboard |
xclip |
Supported |
| openSUSE Leap/Tumbleweed | zypper |
wl-clipboard |
xclip |
Supported |
| Alpine Linux | apk |
wl-clipboard |
xclip |
Supported |
| Void Linux | xbps-install |
wl-clipboard |
xclip |
Supported |
| Gentoo | emerge |
gui-apps/wl-clipboard |
x11-misc/xclip |
Supported |
| Solus | eopkg |
wl-clipboard |
xclip |
Supported |
| WSL/WSL2 | none | not needed | not needed | Supported through clip.exe |
Any distribution not listed above is not guaranteed. The script may still work if one of these commands is already available in PATH:
wl-copyxclipxselclip.exe
Check your system and print help:
./copyfileCopy a file:
./copyfile notes.txtCopy stdin:
printf 'hello\n' | ./copyfile -Install the required clipboard dependency for the current session:
./copyfile --install-depsInstall copyfile systemwide:
./copyfile --install-systemwideAfter systemwide installation:
copyfile notes.txtThe first run is intentionally non-invasive:
./copyfileIt reports:
- distribution
- desktop environment
- session type:
wayland,x11,wsl, orunknown - detected package manager
- available or missing clipboard backend
- the dependency command to run when needed
- the systemwide installation command
If a dependency is missing, it tells you to run:
./copyfile --install-deps--install-deps installs only the clipboard backend needed for the detected session:
- Wayland: installs
wl-clipboard, which provideswl-copy - X11: installs
xclip - WSL: uses Windows
clip.exe; no Linux package is installed
Package installation uses sudo when needed. If sudo is not available, it tries doas.
--install-systemwide installs the current script to:
/usr/local/bin/copyfile
This makes it callable from anywhere as:
copyfile FILEThe target path can be overridden with COPYFILE_INSTALL_PATH:
COPYFILE_INSTALL_PATH="$HOME/.local/bin/copyfile" ./copyfile --install-systemwidecopyfile is quiet on success and returns exit code 0.
It prints errors to stderr and returns a nonzero exit code when:
- the file does not exist
- the input is a directory
- the file is not readable
- no supported clipboard backend is available
- dependency installation fails
- systemwide installation fails
Copy a public SSH key:
copyfile ~/.ssh/id_ed25519.pubCopy a script:
copyfile ManageKVM.shCopy command output:
git diff | copyfile -Copy a file whose name starts with a dash:
copyfile -- -filename.txtRemove the systemwide command:
sudo rm /usr/local/bin/copyfileThis does not remove clipboard dependencies such as wl-clipboard, xclip, or xsel.