How do I capture bash output to the Mac OS X clipboard?

The pbcopy command does this.

For example, this puts the output from ls on the clipboard/pasteboard:

ls | pbcopy

And pbpaste does the reverse, writing to stdout from the clipboard:

pbpaste > ls.txt

You can use both together to filter content on the clipboard – here’s a rot13:

pbpaste | tr 'a-zA-Z' 'n-za-mN-ZA-M' | pbcopy

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)