89

I see here:

http://www.pgrs.net/2008/1/11/command-line-clipboard-access

that there's a way in linux and osx to copy to the clipboard from the command line. So I ran my cygwin setup.exe, but couldn't find the xsel package. I'm guessing maybe this package hasn't been ported to windows? Looks like there's a tool to do it in windows:

http://www.labnol.org/software/tutorials/copy-dos-command-line-output-clipboard-clip-exe/2506/

I guess I'll try that - but in the mean I figured I'd ask if anyone has found a good solution.

7 Answers 7

181

Cygwin comes with special device file called /dev/clipboard:

echo foobar > /dev/clipboard  # Puts "foobar\n" on the clipboard
cat /dev/clipboard  # Pastes clipboard to stdout
6
  • 3
    this works also, but I guess I can't accept 2 different answers Commented Aug 26, 2009 at 12:51
  • 5
    This is better than getclip/putclip, as it requires no package installation.
    – Stabledog
    Commented May 4, 2014 at 19:31
  • 8
    The advantage of getclip/putclip over /dev/clipboard is that the former have options to convert between unix and dos line endings.
    – esquifit
    Commented Dec 28, 2014 at 20:03
  • 10
    The advantage of /dev/clipboard is that it supports UTF8, whereas getclip/putclip doesn't. Commented Feb 29, 2016 at 16:10
  • 3
    And it's easy to create putclip containing cat - >/dev/clipboard and getclip containing cat /dev/clipboard -- as aliases or functions or scripts, whichever takes your fancy. You can use any pair of script names, of course. Mac's have pbcopy and pbpaste to put and get information from the pasteboard (clipboard), for example. Commented Nov 20, 2017 at 20:31
68

On the page you linked, there are comments hinting how to do it on windows:

On Windows, Cygwin comes with getclip and putclip which do the same job.

1
  • 17
    If you don't have these available, you'll need to install the cygutils-extra package (src). Interestingly Babun omits this package by default.
    – chrnola
    Commented Dec 3, 2014 at 14:40
28

I second the answer above

To cat text to the Windows clipboard

putclip < foo.txt

To pipe to a file whatever text is in the Windows clipboard

getclip > foo.txt
1
  • @Adrian Thanks for noticing my useless use of cat. I tend to overuse cat instead of just pipes. I updated my answer.
    – user78706
    Commented Feb 13, 2013 at 23:34
25

getclip/putclip is found in cygutils-extra package.

13

what about just

clip < file.extension

just tried in on my ssh key

1
  • 1
    clip.exe was introduced in Windows Vista, so yes, you can use that as well, but the options are limited.
    – RobSiklos
    Commented Mar 20, 2018 at 15:39
2

Actually google "resource kit clip " for your windows clip and in cygwin terminal ( I use puttycyg works the following: find | clip

2

Not exactly Ditto, but here's a clibboard logger.

#!/usr/bin/ksh
while true
do
    if [[ "$(</dev/clipboard)" = "${LastClip}" ]]
    then
            sleep 2
    else
            LastClip="$(</dev/clipboard)"
            echo "$(</dev/clipboard)" >> $HOME/cliplog.txt
            sleep 1
    fi
done

Not the answer you're looking for? Browse other questions tagged or ask your own question.