Last Updated: September 30, 2021
· jmarizgit

Copy files to clipboard using command line on OSX

Use "pbcopy" to copy content of file to your clipboard.

For example:

$ pbcopy < file.txt

the command will copy all content from "file.txt" directly on your clipboard.

You can check if the content is there by using the "pbpaste" command:

$ pbpaste

The content of "file.txt" will appear on your terminal window.

If you use other *nix distribution please take a look over xclip or xsel. Take look over this website:

4 Responses
Add your response

for windows users you can use

to copy from a file

$ cat file > /dev/clipboard

to paste into a file

$ cat /dev/clipboard > file

or to check the contents of the clipboard

$ cat /dev/clipboard

:) enjoy.

over 1 year ago ·

You can also copy anything using pipes:

$ cat file | grep something | pbcopy
$ echo $ENV_VAR | pbcopy
over 1 year ago ·

Linux user here: I don't have pbcopy, and I don't see it in Ubuntu's repos. Since Ubuntu is one of the more common Linux distros, I think it's safe to say that this is not common to many unix users.

So where is pbcopy available? OSX?

over 1 year ago ·
over 1 year ago ·