Site Map - skip to main content

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes every weekday Monday through Friday.
This page was generated by The HPR Robot at


hpr2815 :: Copy pasta

Copying and pasting on Linux: X selections, xsel, clipboard managers, GPM, screen, and more

<< First, < Previous, , Latest >>

Hosted by Klaatu on 2019-05-17 is flagged as Clean and is released under a CC-BY-SA license.
copy, paste, xsel. (Be the first).
The show is available on the Internet Archive at: https://archive.org/details/hpr2815

Listen in ogg, spx, or mp3 format. Play now:

Duration: 00:38:20

general.

You can copy and paste on Linux the same way you do on any other OS: Ctrl+C to copy and Ctrl+V to paste (or use the Edit menu, or a right-click menu).

However, Linux doesn't limit you to just that. The primary GUI environment of Linux (at the time of this recording) is X, and the Inter-Client Communication Conventions Manual defines three X Selection states: Primary, Secondary, and Clipboard. The Secondary is rarely (if ever?) used, so I don't cover it here.

Primary

The primary X Selection is anything literally selected at any given moment. If you highlight a word in Firefox with your mouse, for instance, then it becomes the Primary Selection, and it is owned by Firefox. If you press the Middle Mouse Button in any application, then that application asks the owner (Firefox, in this example) for the data contained in the Primary Selection. Firefox sends the data to that application so that it can paste it for you.

A Primary selection remains the Primary Selection until it is overwritten by a new Primary Selection. In other words, text needn't be highlighted to be retained in the Primary Selection slot.

Clipboard

The Clipboard Selection is data that has explicitly been sent to the clipboard by a copy action. This is usually a right-click > Copy or a selection of Edit > Copy. When another application is told to paste from the clipboard, it pastes data from the Clipboard Selection.

Both

You can (and often do) have both a Primary Selection and a Clipboard selection. If you press Ctrl+V, you get the contents of the Clipboard Selection. If you press the middle mouse button, then you get the contents of the Primary Selection.

xsel

The xsel command allows you to retrieve the contents of an X Selection.


$ xsel --primary
dungeons
$ xsel --clipboard
dragons

Clipboard managers

Clipboard managers such as Klipper, CopyQ, Parcellite, and so on, provide a history for your clipboard. They track the latest 10 (or so) items you have copied or selected. They can be a little confusing, because they do tend to blur the line between the Primary Selection and the Clipboard Selection, but now that you know the technical difference, it shouldn't confuse you to see them both listed by a clipboard manager designed to conflate them.

GPM

GPM is a daemon allowing you to use your mouse without a GUI. Among its features, it permits you to select text in a text console (TTY) and then paste it with the middle mouse button.

GNU Screen and Tmux

Screen and tmux are "window managers for text consoles". I don't tend to use tmux as often as I should, having learnt GNU Screen long ago, so I'm not familiar with the process of copying and pasting with tmux. For Screen, you can copy text in this way:

  1. Press Ctrl+A to get out of insert mode.

  2. Press left-square_bracket to enter copy-mode

  3. Move your text to the position you want to start selecting and press Enter or Return

  4. Arrow to the position at which you want to end your selection and press Enter or Return again

To paste your selection:

  1. Press Ctrl+A to get out of insert mode.

  2. Press right-square_bracket to paste


Comments

Subscribe to the comments RSS feed.

Leave Comment

Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.

Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).

Provide feedback
Your Name/Handle:
Title:
Comment:
Anti Spam Question: What does the letter P in HPR stand for?
Are you a spammer?
What is the HOST_ID for the host of this show?
What does HPR mean to you?