This command writes (pastes) the content of the clipboard to stdout
.
To use - copy (cmd-c) some text; then in the terminal type pbpaste
and enter:
$ pbpaste
Hello, World!
This is the inverse of pbpaste - copy text from stdin
to the clipboard.
Copy the text Hello
to the clipboard:
$ echo "Hello" | pbcopy
Go to a text editor and do cmd-v, you'll get "Hello".
Copy the content of README.md to the clipboard:
$ pbcopy < README.md
Same, using cat:
$ cat README.md | pbcopy
Copy my ssh public key:
$ pbcopy < ~/.ssh/id_rsa.pub
base64
encodes stdin to stdout.
Encode some text:
$ echo '{"os":"mac"}' | base64
Outputs eyJvcyI6Im1hYyJ9Cg==
to the console.
Encode a file:
$ base64 < file.bin
Encode the clipboard:
pbpaste | base64
If the clipboard contained Hello
, the above will output SGVsbG8=
.
Encode the clipboard into the clipboard:
pbpaste | base64 | pbcopy
The clipboard will contain SGVsbG8=
.
Use base64 -D
(uppercase D) the same way as base64
.
echo 'eyJvcyI6Im1hYyJ9Cg==' | base64 -D
Outputs {"os":"mac"}
to the console.
Python's JSON module contains a CLI tool that reads JSON from stdin, validates it and pretty-prints to stdout.
$ echo '{"os":"mac"}' | python -mjson.tool
{
"os": "mac"
}
Pretty-print from the clipboard:
$ pbpaste | python -mjson.tool
Pretty-print the clipboard into the clipboard:
$ pbpaste | python -mjson.tool | pbcopy
Base64-decode a JSON document from the clipboard and pretty-print it into the clipboard:
$ pbpaste | base64 -D | python -mjson.tool | pbcopy
If the clipboard contained eyJvcyI6Im1hYyJ9Cg==
(base64 of {"os":"mac"}
) before this step, it now contains the following:
{
"os": "mac"
}