Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy the contents of a file to clipboard from WSL to Windows?

Rig description:

I've installed Debian in Windows Subsystem Linux (WSL) on Windows 10.

  • The host means Windows 10.
  • The box means my WSL-Debian box/container.

Goal:

  • I have an SSH key on WSL (my_rsa.pub);
  • I want to copy the contents of that file to the host's clipboard;
  • by running a command in the box (command-line code, not using the mouse).

Explanation:

SSH files are very long, and it doesn't make sense to copy them with the mouse cursor.

I'm also told that Debian doesn't ship with a clipboard: you need to install a clipboard? So, I don't even know where to begin to look.

What I've tried:

"Copy to clipboard" in VIM is configured and working properly, but any contents copied to the 'clipboard' are removed from the 'clipboard' once VIM is closed; similarly, Nano has a CTRL+u function to cut text, and its clipboard does not survive outside of Nano.

like image 584
Wolfpack'08 Avatar asked Jan 30 '20 11:01

Wolfpack'08


People also ask

How do I copy files from WSL to Windows?

Open the File Explorer again to check if the file is created: To copy the file in Windows, right-click on it and select copy: Paste it in the Windows directory where you want to transfer the file.

Can I access the files from WSL in Windows?

One of the benefits of WSL is being able to access your files via both Windows and Linux apps or tools. Using your mounted drives, you can edit code in, for example, C:\dev\myproj\ using Visual Studio / or VS Code, and build/test that code in Linux by accessing the same files via /mnt/c/dev/myproj .

How do I copy file contents to clipboard?

CLIPBOARD - This is used for explicit copy/paste commands via Keyboard using ctrl+c and ctrl+v keys and via menu items.


1 Answers

  • Command:
cat /path/to/file | clip.exe
  • Description:

cat command put the file contents to the output. It is then pipe to the clip.exe, a Win32 program, redirects output to the Windows clipboard. Do not forget to add the .EXE extension of the later one. There are multiple cat alternatives can be used, see this and this.

  • Further Reading:

    • Windows Subsystem for Linux interoperability with Windows
like image 113
Biswapriyo Avatar answered Sep 22 '22 06:09

Biswapriyo