When using the Windows Subsystem for Linux (e.g. Ubuntu/Debian on WSL) the xclip
solution won't work. Instead you need to use clip.exe
and powershell.exe
to copy into and paste from the Windows clipboard.
This solution works on "real" Linux-based systems (i.e. Ubuntu, Debian) as well as on WSL systems. Just put the following code into your .bashrc
:
if grep -q -i microsoft /proc/version; then
# on WSL
alias copy="clip.exe"
alias paste="powershell.exe Get-Clipboard"
else
# on "normal" linux
alias copy="xclip -sel clip"
alias paste="xclip -sel clip -o"
fi
How it works
The file /proc/version
contains information about the currently running OS. When the system is running in WSL mode, then this file additionally contains the string Microsoft
which is checked by grep
.
To copy:
cat file | copy
And to paste:
paste > new_file