DEV Community

BC
BC

Posted on

Copy file content to clipboard in terminal

In Mac you can use pbcopy:

$ pbcopy < hello.txt
Enter fullscreen mode Exit fullscreen mode

In Linux which is using X11 (I am using ubuntu), you can use xsel command:

$ sudo apt install xsel
$ xsel -b < hello.txt
Enter fullscreen mode Exit fullscreen mode

To copy some program's output to clipboard, we can use pipe:

$ date | xsel -b
Enter fullscreen mode Exit fullscreen mode

Then if you use "ctrl-v", you will see the copied date.

Top comments (0)