How to Paste from the Clipboard in Mac Terminal

Paste from the Clipboard in Mac Terminal

Work with a URL from your browser in Terminal? Save a full document from the clipboard to a file quickly (and process it, too)? The command line lets you do it. Find out here how to paste text from the system clipboard into Terminal on a Mac.

First, Bohr and Einstein Go Too Far

“Albert is not much more practically inclined than I am.”

Niels Bohr said something to that effect to himself in 1923 and went to pick up his friend and fellow physicist Albert Einstein from the train station in Copenhagen. They hopped on a tram to go to Bohr’s institute and discuss quantum physics.

The matter of fact being uncertain, nonlocal and entangled as it is, discussion could not wait, however, and soon the two were themselves entangled in talk about, say, light quantization.

Bohr and Einstein missed their stop. When Niels Bohr realized, they got off and went back.

Deep in thought and dispute, they missed their stop again… and again… and again.

Bohr remembers going back and forth “lots of times.” He also wonders what people might have thought. If it was the same people with them all the way back and forth, I gather, it was because they were listening in on the fascinating conversation, eager to get each word and stimulus out of it.

Speaking of which, how about having Terminal listening in on the system clipboard on a Mac?

How to Paste from the Clipboard in Mac Terminal

Using “pbpaste” (Directly Usable in Command-line Applications)

Time needed: 2 minutes

To paste text from the standard macOS system clipboard into the Terminal command prompt as a stream that can be redirected or piped (to a command-line app, for instance, or any file) on a Mac:

  1. Open or go to Terminal on your Mac.

  2. Type pbpaste at the Terminal command prompt.

    What it does: pbpaste takes text from the system clipboard and writes it to standard output; pbpaste does to text from the clipboard what cat does to the text content of files; standard output is typically printed to the screen but importantly can also be redirected as input to other programs.

  3. To save or append the text to a file:

    Saving: Add  > <filename> to write the contents of the Mac system clipboard (overwriting the current contents), replacing <filename> with the name of the file.
    Appending: Add  >> <filename> to add text from the clipboard to the end of the file.
    Example: The full command to save the clipboard text to the file clip.txt in the current directory is pbpaste > clip.txt.

  4. To use text from the clipboard as input for another program:

    Pipe: Append  | <command> to send text from the clipboard to a program that can use text from the standard input.
    Example: use pbpaste | sed 's/[.?!]/&\n/g' | grep -i "La De Du" to first split text from the clipboard into sentences, then extract all those that contain “La De Du”.

  5. Press Enter.

    Use “pbpaste” to paste to standard output in Mac Terminal

Something to paste: How to Copy Text to the Clipboard from Mac Terminal

Using the Terminal “Paste” Command (Good for Short Snippets of Text)

To paste text directly to the text input in Terminal from the system clipboard on a Mac:

  1. Position the text cursor where you want to paste the text.
    Applications: Pasting using the Terminal command will input text from the clipboard as if you had typed it anew.
  2. Press Command V.
    Escaping: You can also have Terminal escape certain characters (including whitespace, parentheses, colons, etc.) with a backslash before pasting; press Command Control V.
    Menu alternative: In the menu bar, you can also select Edit | Paste and Edit | Paste Escaped Text, of course.

How to Paste from the Clipboard in Mac Terminal: FAQ

Can I paste binary data (such as images) to Terminal?

No.

Using pbpaste or the Terminal app’s pasting commands, you can only paste text from the clipboard.

Can I paste formatted text?

To a very limited degree.

The pbpaste command has the option -Prefer that lets you specify rtf or ps for RTF text and encapsulated postscript respectively. It will the paste rich-text or PS-formatted text rather than the plain-text version. If no formatted text is found, pbpaste will still paste the plain text from the clipboard—and that is what typically will happen.
Example: pbpaste -Prefer rtf > ladedu.rtf saves RTF text from the clipboard to the file ladedu.rtf.

What is “Paste Selection”?

In macOS Terminal, you can copy and paste without first copying. The command Edit | Paste Selection in the menu (Command Shift V) pastes highlighted text from within Terminal.

To use it for copying text:

  1. Position the text cursor where you want to paste.
  2. Highlight text with the mouse in Terminal.
  3. Press Command Shift V to paste at the text cursor.

(How to paste from the clipboard in Mac Terminal tested with macOS Sonoma 14.3 and Ventura 13.5; updated March 2024)

Home » Mac Tips and Resources » How to Paste from the Clipboard in Mac Terminal