LinuxCommandLibrary

pbcopy

TLDR

Copy text to clipboard

$ echo "[text]" | pbcopy
copy
Copy file contents
$ pbcopy < [file.txt]
copy
Copy command output
$ ls -la | pbcopy
copy
Paste from clipboard
$ pbpaste
copy
Paste to file
$ pbpaste > [file.txt]
copy

SYNOPSIS

pbcopy [options]
pbpaste [options]

DESCRIPTION

pbcopy copies standard input to the macOS clipboard (pasteboard). Its companion pbpaste outputs clipboard contents to standard output.
These tools integrate the command line with the graphical clipboard, enabling scripted clipboard operations.

PARAMETERS

-pboard name

Pasteboard name (general, ruler, find, font).
-Prefer type
Preferred data type (txt, rtf, ps).

USAGE EXAMPLES

Copy output and paste elsewhere:

$ cat file.txt | pbcopy
# Cmd+V in any application
copy
Process clipboard contents:
$ pbpaste | grep pattern
copy

CAVEATS

macOS only. Rich text may not copy as expected. Binary data needs careful handling. Pasteboard changes affect system clipboard.

HISTORY

pbcopy and pbpaste are macOS utilities provided by Apple. They have been part of macOS since early versions, providing command-line access to the system pasteboard (clipboard).

SEE ALSO

xclip(1), xsel(1), wl-copy(1)

Copied to clipboard