Copy a file's contents to the clipboard on Mac

Send any text file (or command output) straight to the clipboard from Terminal.

macOSTerminalLow risk
Run the command below — the whole file is on your clipboard, ready to paste with Cmd+V anywhere.

01Command

Command
$ pbcopy < ~/Documents/notes.txt

02What it does

pbcopy reads standard input and loads it into the macOS pasteboard, exactly as if you had selected the text and pressed Cmd+C. The < redirect feeds it a file; a pipe feeds it command output, e.g. cat log.txt | pbcopy or git diff | pbcopy. Its counterpart pbpaste prints the clipboard to the terminal. Pairs beautifully with SSH: cat key.pub | pbcopy grabs a public key from a remote server.

03Risk

RiskLow risk
CompatibilitymacOS 10.11 El Capitan – 15 Sequoia

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

Last verified: 2026-09-16 · Category: Developer

06Related solutions