Skip to main content

How to copy file content using command line on Mac?

Published 1 min readMarkdown
Part of seriesToday I Learned

Sometimes I want to quickly copy the contents of a file, e.g. when I'm creating a new SSH key.

Up until now, I would use cat to read the content, then select it and finally copy it.

$: cat id_rsa.pub
  ssh-rsa AAAAB3NzaC1y...

You can do it much faster, using pbcopy, which copies the file content directly to the clipboard.

pbcopy < id_rsa.pub

Note, that, as the title of this post suggest, pbcopy is available only on Mac OS. For Linux, you might want to check xclip.

No comments yet. Be the first to comment.

More from this blog