Clipboard Operations
Read, write, and transform the system clipboard. Built in on macOS; Linux uses xclip/xsel.
When to use
"Copy this", "what's in my clipboard", "paste", or transforming clipboard text.
macOS
pbpaste # Read clipboard
echo "hello" | pbcopy # Copy text
pbcopy < /path/file.txt # Copy file contents
pbpaste > /path/out.txt # Save clipboard to file
ls -la | pbcopy # Copy command output
printf "%s" "exact text" | pbcopy # No trailing newline
# Transform: paste -> process -> copy back
pbpaste | tr '[:lower:]' '[:upper:]' | pbcopy # uppercase
pbpaste | sort | pbcopy # sort lines
pbpaste | wc -w # word count
Linux
xclip -selection clipboard # copy (pipe into)
xclip -selection clipboard -o # paste
Guidelines
- Confirm what was copied with a brief summary.
- Never display clipboard contents unless asked — may contain sensitive data.