How to Copy to Clipboard using Terminal Command

At times you may want to copy the text of a command on a Mac Terminal to the Clipboard, you can do that after executing the command and by making use of the keyboard and the mouse (or trackpad), but this will be a two-step process.

Do you know we can make use of a command called pbcopy, which lets you copy the output of a command straight to the clipboard.


Example:

ls -l | pbcopy
Example Copy Terminal Text to Clipboard

You can learn more about this command using the manual man pbcopy.


This is not an AI-generated article but is demonstrated by a human on an M1 Mac running macOS Sonoma 14.0.

Please support independent contributors like Code2care by donating a coffee.

Buy me a coffee!

Buy Code2care a Coffee!

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!