How do I pipe terminal standard output (stdout) to the clipboard?

Insperatus

For example,

Say I want to list the contents of a folder and directly paste them into a chat window for a friend to see.

I realize I could do ls > filename.txt to create a file (filename.txt) with those contents; I'd then have to open or print the file and manually select and copy the text block (which can be annoying/tedious.) I clearly could also select and copy the output of ls directly from within the terminal window.

It would be much faster/easier to simply pipe standard output to the clipboard.

What terminal command allows me to do this?

Insperatus

This can be done with either xsel or xclip command line utilities. Since neither program comes with Ubuntu by default you'll need to first install them via Ubuntu Software or the terminal. Here's how in the terminal (but remember you only need one of these two.)

sudo apt install xsel
sudo apt install xclip

Note: If you're using Ubuntu in Windows Subsystem for Linux (WSL) see this other answer instead.

Now some examples. If you want to copy the output of ls to the clipboard here's what you'd do:

With xsel:

ls | xsel -ib

With xclip:

ls | xclip -sel clip

This can of course be utilized for other terminal commands as well. Let's say you want to paste your network info into a help forum.

With xsel:

sudo lshw -C network | xsel -ib

With xclip:

sudo lshw -C network | xclip -sel clip

Make this even easier with a new bash alias!

Edit your ~/.bash_aliases file (if it doesn't exist yet create it first with touch ~/.bash_aliases)

Then add one (depending on which program you decided to go with) of the following:

alias copy='xclip -sel clip'

or

alias copy='xsel -ib'

Then save and close.

Now (after restarting your terminal) you can send standard output to the clipboard just by piping it to 'copy' (or whatever you decide to name your new alias)

For example:

ls | copy

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I pipe terminal standard output (stdout) to the clipboard?

From Dev

How do I pipe the last command in my command history to clipboard?

From Dev

Node pipe to stdout -- how do I tell if drained?

From Dev

How do I save terminal output to a file?

From Dev

How do I save terminal output to a file?

From Dev

How do I tell if a program is printing to stderr or stdout in the terminal?

From Dev

I can not pipe terminal output to file

From Dev

I can not pipe terminal output to file

From Dev

When stdout is being used to output binary data, how can I also output debug/verbose info to the terminal?

From Dev

When stdout is being used to output binary data, how can I also output debug/verbose info to the terminal?

From Dev

GitPython pipe output to stdout

From Dev

Direct output to pipe and stdout

From Dev

GitPython pipe output to stdout

From Dev

how do I pipe output of a python script into an Rscript?

From Dev

How do I pipe output to date -d "value"?

From Dev

How do I pipe the output of tar through mv?

From Dev

how do I pipe output of a python script into an Rscript?

From Dev

How do I get the output of jq to pipe to curl

From Dev

How do I encode the FLV to a temporary file and then output that to stdout with FFMpeg?

From Java

How can I pipe stderr, and not stdout?

From Dev

How can I pipe stdout to another program?

From Dev

How does a program know if stdout is connected to a terminal or a pipe?

From Dev

Find out if stdout is terminal or pipe

From Dev

Why can't I pipe assembler output to stdout?

From Dev

How do I echo directly on standard output inside a shell function?

From Dev

How do I pull specific strings out of the standard output of netsh?

From Dev

How do I echo directly on standard output inside a shell function?

From Dev

How do I print slurm variables to standard slurm output?

From Dev

Bash: how do I pipe stdout and stderr of one process to two different processes?

Related Related

  1. 1

    How do I pipe terminal standard output (stdout) to the clipboard?

  2. 2

    How do I pipe the last command in my command history to clipboard?

  3. 3

    Node pipe to stdout -- how do I tell if drained?

  4. 4

    How do I save terminal output to a file?

  5. 5

    How do I save terminal output to a file?

  6. 6

    How do I tell if a program is printing to stderr or stdout in the terminal?

  7. 7

    I can not pipe terminal output to file

  8. 8

    I can not pipe terminal output to file

  9. 9

    When stdout is being used to output binary data, how can I also output debug/verbose info to the terminal?

  10. 10

    When stdout is being used to output binary data, how can I also output debug/verbose info to the terminal?

  11. 11

    GitPython pipe output to stdout

  12. 12

    Direct output to pipe and stdout

  13. 13

    GitPython pipe output to stdout

  14. 14

    how do I pipe output of a python script into an Rscript?

  15. 15

    How do I pipe output to date -d "value"?

  16. 16

    How do I pipe the output of tar through mv?

  17. 17

    how do I pipe output of a python script into an Rscript?

  18. 18

    How do I get the output of jq to pipe to curl

  19. 19

    How do I encode the FLV to a temporary file and then output that to stdout with FFMpeg?

  20. 20

    How can I pipe stderr, and not stdout?

  21. 21

    How can I pipe stdout to another program?

  22. 22

    How does a program know if stdout is connected to a terminal or a pipe?

  23. 23

    Find out if stdout is terminal or pipe

  24. 24

    Why can't I pipe assembler output to stdout?

  25. 25

    How do I echo directly on standard output inside a shell function?

  26. 26

    How do I pull specific strings out of the standard output of netsh?

  27. 27

    How do I echo directly on standard output inside a shell function?

  28. 28

    How do I print slurm variables to standard slurm output?

  29. 29

    Bash: how do I pipe stdout and stderr of one process to two different processes?

HotTag

Archive