160

In Windows I used command-line clipboard copy-and-paste utilities...

  • pclip.exe and gclip.exe

These were UnixUtils ports for Windows (but they only handled plain text). There were a couple of other native Windows utilities which could write/extract any format.

I've looked for something similar in Synaptic Package Manager, but I can't find anything.

Is there something there, that I've missed? ... or maybe this is available in Bash scripting?

The type of utility I'd like will be able to read/write via std-in/std-out or file-in/file-out, and handle Unicode, Rich Text Format, picture, etc. clipboard formats...

NB: I'm not after a clipboard manager.

Peter.O
  • 25,251

12 Answers12

153

xsel

I am using xsel Install xsel, but I am only using it with plain text and unicode text.

xsel can copy and paste to three different "clipboards".

By default, it uses the X Window System primary selection, which is basically whatever is currently in selection. The X Window System also has a secondary selection (which isn't used much), and a clipboard selection. You're probably looking for the clipboard selection, since that's what the desktop environment (e.g. Gnome, KDE, XFCE) uses for its clipboard. To use that with xsel:

xsel --clipboard < new-clipboard-contents.txt
xsel --clipboard > current-clipboard-contents.txt
Pablo Bianchi
  • 17,371
Adi Roiban
  • 2,942
118

xclip

Install xclip may be one of your choices.

cat samples.sh | xclip -sel clip

you can also setting it in the .bashrc file using alias.

alias clipboard='xclip -sel clip'

The key to paste binary data to a file with xclip is to tell what Media Types you have on clipboard. For PNG you can:

xclip -selection clipboard -t image/png -o > "`date '+%Y-%m-%d_%T'`.png"

So now on ~/Dropbox/.mybashrc ;) you can add an alias (clipboard2photo) to easily paste to image file (maybe someday we'll have it on Nautilus).

Pablo Bianchi
  • 17,371
kit.yang
  • 2,182
12

Parcellite

I've used parcellite for many years as a clipboard manager. It runs in the Notification Area and offers many options for managing both Primary Selection and standard freedesktop.org Clipboard.

Tray Icon

It's been my answer to managing clipboard items.

Preferences

Marco Ceppi
  • 48,827
12

I recently came across the tools xclip-copyfile, xclip-cutfile, and xclip-pastefile (package xclip). These tools allow you to copy/cut/paste entire files via the command line.

You can see their man page here.

slm
  • 3,155
9

clipit

clipit is a clipboard manager for GTK+ that allows piping text from the command line:

ls | clipit
Pablo Bianchi
  • 17,371
eMBee
  • 99
4

You can use CopyQ for this. From the website:

Clipboard manager with advanced features

  • CopyQ is clipboard manager with searchable and editable history.
  • Supports Linux and Windows.
  • Experimental support for OS X 10.9+.
  • Store text, HTML, images and any other custom format.
  • Advanced command-line interface and scripting.

To copy a text file:

copyq action "cat /tmp/file.txt" "" && copyq select 0

To copy an image (you need to indicate the MIME type):

copyq write image/png - < file.png && copyq select 0

To copy a data file (you need to indicate the MIME type):

copyq write application/pdf - < file.pdf && copyq select 0

Check their wiki for more documentation and usage examples.

You can install it either via the ppa:noobslab/indicators PPA or by manually downloading prepackaged .deb files of latest stable from the project's Downloads section.

landroni
  • 6,011
4

If you just want to copy some text to the clipboard:

echo -n "some-text" | xclip -selection clipboard

2

Pastie

A new clipboard manager with Indicator Applet support was recently released (though not in the archive yet). In addition to tracking text clipboard history it will also capture and persist data clipboard entries as well (Files, Folders, etc) which may be useful if you manipulate files a lot via a GUI/Clipboard environment.

alt text

You can add the following PPA: ppa:hel-sheep/pastie

Marco Ceppi
  • 48,827
2

For RTF format I use this procedure: I copy text into clipboard in the application. If I am unsure whether it is rtf or what, I use this command to verify:

xclip -selection clipboard -o -t TARGETS

When it prints out something like this:

TARGETS

text/rtf

text/richtext

So I cannot resist to exclaim quite aloud: "Gee, that is genious! God bless linux!" After that shot prayer, just obvious thing follows:

xclip  -selection clipboard -o -t text/rtf > mypreciousRTFcontent.rtf

Then I process it all in libreoffice and send to all my friends as a spam.

:-)

xerostomus
  • 1,060
1

How about GPaste daemon settings, a clipboard management daemon applet with DBus interface:

  • GPaste is a clipboard management suite for GNOME written in Vala
  • GPaste settings look has been updated to better fit with recent GNOME
  • Daemon now fully evenmential (no more polling, less power consuption)
  • GPasteClipboard now has a “owner-change” signal similar to GtkClipboard’s one
  • New setting to set the maximum amount of memory used by data in history
  • FIFO mode has been dropped (lacking design)
  • Code cleanup and modernisation
  • g_paste_history_add is now transfer full
  • g_paste_keybinder_add_keybinding is now transfer full

Installation:

To install it in Ubuntu 13.10, 13.04, 12.10 or 12.04, use the commands below:

sudo add-apt-repository ppa:webupd8team/gnome3
sudo apt-get update
sudo apt-get install gnome-shell-extensions-gpaste

Or install gpaste through synaptic package manager (and also gnome-shell-extensions-gpaste if you use Gnome-Shell).

Another option is the installation through software-center.

enter image description here

v2r
  • 9,707
1

I'm trying to develop a better solution that isn't a clipboard manager, found at https://github.com/baitisj/copypasta . It doesn't handle RTF and HTML correctly quite yet, and large images pose problems, but feel free to fork and submit patches.

baitisj
  • 111
  • 3
-1

Yes, there is. Try tmux which is more advanced than screen. To install tmux, type this in the terminal:

sudo apt-get install tmux

Also try gpm. The commands gpm and tmux might be a good combination...

karthick87
  • 84,513