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 tagged screen from sorted by
Terminal - Commands tagged screen - 35 results
xbacklight -set 50
2014-02-07 12:03:57
User: gabe240
1

I'm not sure what apt this is, but it seems to work on most X screens, an is useful for saving power, and not straining your eyes

xdpyinfo | grep dimensions | awk '{print $2}'
screen -R -D -S sessionname -q
complete -C "perl -e '@w=split(/ /,\$ENV{COMP_LINE},-1);\$w=pop(@w);for(qx(screen -ls)){print qq/\$1\n/ if (/^\s*\$w/&&/(\d+\.\w+)/||/\d+\.(\$w\w*)/)}'" screen
2013-04-10 17:17:33
User: hubt
Tags: bash screen
2

this bash command sets it so that when you type "screen ", it searches your running screens, and present valid auto-complete choices. The output is .

Note: You must have programmable completion enabled. Check with "shopt progcomp", set with "shopt -s progcomp"

alias sdr="screen -dR"
2012-10-22 21:46:26
User: tox2ik
Functions: alias
Tags: bash screen
0

There is no need to use the shell or construct. Screen offers varius ways of detaching and reattaching. man screen and look for -[rRdD].

to create a named session: sdr moo

hide:

resume: sdr moo

screen -r irc || screen -S irc irssi
2012-10-19 12:12:54
User: daneoshiga
Functions: screen
Tags: bash screen irssi
-2

Tries to reattach to screen, if it's not available, creates one.

created an alias "irc" for it, since sometimes i forget if there already is a screen session running with irssi, this way I avoid creating a new one by mistake.

s() { screen -d -RR -m -S "$1" -t "$USER"@"$1" ssh "$1"; }
2012-09-07 23:02:52
User: salamando
Functions: screen ssh
Tags: ssh screen Linux
5

Use as: $ s host1

Will ssh to remote host upon first invocation. Then use C-a d to detatch. Running "s host1" again will resume the shell session on the remote host. Only useful in LAN environment. You'd want to start the screen on the remote host over a WAN.

Adapted from Hack 34 in Linux Server Hacks 2nd Addition.

alias irc="screen -D -R -S chatclient irssi"
2012-08-12 13:24:43
User: expelledboy
Functions: alias
2

This command attempts to attach to existing irssi session, if one exists, otherwise creates one.

I use "irc" because I use different irc clients depending on what system I am working on. Consistency is queen.

screen -S [name] -d -m [<command>]
2012-08-10 09:30:22
User: bones
Functions: screen
0

Starts a detached screen with the given screen-name.

Can be useful for automatic started scripts and init.d-scripts.

ash prod<tab>
2012-05-12 19:51:02
User: c3w
-1

http://github.com/c3w/ash

. a Ruby SSH helper script

. reads a JSON config file to read host, FQDN, user, port, tunnel options

. changes OSX Terminal profiles based on host 'type'

USAGE:

put 'ash' ruby script in your PATH

modify and copy ashrc-dist to ~/.ashrc

configure OSX Terminal profiles, such as "webserver", "development", etc

run "ash myhostname" and away you go!

v.2 will re-attach to a 'screen' named in your ~/.ashrc

cvlc --input-slave pulse://<device> screen:// --screen-fps=15 --screen-top=0 --screen-left=0 --screen-width=640 --screen-height=480 --sout='#transcode{vcodec=FLV1,vb=1600,acodec=aac}:std{access=file,mux=ffmpeg{mux=flv},dst=viewport1.flv}'
2012-04-20 17:55:41
User: ysangkok
2

Errors in output don't matter. Stop recording: ctrl-c. Result playable with Flash too.

IMPORTANT: Find a Pulse Audio device to capture from: pactl list | grep -A2 'Source #' | grep 'Name: ' | cut -d" " -f2

rlwrap -S "$STY> " sh -c 'while read; do screen -S "'"$STY"'" -X $REPLY; done'
2012-04-16 21:49:06
User: bandie91
Functions: screen sh
Tags: screen rlwrap
0

run it inside a screen session, you send commands to screen itself!

