How to get the stdout of a command into the clipboard on Ubuntu Linux ?

ยท 234 words ยท 2 minute read

Pre-installed Commandline Tools on Ubuntu ๐Ÿ”—

xsel comes preintalled in Ubuntu Linux. Actually XSEL is pre-installed with XServer if you are using it. You can copy with xsel like this.

echo "text to be copied" | xsel -ib

Or copy by directing the output of text files like that.

xsel -ib < ~/.bashrc

You can paste the copied text into the standard output by this command.

xsel -ob

Or just use the command without any arguments.


Fish shell Tools ๐Ÿ”—

If you installed FISH shell on your Ubuntu Linux, you can use the tool made by Fish team to manage system clipboard (fish_clipboard_copy). You can Pipe the output of a command into the input of it like this.

cat ~/id_bus_ssh_pass.txt | fish_clipboard_copy

Fish shell has a command line tool to paste from clipboard too. You can use it like this.

fish_clipboard_paste | sed 's/A/B/g' | cat > new-text-file.txt

In that command, fish_clipboard_paste pastes the clipboard text into the stdout, then the sed program replaces every A character into B character, then the cat program concatenate the whole text output into a file called new-text-file.txt.

I hope this post helps you. If you know a person who can benefit from this information, send them a link of this post. If you want to get notified about new posts, follow me on YouTube , Twitter (x) , LinkedIn , Facebook , Telegram and GitHub .