Maciek Sitkowski
Maciek's Blog

Follow

Maciek's Blog

Follow

How to copy file content using command line on Mac?

Maciek Sitkowski's photo
Maciek Sitkowski
·Nov 3, 2022·

1 min read

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.

 
Share this