HomeBlog › pbcopy & pbpaste: The Mac Clipboard in Terminal

pbcopy and pbpaste: Using the Mac Clipboard From the Terminal

Updated August 2026 · 5 min read

Every Mac ships with two tiny command-line tools that most people discover years late: pbcopy puts text onto the clipboard, and pbpaste prints what's on it. Once they're in your muscle memory you stop dragging the mouse across terminal output forever. (The pb is for pasteboard — macOS's internal name for the clipboard, managed by a system service called pboard.)

The basics

# copy a file's contents to the clipboard
cat ~/.ssh/id_ed25519.pub | pbcopy

# copy command output
pwd | pbcopy
git branch --show-current | pbcopy

# paste the clipboard into a file / a pipeline
pbpaste > notes.txt
pbpaste | wc -l
pbpaste | jq .

That first one is the classic: your SSH public key onto the clipboard with no mouse, no missed trailing newline.

One-liners worth stealing

# strip formatting from copied text (plain-text laundering)
pbpaste | pbcopy

# sort & dedupe whatever you copied
pbpaste | sort -u | pbcopy

# count words in copied text
pbpaste | wc -w

# copy your public IP
curl -s ifconfig.me | pbcopy

# pretty-print copied JSON and re-copy it
pbpaste | jq . | pbcopy

# url-decode copied text (python one-liner)
pbpaste | python3 -c "import sys,urllib.parse;print(urllib.parse.unquote(sys.stdin.read()))" | pbcopy

The pbpaste | … | pbcopy sandwich is the pattern: clipboard in, transform, clipboard out. (For the formatting-strip specifically, there are also keyboard-level ways to paste without formatting.)

What pbcopy actually talks to: the pasteboard

macOS keeps the clipboard in a background service, pboard. There's one general pasteboard (what ⌘C and pbcopy use) plus special ones for find text and rulers — and it holds exactly one item: every pbcopy or ⌘C replaces the last. If copy/paste ever stops working system-wide, it's usually this service hung — killall pboard restarts it, and our copy-paste troubleshooting guide covers the rest.

The one-item limit, and fixing it

Because the pasteboard holds a single item, a pbcopy can silently destroy something you copied ten seconds ago. A clipboard manager fixes that at the system level: it watches the pasteboard and keeps history, so everything you pbcopy is also captured. We make Vee for exactly this — press V in any app (or in your terminal) and your recent history opens at the cursor, including every value your scripts pushed with pbcopy. More terminal-flavored workflows in clipboard history for developers.

Bonus: remote pbcopy over SSH

# copy a remote file's contents to your local clipboard
ssh server cat /etc/hostname | pbcopy

Anything that prints on the remote side pipes into your local clipboard — no scp, no tmp files. Combined with a clipboard history, terminal work starts to feel mouse-optional. Vee is free to try if you want the history half.

Related guides

Try Vee — your clipboard, one V away

Vee keeps everything you copy and opens your history right at the cursor. Press V, pick, paste. Free for text history, no account required.

Download Vee for macOS