<ctrl+a>:at "#" stuff "echo hello world^M"
switchMonitor () { LF=/tmp/screen-lock; if [ -f $LF ]; then rm $LF; else touch $LF; sleep .5; while [ -f $LF ]; do xset dpms force off; sleep 2; done; fi };
2011-08-26 17:55:44
User: totti
Functions: rm sleep touch
1

Use the command to create a script and bind it to a key using keyboard shortcut.

eg:

Script locks the screen in a loop until the command is executed again.At first it

screen -x <screen_id>
# su - <user> ; script /dev/null ; screen -r
2011-07-04 16:26:10
User: dmmst19
Functions: screen script su
Tags: screen su pty
2

Normally, if you su to another user from root and try to resume that other user's screen session, you will get an error like "Cannot open your terminal '/dev/pts/0' - please check." This is because the other user doesn't have permission for root's pty. You can get around this by running a "script" session as the new user, before trying to resume the screen session. Note you will have to execute each of the three commands separately, not all on the same line as shown here.

Credit: I found this at http://www.hjackson.org/blog/archives/2008/11/29/cannot-open-your-terminal-dev-pts-please-check.

echo 'hardstatus alwayslastline " %d-%m-%y %c:%s | %w"' >> $HOME/.screenrc; screen
2011-02-16 08:04:56
User: olorin
Functions: echo
4

Configures screen to always display the clock in the last line (has to be configured only once).

After that you not only have got the possibility to detach sessions and run them in background, but also have got a nice clock permanently on your screen.

alias irssi="screen -wipe; screen -A -U -x -R -S irssi irssi"
2010-12-15 09:10:53
User: djsmiley2k
Functions: alias
3

Bash alias for easy irssi within screen, attempts to attach to existing irssi session, if one exists, otherwise creates one - Including wipe for when system reboots and leaves "dead" session.

cd /proc&&ps a -opid=|xargs -I+ sh -c '[[ $PPID -ne + ]]&&echo -e "\n[+]"&&tr -s "\000" " "<+/cmdline&&echo&&tr -s "\000\033" "\nE"<+/environ|sort'
1

Grabs the cmdline used to execute the process, and the environment that the process is being run under. This is much different than the 'env' command, which only lists the environment for the shell. This is very useful (to me at least) to debug various processes on my server. For example, this lets me see the environment that my apache, mysqld, bind, and other server processes have.

Here's a function I use:

aa_ps_all () { ( cd /proc && command ps -A -opid= | xargs -I'{}' sh -c 'test $PPID -ne {}&&test -r {}/cmdline&&echo -e "\n[{}]"&&tr -s "\000" " "<{}/cmdline&&echo&&tr -s "\000\033" "\nE"<{}/environ|sort&&cat {}/limits' ); }

From my .bash_profile at http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html

cat > /dev/null
2010-10-08 14:35:25
User: GouNiNi
Functions: cat
-5

In exemple, screen can bind keys to switch between windows. I like to use Ctrl + Arrow to move left or right window. So I bind like this in .screenrc :

bindkey ^[OD prev # Ctl-left, prev window

bindkey ^[OC next # Ctl-right, next window

bindkey ^f at "#" kill
2010-10-07 12:01:38
Functions: at
Tags: screen
0

Kills all windows in a gnu screen session and terminates it , on pressing Control-f , useful in closing screen session with large number of windows . Add it to your screenrc .

screen /dev/tty<device> 9600
screen -raAd
2010-04-12 22:54:58
User: rkulla
Functions: screen
11

By default, screen tries to restore its old window sizes when attaching to resizable terminals. This command is the command-line equivalent to typing ^A F to fit an open screen session to the window.

eval `ssh-agent`; screen
2010-03-07 14:58:54
User: mechmind
Functions: eval
4

When you start screen as `ssh-agent screen`, agent will die after detatch.

If you don't want to take care about files when stored agent's pid/socket/etc, you have to use this command.

xrandr --auto
2009-12-30 18:52:02
User: kanzure
8

i spent way too many hours trying to fiddle with /etc/X11/xorg.conf trying to hook up various external projectors. too bad i didn't know this would solve all my problems.