Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy to clipboard using Bash for Windows

How do I copy results from the commandline directly to the clipboard?

On Windows's cmd.exe I can do simply echo "asd" | clip and it pipes output to the clipboard.

I tried to install xclip for that, and though it compiled, when called it prints:

Error: Can't open display: (null) 

Using mouse is not the solution.

like image 680
Marek Lewandowski Avatar asked Mar 31 '17 15:03

Marek Lewandowski


People also ask

How do I copy and paste in bash Windows?

Copying and Pasting in Git Bash There are two ways to copy and paste in Git Bash: Keyboard: Hold Shift and use the left/right arrows to select a text area, then press Enter to copy. Paste text by pressing Insert . Mouse: Left-click and drag to highlight a text selecting, then right click to copy.

How do I paste from clipboard to bash?

You can now press Ctrl+Shift+C to copy selected text in the Bash shell, and Ctrl+Shift+V to paste from your clipboard into the shell. Because this feature uses the standard operating system clipboard, you can copy and paste to and from other Windows desktop applications.

How do you copy in bash?

Copy a File ( cp ) You can also copy a specific file to a new directory using the command cp followed by the name of the file you want to copy and the name of the directory to where you want to copy the file (e.g. cp filename directory-name ). For example, you can copy grades. txt from the home directory to documents .

How do I copy and paste from Windows to Linux?

Similarly, you can use Ctrl+shift+C to copy text from the terminal and then use it to paste in a text editor or web browser using the regular Ctrl+V shortcut. Basically, when you are interacting with the Linux terminal, you use the Ctrl+Shift+C/V for copy-pasting.


1 Answers

In Build 14393 or later, if you want to copy something to clipboard in WSL console, just add '.exe' to what you do in Windows cmd.

echo "aaa"|clip.exe 

To read from clipboard:

powershell.exe -command "Get-Clipboard" 
like image 195
reker Avatar answered Oct 27 '22 01:10

reker