Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Getting Screen's Copy Buffer Into X's Copy Buffer (on Linux)

Terminal - Getting Screen's Copy Buffer Into X's Copy Buffer (on Linux)
Type "c-a b" in gnu screen after updating your .screenrc (See Description below).
2009-05-23 02:10:12
User: deeelwy
Functions: screen
5
Getting Screen's Copy Buffer Into X's Copy Buffer (on Linux)

This command will let you just type c-a b (which means press 'ctrl' then 'a' then 'b'), and screen will save your copy buffer to /tmp/screen-exchange, and then execute xsel to copy the contents of that file into the system's X clipboard.

1. Install Conrad Parker's xsel from http://www.vergenet.net/~conrad/software/xsel/

2. Add these lines to your .screenrc

# Add cool line to make copying to x clipboard possible.

# This binds C-a b to copy screen's copy buffer to the system clipboard.

bind b eval writebuf 'exec /bin/sh -c "xsel -i -b < /tmp/screen-exchange"' 'exec /bin/sh -c "killall xsel"'

3. Restart screen.

4. Test it by typing c-a [ to enter copy mode.

5. Select some text using vi movement keys (h, j, k, l, etc...) and starting your selection by hitting the space bar, moving with vi movement keys, and then ending your selection with the space bar.

6. Type C-a b, and screen will use xsel to copy your screen copy buffer to the system's X clipboard buffer.

7. Then you can paste the screen copy buffer into any X program.

Note: If you're using Mac OSX, you can use pbcopy instead of xsel.

Also Note: The second exec in the .screenrc file, which runs killall on xsel, is necessary, because even when you redirect a file to xsel, xsel waits for you to press ctrl-c to kill it, and have it stop waiting for more input. Since xsel forces screen to wait, and I don't want to press ctrl-c, I send the equivalent of ctrl-c with killall causing xsel to write /tmp/screen-exchange to the X clipboard, and then exit. It's a hack, but it works. If you know how to get this to work without a lame hack leave a comment explaining how.

Alternatives

There are 4 alternatives - vote for the best!

Terminal - Alternatives

Know a better way?

If you can do better, submit your command here.

What others think

As long as you want less than a screenful, there's always select in your terminal and then paste with middle-click.

Comment by bwoodacre 270 weeks and 1 day ago

@bwoodacre, screen's copy function is much more powerful - it allows block copying so you can copy a block of text without all the hassle of the margins, line numbers etc.

This command is great! I use Ratpoison window, so I prefer using the keyboard to the mouse.

Comment by harryhaller 263 weeks ago

If some find it doesn't work with their WM, then they should try:

xsel -i instead of xsel -i -b since the -b puts into the clipboard, and without the -b it goes (by default) into the primary buffer.

On my WM, Ratpoison, the primary buffer is used instead of the clipboard.

Read man xsel.

There are also other programmes such as xclip and xcb which might be used as well as xsel - though xsel does the job fine.

Pity we have to do the C-a b - I wish there was a way to put it straight into the buffer/clipboard without the extra step....

;-)

A very good command - thanks deeelwy!

Comment by harryhaller 263 weeks ago

Your point of view

You must be signed in to comment.

Related sites and podcasts