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

Commands using screen from sorted by
Terminal - Commands using screen - 39 results
screen -x
2009-09-09 11:30:56
User: flart
Functions: screen
5

Force the user you want to watch doing things into doing his things in a screen session. Then simply attach yourself to that session with the command shown above.

Works only if you are on the same machine, of course

tmpfile=$(mktemp) && echo -e 'startup_message off\nscreen -t top htop\nsplit\nfocus\nscreen -t nethogs nethogs wlan0\nsplit\nfocus\nscreen -t iotop iotop' > $tmpfile && sudo screen -c $tmpfile
2009-08-03 10:14:02
User: Patola
Functions: echo screen sudo top
18

This command starts screen with 'htop', 'nethogs' and 'iotop' in split-screen. You have to have these three commands (of course) and specify the interface for nethogs - mine is wlan0, I could have acquired the interface from the default route extending the command but this way is simpler.

htop is a wonderful top replacement with many interactive commands and configuration options. nethogs is a program which tells which processes are using the most bandwidth. iotop tells which processes are using the most I/O.

The command creates a temporary "screenrc" file which it uses for doing the triple-monitoring. You can see several examples of screenrc files here: http://www.softpanorama.org/Utilities/Screen/screenrc_examples.shtml

ssh -t user@host screen -x <screen name>
2009-08-02 15:39:24
User: Dark006
Functions: screen ssh
7

If you know the benefits of screen, then this might come in handy for you. Instead of ssh'ing into a machine and then running a screen command, this can all be done on one line instead. Just have the person on the machine your ssh'ing into run something like

screen -S debug

Then you would run

ssh -t user@host screen -x debug

and be attached to the same screen session.

rxvt-unicode -g 999x999 -sr -depth 32 -bg rg-ba:0000/0000/0000/dddd +sb -T irssi -n irssi -name irssichat -e ssh server.com -Xt screen -aAdr -RR irssi irssi
2009-07-30 04:53:17
User: MTecknology
Functions: screen ssh
-1

This will launch and irssi session on your server. If it's not running, it will create the session. If it's running it'll connect to it and destroy any other connections. If compositing is available, the rxvt window will have transparency added. This window will also open maximized. Anything else this does should be easily figured out in the man pages.

ssh -t remote_host screen -r
2009-07-23 06:15:04
User: recursiverse
Functions: screen ssh
Tags: ssh screen
41

Directly attach a remote screen session (saves a useless parent bash process)

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

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.

screen -x
2009-05-19 19:10:52
User: GeckoDH
Functions: screen
13

Ater person A starts his screen-session with `screen`, person B can attach to the srceen of person A with `screen -x`. Good to know, if you need or give support from/to others.

screen -d -m nautilus --no-desktop `pwd`
2009-05-07 00:49:07
User: windsurfer
Functions: screen
-10

This opens up nautilus in the current directory, which is useful for some quick file management that isn't efficiently done from a terminal.

screen -dmS "name_me" echo "hi"
2009-05-06 02:04:15
Functions: echo screen
3

Runs an instance of screen with name of "name_me" and command of "echo "hi""

To reconnect to screen instance later use:

screen -r name_me

screen -d -m [<command>]
2009-04-28 12:35:25
User: cammarin
Functions: screen
Tags: screen
16

Start screen in detached mode, i.e., already running on background. The command is optional, but what is the purpose on start a blank screen process that way?

It's useful when invoking from a script (I manage to run many wget downloads in parallel, for example).

screen -ls | grep pts | gawk '{ split($1, x, "."); print x[1] }' | while read i; do gnome-terminal -e screen\ -dx\ $i; done
2009-04-22 10:36:39
User: microft
Functions: gawk grep read screen
3

connects to all the screen instances running.

% screen -r someuser/
2009-03-25 23:59:38
User: totoro
Functions: screen
38

If you enable multiuser, then you can permit others to share your screen session. The following conditions apply:

1. screen must be suid root;

2. "multiuser on" must be configured in ~/.screenrc;

3. control the others user(s) access with "aclchg":

# ----- from ~/.screenrc-users -----

aclchg someuser +rx "#?" #enable r/o access to "someuser"

aclchg someuser -x "#,at,aclchg,acladd,acldel,quit" # don't allow these

aclchg otheruser +rwx "#?" # enable r/w access to "otheruser"

aclchg otheruser -x "#,at,aclchg,acladd,acldel,quit" # don't allow them to use these commands

# -----

After doing this (once), you start your session with:

$ screen

Then, the other user can join your terminal session(s) with youruserid:

$ screen -r youruserid/

Note: the trailing "/" is required.

Multiple users can share the same screen simultaneously, each with independent access controlled precisely with "aclchg" in the ~/.screenrc file.

I use the following setup:

# ~/.screenrc-base

# default screenrc on any host

source $HOME/.screenrc-base

source $HOME/.screenrc-$HOST

source $HOME/.screenrc-users

# -----

Then, the base configurations are in ~/.screenrc-base; the host-specific configurations are in ~/.screenrc-$HOST, and the user configurations are in ~/.screenrc-users.

The host-specific .screenrc file might contain some host-specific screen commands; e.g.:

# ~/.screen-myhost

# -----

screen -t 'anywhere' /bin/tcsh

screen -t 'anywhere1' /bin/tcsh

# ----

The .screenrc-base contains:

# ~/.screenrc-base

## I find typing ^a (Control-a) awkward. So I set the escape key to CTRL-j instead of a.

escape ^Jj

termcapinfo xterm* ti@:te@:

autodetach on

zombie kr

verbose on

multiuser on

screen -xR
2009-02-05 22:22:10
User: stuart
Functions: screen
4

Have your screen session running in multiple places. (warning, things start to look weird if the terminal windows have different dimensions)

screen -ls | grep main && urxvt -name screen -e screen -x main || urxvt -name screen -e screen -R -S main
2009-02-05 10:51:31
User: trey
Functions: grep screen
0

Open a terminal (urxvt in this case) to connect to a screen session (named "main") and create the screen session if necessary.