Copy Entire File to Clipboard Using the Command Line

macOS

Use the built-in pbcopy utility:

cat filename.txt | pbcopy

Replace filename.txt with the file you want to copy.

Linux (X11 with xclip)

Use xclip to copy to the system clipboard:

xclip -selection clipboard < filename.txt

Or with cat:

cat filename.txt | xclip -selection clipboard

Install with:

sudo apt install xclip
Linux (Wayland with wl-clipboard)

Use wl-copy if on Wayland:

wl-copy < filename.txt

Install with:

sudo apt install wl-clipboard
Windows

In PowerShell:

Get-Content filename.txt | Set-Clipboard

Or using WSL:

cat filename.txt | clip.exe