pbcopy & pbpaste for WSL

I use pbcopy and pbpaste on MacOS and Linux quite a bit. It’s a convenient way to pipe the output of something in the terminal to your clipboard or from your clipboard into the terminal. If you’re running WSL (the Windows Subsystem for Linux) you haven’t been able to use this, until now.


Launch WSL terminal

mkdir ~/bin

Modify your ~/.bashrc or ~/.zshrc depending on which shell you use (I use zshell) and add to the end of the file:

export PATH=$HOME/bin:$PATH


nano ~/bin/pbcopy

paste the following contents:

# pbcopy for wsl
tee <&0 | clip.exe
exit 0

then we need to set permissions and make it excutable

chmod u+x ~/bin/pbcopy


nano ~/bin/pbpaste

paste the following contents:

# pbpaste for WSL
powershell.exe Get-Clipboard | sed 's/\r$//' | sed -z '$ s/\n$//'
exit 0

Now you can use pbpaste and pbcopy just as you would on Linux and MacOS!

3 thoughts on “pbcopy & pbpaste for WSL

Leave a Reply

Your email address will not be published. Required fields are marked *