Name

pbcopy — stdin  stdout  - file  -- opt  --help  --version

Synopsis

pbcopy [options]

pbcopy copies standard input to the Macintosh clipboard.[24] This is great for copying the output of commands into other programs. For example, to copy the output of who into TextEdit, first send the output to the clipboard:

who | pbcopy

Then perform a paste operation in TextEdit. You can also copy the entire contents of a text file to the clipboard with:

pbcopy < myfile.txt

Typed without arguments, pbcopy reads from standard input until you type ^D on a line by itself:

pbcopy
This is the symphony
that Schubert wrote
and never finished.
^D              Ctrl-D to end the input

Now perform a paste operation in another application, and you’ll get the typed text.

pbcopy is most effective when you’re using the Mac desktop and Terminal. If you’re logged in from a remote system via SSH (as described in Running a Shell Remotely), you won’t have the same clipboard as the graphical applications on the desktop, so copying from them won’t work.

[24] Apple uses the term “pasteboard,” hence the “pb” in the name.

Get Macintosh Terminal Pocket Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.