pbcopy and pbpaste


pbcopy and pbpaste are two very simple shell commands that help you to streamline your copy & paste operations.

pbcopy copies stdin to the OSX clipboard. pbpaste copies the clipboard content to stdout. Combining both allows you to perform complex operations on your clipboard contents. Need an example:

pbpaste | fmt -s -w 80 | pbcopy

will format the text in your clipboard so that it breaks at a text width of 80 characters. very good if you need to write technical documents with fixed character width. I guess you can easily imagine any text-based workflow. Just think of what stream processing you can do with html tidy, aspell, etc.

Of course, putting your pbpaste/pbcopy chain to a script that you can conveniently run from any shell or binding it to a key combination will make the whole thing even more useful.

I found this works for OSX. Maybe there is an equivalent for Linux as well. Any hints?

1 thought on “pbcopy and pbpaste

  1. For Linux there’s xclip, so the command would work like this:

    xclip -o|fmt -s -w 80|xclip -i

    Great idea btw. I usually just use vim to rebreak any mails/documents I might receive, but this is handy too.

Leave a reply to Jojo Cancel reply