Copy to clipboard from command line

I just discovered a couple useful command-line tools on OSX and thought I’d share. pbcopy will copy stdin to the clipboard and pbpaste will send the clipboard to stdout.

$ cat somefile.txt | pbcopy #copy a file to the clipboard
$ pbpaste | grep foo #search the clipboard for foo

Handy.

2 responses

  1. Marcelo Cantos

    grep foo < pbpaste doesn't do what you think it does.

  2. Thanks Marcelo, I fixed the example.

Your post must include a link to this post.

How does this work?
Write a response on your own website and include a link to this post. Then submit your response’s URL here. Your response may appear here after moderation. To update or remove it, edit or delete your original post and submit the same URL again. Learn more about Webmentions.