brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: pbcopy and pbpaste connect the terminal to your clipboard

Terminal
~/tips/tip-macos-pbcopy-pbpaste

cat ~/.ssh/id_ed25519.pub | pbcopy

Pipes terminal output to your clipboard and pastes clipboard text into commands.

Selecting terminal output with the mouse is slow and always grabs one character too many.

Pipe it into pbcopy. It takes standard input and places it on the pasteboard, which is what the Mac calls the clipboard.

cat ~/.ssh/id_ed25519.pub | pbcopy

The reverse is pbpaste. It writes the pasteboard contents to standard output, so you can feed copied text into another command.

pbpaste | sort -u | pbcopy

That line takes a copied list, removes duplicates and puts the result back on the clipboard. No editor needed.

The man page has two details worth knowing. Input is saved as plain text unless it starts with an EPS or RTF header. And if the pasteboard holds none of the types pbpaste looks for, it prints nothing, so a copied image gives you an empty result and not an error.

Once you use these two, you start seeing them everywhere: copy the output of a build, paste a command from a note, send a log line to a chat. The clipboard becomes just another stream, which is how shell people like it.

Further reading: pbcopy.1 man page, On this site: pbcopy puts the output of any command on your Mac clipboard

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link